Checksums (was Re: Ping, checksum algorithm?)


gordan (mnetor!spectrix!yunexus!maccs!gordan@uunet.uu.net)
23 Mar 88 01:03:47 GMT


BAD MSG:
required.

Note the TCP length must be calculated as the total IP Length (0x4b in
this case) minus the length of the IP header (5 32-bit words in this
case, or 0x14 (decimal 20) bytes). The TCP header itself does not store
the number of bytes of TCP data, so the TCP layer relies on the IP layer
to supply it with this information.

This describes how the sender of a packet calculates the checksum. The
receiver, on the other hand, can verify the checksum quickly in the
following manner: it simply one's complement sums the 16-bit words and
checks if the result is 0xffff (except UDP's special case behavior must
again be taken into account) -- if it is, the checksum is correct and
the packet data is valid.

A moment's thought should show why this works. Recall that when the
sender calculated the checksum, the checksum field itself was zero; when
the receiver looks at the header, however, the field has been filled in.
The checksum is the one's complement of the one's complement sum, and
whenever a number and its one's complement are added together, the
result is 0xffff.

--
Many Americans work side by side with space
aliens who look	human -- but you can spot
these visitors by looking for certain		    Gordan Palameta
tip-offs, say experts.				    mnetor!maccs!gordan



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