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);
|