libipq and ipq_packet_msg_t (desperate)
maarten.wijnants at pandora.be
Wed Dec 15 16:44:55 CET 2004
> Now that I got the ip header, and TCP header.. I am confused on how to get
> to the TCP payload. Correct me if I am wrong, but the ipq_packet_msg_t
> structure is composed of the complete packet. e.g. ethernet header, IP
> header, TCP header and data.
You are correct in the fact that the ipq_packet_msg_t structure contains the
complete packet, but the ethernet header is NOT included. So in the case of
a TCP/IP packet, the payload of the ipq_packet_msg_t structure first
contains the IP header and then the TCP header and then the (TCP) payload.
> So what I need to do is setup offsets from
> the ipq_packet_msg_t->payload to point to each of these areas within the
> So what I need know is how to get the offset of the payload(data portion).
Well this is exactly what the code snippet shows. You first parse the ip
header of the packet (with struct iphdr) to retrieve the (variable) length
of the IP header. You add this amount of bytes to the payload member of the
ipq_packet_msg_t structure. Add this moment, you are pointing to the
position in the received packet where the TCP header begins. So you parse
the TCP header (with struct tcphdr) to retrieve the (variable) length of the
TCP header. If you now also add this amount of bytes, you will point to the
payload of your packet.
> I also need to find the length of the payload section.
This information can also be found by parsing the IP header of the packet
with the struct iphdr. This struct has a member which specifies the total
length of the IP packet (including headers!!).
More information about the netfilter-devel