CAP7001 · Unit 5: Transport layer
Port and socket addresses, UDP
10 practice questions · in the ETE syllabus
Key points
- Ports are 16 bits; socket address = IP address + port
- UDP header is 8 bytes: ports, length, checksum
- UDP gives no handshake, ordering or retransmission
- Checksum is the one's complement of the folded 16-bit sum
- A computed checksum of 0 is sent as 0xFFFF
A port number is a 16-bit value (0 to 65535) that selects an application on a host. Well-known ports are 0 to 1023, such as DNS 53, HTTP 80 and SMTP 25. A socket address is the pair IP address plus port number, such as 203.0.113.5:80, and a connection is identified by the two socket addresses.
UDP is connectionless and unreliable: no handshake, no acknowledgments, no ordering, no retransmission. This keeps it light for DNS, streaming and DHCP. The header is 8 bytes with four 16-bit fields: source port, destination port, length and checksum. The Length field counts header plus data, so a length of 1008 means 1000 data bytes.
UDP checksum: add all 16-bit words using one's-complement arithmetic, wrapping any carry back into the sum, then complement the result. The receiver adds everything including the checksum and expects 0xFFFF.
Worked example: words 0xF000, 0xF000 and 0x1234 sum to 0x1E000 + 0x1234, which folds to 0xF235, so the checksum is 0x0DCA.
In IPv4 a checksum field of 0 means no checksum was computed, so a computed result of 0x0000 is sent as 0xFFFF.
A UDP server tells clients apart by the source IP address and port of each datagram it receives.
Exam trap: forgetting to wrap the carry, or sending the plain sum instead of its complement.
Try two questions
What is a socket address?
- The combination of an IP address and a port number
- The combination of a MAC address and an IP address
- The combination of a port number and a checksum
- The combination of two IP addresses at both ends
Show the answer
A. A socket address names one endpoint of a communication, such as 203.0.113.5:80.
Why not B: A MAC and IP pair is not a socket address.
Why not C: Checksums do not identify an endpoint.
Why not D: Two IP addresses describe a path, not an endpoint.
Which statement about UDP is correct?
- It retransmits lost datagrams using acknowledgements
- It provides no delivery guarantee and keeps no connection state
- It sets up a connection with a three-way handshake
- It orders datagrams by sequence number before delivery
Show the answer
B. UDP is connectionless and unreliable, which keeps it lightweight.
Why not A: Retransmission is a TCP feature.
Why not C: The three-way handshake belongs to TCP.
Why not D: UDP has no sequence number field.