Skip to contentSkip to conversation

tcp checkum claculation!!

DISCUSSION Fallucchi Antonio 1 participant 1 message Sep 16, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

I need a Help for recalculate the checksum of TCP packet. I read the packet from iptables_queue, and sum 16 bit word from and add the pseudoheader ipsource, ipdest, 6, tcp_len (form the ip packet), and i see the buddy. I all width complement!

I have see the site http://www.netfor2.com/tcpsum.htm

and the my code is:

	for (i=0;i<11;i=i+2)
	{
		sum+=*pseudobuff++;
	}

	nwords=swap(len_tcp)-(len_ip*4);
	
	while(nwords>1)
	{
		sum+=*buff++;
		nwords-=2;	
	}
	if(nwords==1)
	{
		sum+=*(unsigned char *)buff;
	}
	
	sum=(sum>>16)+(sum&0xffff);
	sum+=(sum>>16);
	
	sum = ~sum;

but the result isn't correct...

tancks for the help.

bye bye