Path: utzoo!yunexus!maccs!Ariel@en-c06.Prime.COM From: Ariel@en-c06.Prime.COM Newsgroups: comp.protocols.tcp-ip Subject: Re: Checksums (was Re: Ping, checksum algorithm?) Summary: more C code for doing TCP/IP checksums Keywords: checksums Message-ID: <1115@maccs.UUCP> Date: 7 Apr 88 04:36:55 GMT Article-I.D.: maccs.1115 Posted: Thu Apr 7 00:36:55 1988 References: <8803301719.AA03945@braden.isi.edu> Sender: gordan@maccs.UUCP Reply-To: Ariel@en-c06.Prime.COM Lines: 51 Forwarded article follows: ---------------------------------------------------------------- Hi, I noted your article about the TCP and IP checksum algorithm on Usenet. Feel free to post this if you feel it is of interest; I only have CSnet/ARPAnet access. The algorithm used by Prime's TCP/IP/X.25 software is very similar to your "psuedo-code". Note that it is not necessary to add the carries back in until the end. (Prime 50-series machines have network byte order) ---------------------------------------------------------------- int checksumIP(ip) IP_header *ip; { uns16 *word; uns32 sum; int count; ip->IP_checksum = 0; count = ip->IP_IHL * 2; sum = 0; word = (uns16 *)ip; /* magic occurs ... */ while (count--) sum += *word++; while (sum > 0xFFFF) sum = (sum & 0xFFFF) + (sum >> 16L); sum = (~sum & 0xFFFF); ip->IP_checksum = sum; return; } ---------------------------------------------------------------- Note that most of the work is in the single instruction while loop, with a non-complex termination test. The second while loop is executed at most twice. A 9955 or 6350 running this in CIX mode blows the doors off of any poor controller micro-processor. Robert Ullmann Prime.COM zone/domain adminitrator Ariel@en-c06.Prime.COM