Back to the 2024 paper

Module 4: Transport Layer & Congestion Control

20247m

Describe the various fields of UDP segment and also explain about UDP checksum with an example?

Worked SolutionAI Assisted

UDP segment format

UDP (User Datagram Protocol) is a connectionless, unreliable transport protocol with a very small 8-byte header:

 0                16                31
+-----------------+-----------------+
|  Source Port    | Destination Port|
|    (16 bits)    |    (16 bits)    |
+-----------------+-----------------+
|     Length      |    Checksum     |
|    (16 bits)    |    (16 bits)    |
+-----------------+-----------------+
|         Data (application)        |
+-----------------------------------+
Field Size Description
Source port 16 bits Port of the sending process (optional; 0 if unused). Used as the reply address
Destination port 16 bits Port of the receiving process (e.g. 53 = DNS, 67/68 = DHCP)
Length 16 bits Length of the UDP header + data in bytes (minimum 8)
Checksum 16 bits Error detection over the pseudo-header, UDP header and data

Features: connectionless (no handshake), no acknowledgements, no retransmission, no flow or congestion control, preserves message boundaries, low overhead and fast. Used for DNS, DHCP, streaming, VoIP, online games, SNMP.

UDP checksum

The checksum is the 1's complement of the 1's complement sum of all 16-bit words of the pseudo-header (source IP, destination IP, zero byte, protocol = 17, UDP length), the UDP header (with the checksum field set to 0) and the data. If the total length is odd, the data is padded with a zero byte.

Sender's steps

  1. Divide the data into 16-bit words.
  2. Add all words using 1's complement addition (any carry out of the top bit is wrapped around and added back to the least significant bit).
  3. Complement the result (invert every bit). This is the checksum.

Receiver's steps

Add all the words including the checksum. If there is no error, the sum is 1111 1111 1111 1111. Any 0 bit means an error, and the datagram is discarded.

Example

Three 16-bit words:

Word 1 :  0110 0110 0110 0110   (0x6666)
Word 2 :  0101 0101 0101 0101   (0x5555)
Word 3 :  0000 1111 0000 1111   (0x0F0F)

Step 1: Word 1 + Word 2

  0110 0110 0110 0110
+ 0101 0101 0101 0101
= 1011 1011 1011 1011   (no carry)

Step 2: add Word 3

  1011 1011 1011 1011
+ 0000 1111 0000 1111
= 1100 1010 1100 1010   (0xCACA, no carry)

Step 3: 1's complement of the sum

Sum        = 1100 1010 1100 1010
Checksum   = 0011 0101 0011 0101   (0x3535)

Verification at the receiver: 0xCACA + 0x3535 = 0xFFFF = 1111 1111 1111 1111, so the data is accepted.

Wrap-around example: 1111 1111 1111 1111 + 0000 0000 0000 0010 = 1 0000 0000 0000 0001; wrapping the carry gives 0000 0000 0000 0010.

Limitations: the checksum detects most single-bit and burst errors but cannot correct them, and two compensating errors can go undetected. In IPv4 the checksum is optional (0 means "not computed"); in IPv6 it is mandatory.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.