Extracting the tcp header from a IPv4/IPv6 packet

Juan Luis Baptiste juancho at linuxmail.org
Tue Oct 15 13:39:39 EDT 2002


Hi,   
   
I'm coding an element to be used with the IPv4/IPv6   
translation elements (AddressTRanslator,   
protocolTranslator46 and protocolTranslator64) to translate   
EPSV/EPRT FTP commands as FtpPortMapper does.   
   
I'm having a little problem extracting the tcp header from   
the packets, in both ways (ipv4->ipv6 and ipv6->ipv4).   
   
This is how I do it:   
   
With a IPv6 packet (wich has PASV/PORT commands that needs   
to be translated to EPSV/EPRT):   
   
click_ip6 *ip6 = (click_ip6 *)p->data();   
const click_tcp *tcph = (click_tcp *)ip6 + 1;   
const unsigned char *data = (unsigned char *)tcph + 1;   
unsigned data_offset = (unsigned)data + (tcph->th_off<<2);   
unsigned len = p->length() - strlen((char *)data);   
   
Starting a telnet session, if I print tcph->th_off, it has a   
value of 0, but in both protocolTranslator's I can see that   
the value is 40.   
   
With a IPv4 packet a get a seg fault when trying to   
print/use tcph->th_off. This is the code I use, wich was   
taken from FtpPortMapper:   
   
const click_ip *iph = p->ip_header();   
const click_tcp *tcph = p->tcp_header();   
unsigned data_offset = p->transport_header_offset() +   
(tcph->th_off<<2);   
const unsigned char *data = p->data() + data_offset;   
unsigned len = p->length() - data_offset;   
   
What I think is happening is that I'm not getting to the   
right point in the packet where the tcp header starts, and   
I'm getting the wromg values for the tcp header and data.   
   
Any clues?   
   
Thanks!   
 
Juan Luis Baptiste M. 
-- 
Get your free email from www.linuxmail.org 


Powered by Outblaze




More information about the click mailing list