Date: Thu, 18 May 2000 18:05:56 +1200 From: Dave Preece <dave.preece@kbgroup.co.nz> To: hackers@freebsd.org Subject: Musings on ip checksumming Message-ID: <67B808B0DD93D211ABEE0000B498356B02BBF9@internet.kbgroup.co.nz>
next in thread | raw e-mail | index | archive | help
I'm trying to write a simple static NAT, and have got a bit stuck with the new checksum in the IP header.... thing with me is that I'm not happy about something till I understand it (and it appears that the IP stack is well behaved and won't send something unless the IP checksum is right either). Looking into ping.c for an example we have a checksum calculator (in_cksum) that I have been trying to understand. It takes a header and adds all the 16 bit words to a 32 bit acumulator. Fine. It then takes the top 16 bits and adds them to the bottom 16, (adding an additional one if this operation itself takes the resulting number to 17). Not what I understand as a checksum, but none the less a perfectly valid algorithm. What I *don't* understand is this: The routine appears to be written as if would only work on a big endian system i.e. this would only work if u_short's and int's were stored most significant byte first. This impression is further underscored by using >> 16 to fold the top 16 bits into the lower 16 bits. The pile of htons calls and ntohs calls I was expecting to see is simply not there. So, how come it works? Dave :) (but a bit confused) Ref: /usr/src/sbin/ping/ping.c /usr/src/lib/libalias/alias_local.h (ADJUST_CHECKSUM) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?67B808B0DD93D211ABEE0000B498356B02BBF9>