Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site redwood.UUCP
Path: utzoo!watmath!clyde!bonnie!akgua!mcnc!decvax!decwrl!amd!fortune!foros1!redwood!rpw3
From: rpw3@redwood.UUCP (Rob Warnock)
Newsgroups: net.lan
Subject: Re: (DoD) InterNet Header Checksum
Message-ID: <52@redwood.UUCP>
Date: Sat, 29-Sep-84 06:57:45 EDT
Article-I.D.: redwood.52
Posted: Sat Sep 29 06:57:45 1984
Date-Received: Mon, 1-Oct-84 07:26:05 EDT
References: <624@ttds.UUCP>
Organization: Rob Warnock, Redwood City, CA
Lines: 42

+---------------
| Version 4 IHL 5 service 0 totlen 29
| id 116 flags 0 fragoffs 0
| ttl 255 prot 255 chksum 43606
| sadr 192 9 200 2 dadr 192 9 200 1
| 
| which gives the following 16-bit words:
| 17664, 29, 116, 0, 65535, 0, 49161, 51202, 49161, 51201
| 
| ... At least not 43606. If I sum all the words,
| negate the sum and take the right sixteen bits I get 43611. That is
| 5 bigger, but that's not the proper algorithm....
| 
| What is my error? 
+---------------

I don't have all the references at hand I need to check your math, but
one thing to note: one's complement addition includes end-around carries.
From the way you say "take the right sixteen bits", I suspect you are not
doing the carries. That could easily lead to your discepancy of "5".

There was some Pascal code I saw in one of the Xerox XNS documents that
may help. (I know, the two checksums are not the same. XNS also rotates
the sum each step. But one's-comp arith should be the same.) Try using
the following "C" code fragment (or InterLisp equivalent) in your inner
sum loop:

	long sum, word;			/* Have to hold at least 131070 */
	...
	if ( (sum += word) > 65535 )	/* Did we get a carry out the left? */
		sum -= 65535;		/* Yes, add it back into the right.
					 * TRICKY! This is actually adding 1
					 * and subtracting 65536.
					 */
Hope this helps!

Rob Warnock

UUCP:	{ihnp4,ucbvax!amd}!fortune!redwood!rpw3
DDD:	(415)369-7437
Envoy:	rob.warnock/kingfisher
USPS:	Suite 203, 4012 Farm Hill Blvd, Redwood City, CA  94061