libipq and ipq_packet_msg_t (desperate)

Henrik Nordstrom hno at marasystems.com
Thu Dec 16 08:17:44 CET 2004


On Wed, 15 Dec 2004, Steven J Scott wrote:

> Hello Maarten,
>
> Thanks for the clarification of ipq_packet_msg_t and what is consists of.  I had a feeling it didn't contain ethernet
> header.
>
> So to calculate the offset of the payload would look like the following:
>
> struct iphdr *iph = ((struct iphdr *)m->payload);
> struct tcphdr tcp = (struct tcphdr *)(m->payload + (iph->ihl << 2));
>
> char *payload = ( (char*)tcp) + sizeof(struct tcphdr);
> int payload_length = ntohs(iph->tot_len) - ( sizeof(struct tcphdr) +
> sizeof(struct iphdr) );
>
> Is that correct?

No. You need to use the correct header fields, not sizeof. Something like 
the following should work

payload = ((char *)tcp) + (tcp->doff << 2);

payload_length = ntohs(iph->tot_len) - (payload - (char *)iph);

Regards
Henrik



More information about the netfilter-devel mailing list