tcp checksum calculation incorrect - off by 2
tcp checksum calculation incorrect - off by 2
- Subject: tcp checksum calculation incorrect - off by 2
- From: "Raj Hariginadoni" <email@hidden>
- Date: Mon, 16 Jul 2007 09:46:02 -0400
Hi Folks,
I am looking at a driver code for OS X 10.3 where the checksum is
being calculated on an inbound syn-ack. First by zeroing out the
checksum, then calculating the checksum of the pseudo header and
finally calculating the checksum. The checksum functions used are
available in the xnu sources.
Here is the snippet
printf("tcplen =%x",tcplen);
printf(" checksum Before=%x,\n",tcph->th_sum);
tcph->th_sum=0;
tcph->th_sum = in_pseudo(iph->ip_src.s_addr, iph->ip_dst.s_addr,
htonl((iph->ip_p << 16) | (tcplen & 0xffff)));
tcph->th_sum = in_cksum_skip(mbuf, packet_len, iph->ip_hl << 2);
printf("final checksum tcph=%x,\n",tcph->th_sum);
The final checksum is less by 2 than the original. Here is the sample output
tcplen=26
checksum before =7182
final checksum=7180
tcplen=26
checksum before =2d87
final checksum=2d85
tcplen=26
checksum before =5ab0
final checksum=5aae
I have also observed that the checksum is calculated correctly when
the length of the tcp segment in the packet is 40.
tcplen=40
checksum before =d1cf
final checksum=d1cf
tcplen=40
checksum before =e237
final checksum=e237
Can someone guide me in solving this problem?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden