how to program a conntrack module

Svenning Sørensen sss@sss.dnsalias.net
Sat, 27 Oct 2001 01:41:46 +0200


> struct tcphdr *th = ( struct tcphdr *)(iph+iph->ihl*4 );
>
> printk("ctinfo = %u\n", ctinfo );
> printk( "[tcp_help()]: source %d.%d.%d.%d dst %d.%d.%d.%d sport %u dport
> %u\n", NIPQUAD( iph->sad
> dr), NIPQUAD( iph->daddr ), th->source, th->dest );
> 
> return NF_ACCEPT;
> }
> 
> The part printing the "dport" and "sport" doesn't seems alright with the
> following result
> 
> Oct 26 23:56:16 suifai kernel: [tcp_help()]: source 192.168.73.107 dst
> 198.186.203.85 sport 0 dport 0
> 

Your pointer arithmetic works in units of struct iphdr.
You should cast the iph pointer to a char pointer first, like this:

 struct tcphdr *th = (struct tcphdr *)(char *)iph+iph->ihl*4;

You also need to take care of endianness when printing the port numbers;
ntohs() is your friend.


Svenning