Extracting the tcp header from a IPv4/IPv6 packet

Juan Luis Baptiste juancho at linuxmail.org
Wed Oct 16 13:44:35 EDT 2002


Hi Eddie, 
 
First of all thanks for your fast response! 
 
>That looks like the correct code, but it will only work if 
>the packet has 
>gone through a CheckIPHeader or MarkIPHeader element 
>previously. (It 
>depends on the "IP header annotation".) 
 
Yes. This corrected the problem. I inserted a CheckIPHeader 
(when called from IPv4) and CheckIP6Header (when called from 
IPv6) before calling my element and everything seems to 
work. 
 
[...] 
 
>Don't know much about IP6, but I believe there might be 
>other headers 
>between the IP header and the TCP header.  
 
Well, what you say is true, but as how the IPv4/IPv6 
protocol translator works, it discards packets that have any 
extension header, so in this moment to my element are 
arriving IPv6 packets with no extension headers. I know this 
make it a little limited, but for now I'm concentrating in 
getting it working, later I'll try to make it cooler :-)  
 
>And have you stripped off any Ethernet header? 
 
I'm doing a Strip(14) after a Classifier and before the 
CheckIPHeader element at the beginning but nowhere else, 
like this: 
 
extern_class[2] 
	-> Strip(14) 
	-> CheckIP6Header(3ffe:1ce1:2:0:200::ffff 
3ffe:1ce1:2::ffff) 
	-> GetIP6Address(24) 
	-> ipv6rt; 
 
intern_class[2] 
	-> Strip(14) 
	-> CheckIPHeader(192.168.1.255) 
	-> GetIPAddress(16) 
	-> ipv4rt; 
 
Would you like to see my config file? 
 
[...] 
 
>Even aside from that, your code is pretty suspect. Don't 
>use strlen(), for 
>example; the packet data is not a null-terminated string. 
> 
>And you've got 
>the precedence of casts wrong. To get the TCP header, you 
>want  
>(click_tcp *)(ip6 + 1)  not  ((click_tcp *)ip6) + 1  (which 
>is what you 
>have now). Try something like: 
 
> click_ip6 *ip6 = (click_ip6 *)p->data();    
> click_tcp *tcph = (click_tcp *)(ip6 + 1); 
> unsigned char *data = (unsigned char *)tcph + 
(tcph->th_off << 2); 
> unsigned len = (p->data() + p->length()) - data; 
 
Ok, I will do this, but now I don't have very clear how to 
get the data offset... 
 
Thanks for the seggestions! 
 
Juan Luis 
-- 
Get your free email from www.linuxmail.org 


Powered by Outblaze




More information about the click mailing list