Re: Checksums (was Re: Ping, checksum algorithm?)


mnetor!spectrix!yunexus!maccs!Ariel%en-c06.Prime.COM@uunet.uu.net
7 Apr 88 04:36:55 GMT


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



This archive was generated by hypermail 2.0b3 on Thu Mar 09 2000 - 14:41:55 GMT