IPv6 Network - THE IPV4, TCP, AND UDP CHECKSUM The checksum algorithm for the IPv4 header, TCP, and UDP is “the 16-bit one’s complement of the one’scomplement sum of all 16-bit words in the header” (RFCs 791 (IP), 792 (ICMP), 793 (TCP), and 768 (UDP), respectively). One’s complement math is slightly different from normal math. When adding the decimal values 32768 and 49152, the result is 81920. In hexadecimal, that would be 0x8000 + 0xC000 = 0x14000, or 0x4000 with a carry bit when using 16 bits. In one’s complement additions, the carry bit is added to the result, making the 16-bit one’s complement addition of 0x8000 and 0xC000 equal to 0x4001. As usual with checksums and CRCs, the value is computed at the source and transmitted along with the data. The destination performs the same computation and compares the value found in the packet with the new result. If they’re the same, presumably the packet didn’t change in transit. An interesting property of one’s complement math is that the values 0x0000 and 0xFFFF are equivalent: adding 0x0000 to a value has the same result as adding 0xFFFF to that value. For instance: 0x6201 + 0x0000 = 0x6201 (obviously). 0x6201 + 0xFFFF would normally be 0x16200, but with the special treatment for the carry bit, this also becomes 0x6201. This means that the value 0x0000 can be inserted in the UDP checksum field to indicate that a checksum wasn’t computed. The TCP, UDP, and ICMPv6 checksums are computed over a “pseudo header” and the TCP, UDP, or ICMPv6 header, and user data respectively. The pseudo header consists of the source and destination addresses, the upper-layer packet length, and the protocol number. Including this information in the checksum calculation makes sure that TCP, UDP, or ICMPv6 don’t process packets that were delivered incorrectly, for instance, because of a bit error in the IP header.