This document provides an example of calculating an internet checksum for a packet header. It describes taking the packet header bytes and forming 16-bit words, then summing the words using 32-bit arithmetic and taking the 1s complement of the result to get the checksum value. The checksum is added to the packet header and re-calculated at the receiver to check for errors.
This document provides an example of calculating an internet checksum for a packet header. It describes taking the packet header bytes and forming 16-bit words, then summing the words using 32-bit arithmetic and taking the 1s complement of the result to get the checksum value. The checksum is added to the packet header and re-calculated at the receiver to check for errors.
Simplified example internet checksum calculation (example from the Net)
Assume the packet header is: 01 00 F2 03 F4 F5 F6 F7 00 00 (00 00 is the checksum to be calculated) The first step is to form 16-bit words. 0100 F203 F4F5 F6F7 The second step is to calculate the sum using 32-bits. 0100 + F203 + F4F5 + F6F7 = 0002 DEEF The third step is to add the carries (0002) to the 16-bit sum. DEEF + 002 = DEF1 The fourth step is to take the complement. (1s becomes 0s and 0s become 1s) ~DEF1 = 210E
So the checksum is 21 0E. The packet header is sent as: 01 00 F2 03 F4 F5 F6 F7 21 0E
At the receiver, the steps are repeated. The first step is to form 16-bit words. 0100 F203 F4F5 F6F7 210E The second step is to calculate the sum using 32-bits. 0100 + F203 + F4F5 + F6F7 + 210E = 0002 FFFD The third step is to add the carries (0002) to the 16-bit sum. FFFD + 0002 = FFFF which means that no error was detected. (In 1s complement, zero is 0000 or FFFF.)