Path: utzoo!attcan!uunet!ginosko!gem.mps.ohio-state.edu!apple!bionet!ames!think!kulla!barmar From: barmar@kulla (Barry Margolin) Newsgroups: comp.protocols.tcp-ip Subject: Re: Checksum Byte Order...What is it? Message-ID: <30228@news.Think.COM> Date: 27 Sep 89 19:41:40 GMT References:Sender: news@Think.COM Distribution: na Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 24 In article adnan@sgtech.UUCP (Adnan Yaqub) writes: > ip->ip_sum = in_cksum(m, hlen); >Since the checksum is a 16-bit quantity, it would see to me that one >would get a different value depending on whether the host is big or >little endian. I looked at in_cksum_c (I don't have a copy of >in_cksum), and it doesn't seem to be endian sensitive. (I may be >wrong, because the code is quite tricky.) This is due to an interesting feature of 16-bit one's-complement checksums with end-around carry: it automatically does the right thing! It's because the checksum routine is reading the packet in 16-bit chunks in host byte order. Since it isn't converting from network order to host order before summing, it doesn't have to convert back to network order when storing the sum. There's a rigorous proof (which I don't know) that this always produces the right result. I think the end-around carry is the part of the checksum algorithm that does it; it means that carries out of the high-order byte act just like carries out of the low-order byte, being added into the other byte, so the byte order is not significant (an implementation has to be consistent, though). Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar