Tcp checksum calculation wrong by 2
Raj
raj at thenewfront.us
Tue Jul 17 14:18:03 UTC 2007
Hi Folks,
This problem is related to Mac OS X 10.3. Please accept my apologies for
posting here , as I thought this is one avenue I could explore to get an
answer and also OS X has some freebsd core too!
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 be kind enough to give me an idea on why I am getting the wrong
checksum?
TIA
Raj
More information about the freebsd-net
mailing list