LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-01-2005, 12:32 PM   #1
astead
LQ Newbie
 
Registered: Mar 2005
Posts: 1

Rep: Reputation: 0
Cant seem to reference IP header info


I am using ULog, and have ULog sending the information it is logging from Netfilter to another machine via sockets. The other machine can read all the information passed to it except for the ip header information...? I keep getting a "error dereferencing pointer to incomplete type" error when I try and compile...

If anyone is familiar with ULog and can help point out how to get to the payload member of the ulog_packet_msg struct, that would be fantastic!

Alan

Here is a code snippet:
recv(new_socket, buffer, sizeof(struct ulog_packet_msg), 0);
ulog_packet =(struct ulog_packet_msg *) buffer;
tmp_iphdr = (struct iphdr *) ulog_packet->payload;

/* For parsing IP headers */
/* I get the compile error on this next line... actually any line where I try and access a member of the ulog_packet->payload... */
struct udphdr *tmp_udphdr = (struct udphdr*) ((char*) tmp_iphdr+(tmp_iphdr->ihl*4));
struct tcphdr *tmp_tcphdr = (struct tcphdr*) ((char*) tmp_iphdr+(tmp_iphdr->ihl*4));
struct icmphdr *tmp_icmphdr = (struct icmphdr*) ((char*) tmp_iphdr+(tmp_iphdr->ihl*4));
unsigned short srcport, dstport;
unsigned int hdr_len = tmp_iphdr->ihl*4;

switch(tmp_iphdr->protocol) {
case IPPROTO_UDP:
srcport = ntohs(tmp_udphdr->source);
dstport = ntohs(tmp_udphdr->dest);
break;
case IPPROTO_TCP:
srcport = ntohs(tmp_tcphdr->source);
dstport = ntohs(tmp_tcphdr->dest);
break;
case IPPROTO_ICMP:
srcport = tmp_icmphdr->type;
dstport = tmp_icmphdr->code;
break;
default:
srcport = dstport = 0;
break;
}

printf("Received log message\n");
printf("proc_name: %s\n", ulog_packet->proc_name);
printf("pid: %d\n", ulog_packet->pid);
printf("src port: %i\n", srcport);
printf("dst port: %i\n", dstport);
 
Old 01-15-2009, 07:22 AM   #2
KarthikBG
LQ Newbie
 
Registered: Jan 2009
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by astead View Post
I am using ULog, and have ULog sending the information it is logging from Netfilter to another machine via sockets. The other machine can read all the information passed to it except for the ip header information...? I keep getting a "error dereferencing pointer to incomplete type" error when I try and compile...

If anyone is familiar with ULog and can help point out how to get to the payload member of the ulog_packet_msg struct, that would be fantastic!

Alan

Here is a code snippet:
recv(new_socket, buffer, sizeof(struct ulog_packet_msg), 0);
ulog_packet =(struct ulog_packet_msg *) buffer;
tmp_iphdr = (struct iphdr *) ulog_packet->payload;

/* For parsing IP headers */
/* I get the compile error on this next line... actually any line where I try and access a member of the ulog_packet->payload... */
struct udphdr *tmp_udphdr = (struct udphdr*) ((char*) tmp_iphdr+(tmp_iphdr->ihl*4));
struct tcphdr *tmp_tcphdr = (struct tcphdr*) ((char*) tmp_iphdr+(tmp_iphdr->ihl*4));
struct icmphdr *tmp_icmphdr = (struct icmphdr*) ((char*) tmp_iphdr+(tmp_iphdr->ihl*4));
unsigned short srcport, dstport;
unsigned int hdr_len = tmp_iphdr->ihl*4;

switch(tmp_iphdr->protocol) {
case IPPROTO_UDP:
srcport = ntohs(tmp_udphdr->source);
dstport = ntohs(tmp_udphdr->dest);
break;
case IPPROTO_TCP:
srcport = ntohs(tmp_tcphdr->source);
dstport = ntohs(tmp_tcphdr->dest);
break;
case IPPROTO_ICMP:
srcport = tmp_icmphdr->type;
dstport = tmp_icmphdr->code;
break;
default:
srcport = dstport = 0;
break;
}

printf("Received log message\n");
printf("proc_name: %s\n", ulog_packet->proc_name);
printf("pid: %d\n", ulog_packet->pid);
printf("src port: %i\n", srcport);
printf("dst port: %i\n", dstport);


I think that it is not a good practise to typecast the data received
against structure as it will have portability issues !!

Karthik Balaguru
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert an info file(bash.info.gz) to a single html file Darwish Linux - Software 2 09-24-2005 07:51 AM
YUM: Damaged header.info the_styler Fedora 6 10-25-2004 02:58 PM
bad 'updates' header.info from freshrpms.net? -Nw- neX Fedora 4 08-18-2004 11:38 AM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 03:24 AM
I want change mail header info, which config file i should modify? exper Linux - Software 2 12-05-2003 07:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration