From: Scott MacKay Subject: Re: libipq/payload doubt Date: Thu, 20 May 2004 09:24:58 -0700 (PDT) Sender: netfilter-devel-admin@lists.netfilter.org Message-ID: <20040520162458.75930.qmail@web13906.mail.yahoo.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Ulysses Almeida , Netfilter Devel Return-path: To: Henrik Nordstrom In-Reply-To: Errors-To: netfilter-devel-admin@lists.netfilter.org List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: List-Id: netfilter-devel.vger.kernel.org AH yes, mentioned in my sentences, not in code :P instead of sizeof(ip) you will want the offset... Note that the ip protocol does not need htons() Also, since ipHeader->tot_len represents the entire ip datagram in case you want to do any validation on the settings for the header size indicators. int utilities::ip_payload_offset(unsigned char *ip_packet) { unsigned int offset=0; struct tcphdr *tcpHeader; struct iphdr *ipHeader; ipHeader=(struct iphdr *)ip_packet; // Determine offset into packet contents. if (ipHeader.protocol==IPPROTO_TCP) { tcpHeader=(tcphdr *)(ip_packet+ipHeader->ihl*4); offset=ipHeader->ihl*4 + tcpHeader->doff*4; if (ipHeader.protocol==IPPROTO_UDP) { offset=ipHeader->ihl*4+8; } else { return -1; } return offset; } --- Henrik Nordstrom wrote: > On Thu, 20 May 2004, Scott MacKay wrote: > > > // Determine offset into packet contents. > > if (ip_packet[9]==6) { > > tcpHeader=(tcphdr *)(ip_packet+sizeof(ip)); > > Don't do this. There may be IP options extending the > size of the IP > header. Use iphdr->ihl to find the IP header size in > the same manner as > tcphdr->doff is used to find the size of the TCP > header.. > > Regards > Henrik > > __________________________________ Do you Yahoo!? Yahoo! Domains – Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer