This blog post covers how to calculate the UDP checksum field with an example.
First, let us understand what constitutes to UDP checksum field calculation - UDP header, Pseudo header, and the UDP Data.
UDP Header is of 32 bits sourcePort (8 bits), destinationPort (8 bits), length (8 bits), and checksumField (8 bits). The sourcePort and destinationPort values are trivial so I will not be discussing them in detail here. The length field is the sum of length of the UDP header and the UDP data. The checksumField is initialized to zero.
The Pseudo header consists of sourceIP (32 bits), destinationIP (32 bits), 0000 0000 (8 bits), protocolField (8 bits), and length (16 bits). The sourceIP and destinationIP values are trivial so I will not be discussing them in detail here. The protocolField is from the IP layer and for UDP the value of protocolField is 0x11. Th length field is similar to the the length field described in the above paragraph with the exception of being padded with zero's to make it a 16 bit field.
The UDP Data is the data part of the UDP segment.
Example: For the given ethernet frame, calculate the UDP checksum field.
For the given ethernet frame, calculate the UDP checksum field.
f8 bc 12 86 23 bf 50 9a 4c 1e bd 18 08 00 45 00 00 28 18 8f 40 00 40 11 8c 57 0a 72 40 b2 0a 72 40 49 13 88 13 88 00 14 00 00 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 f8 bc 12 86 23 bf 50 9a 4c 1e bd 18 08 00 45 00 00 28 18 8f 40 00 40 11 8c 57 0a 72 40 b2 0a 72 40 49 13 88 13 88 00 14 00 00 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64
From the above frame, the following fields can be deduced
Ethernet Header
IP Header
UDP Header
UDP Data = 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64
Therefore, the UDP checksum segment = 13 88 13 88 00 14 00 00 0a 72 40 b2 0a 72 40 49 00 11 00 14 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64
Steps to calculate the UDP checksum