Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.dcom.lans Subject: Re: Internet Protocol header checksum implementation problem Message-ID: <7899@utzoo.UUCP> Date: Sat, 11-Apr-87 22:07:13 EST Article-I.D.: utzoo.7899 Posted: Sat Apr 11 22:07:13 1987 Date-Received: Sat, 11-Apr-87 22:07:13 EST References: <328@dcl-csvax.comp.lancs.ac.uk> Organization: U of Toronto Zoology Lines: 21 > To calculate the checksum I take each 16-bits within the header ... > To each of these > I take the 16-bit one's complement and add them all up giving an > unsigned 16-bit value. This is then one's complemented to give me > the header checksum ... (as per the IP spec). The problem is that you have misunderstooding the meaning of the term "one's-complement addition". This does not mean adding the complements of the numbers. One's-complement addition is addition done by treating the 16-bit lumps as numbers in the obsolete one's-complement number representation, rather than the two's-complement representation that most modern computers use. See any good book on digital systems design for the details of what one's-complement representation is all about. The simple way to fake one's-complement addition on a two's-complement machine is to do a regular add and then add the carry to the result; on a 32-bit machine it's often better to do a 32-bit sum of all the 16-bit values and then add the top 16 bits to the bottom 16 (repeating this until the top 16 are zero). -- "We must choose: the stars or Henry Spencer @ U of Toronto Zoology the dust. Which shall it be?" {allegra,ihnp4,decvax,pyramid}!utzoo!henry