Table of Contents AIX
TCP/IP Tutorial and Technical Overview

2.11 User Datagram Protocol (UDP)

Figure: User Datagram Protocol (UDP)

UDP is a standard protocol with STD number 6. UDP is described by RFC 768 - User Datagram Protocol. Its status is recommended, but in practice every TCP/IP implementation which is not used exclusively for routing will include UDP.

UDP is basically an application interface to IP. It adds no reliability, flow-control or error recovery to IP. It simply serves as a ``multiplexer/demultiplexer'' for sending and receiving datagrams, using ports to direct the datagrams as shown in Figure - UDP, A Demultiplexer Based on Ports. For a more detailed discussion of ports refer to Ports and Sockets.

Figure: UDP, A Demultiplexer Based on Ports

UDP provides a mechanism for one application to send a datagram to another. The UDP layer can be regarded as being extremely thin and consequently has low overheads, but it requires the application to take responsibility for error recovery and so on.

2.11.1 Ports

The port concept was discussed earlier in Ports and Sockets.

Applications sending datagrams to a host need to identify a target which is more specific than the IP address, since datagrams are normally directed to certain processes and not to the system as a whole. UDP provides this by using ports.

A port is a 16-bit number which identifies which process on a host is associated with a datagram. There are two types of port:

Well-known ports belong to standard servers, for example TELNET uses port 23. Well-known port numbers range between 1 and 1023 (prior to 1992, the range between 256 and 1023 was used for UNIX-specific servers). Well-known port numbers are typically odd, because early systems using the port concept required an odd/even pair of ports for duplex operations. Most servers require only a single port. An exception is the BOOTP server which uses two: 67 and 68 (see BOOTstrap Protocol - BOOTP).

The reason for well-known ports is to allow clients to be able to find servers without configuration information. The well-known port numbers are defined in STD 2 - Assigned Internet Numbers.

Clients do not need well-known port numbers because they initiate communication with servers and the port number they are using is contained in the UDP datagrams sent to the server. Each client process is allocated a port number as long as it needs it by the host it is running on. Ephemeral port numbers have values greater than 1023, normally in the range 1024 to 5000. A client can use any number allocated to it, as long as the combination of <transport protocol, IP address, port number> is unique.

Note: TCP also uses port numbers with the same values. These ports are quite independent. Normally, a server will use either TCP or UDP, but there are exceptions. For example, Domain Name Servers (see Domain Name System (DNS)) use both UDP port 53 and TCP port 53.

2.11.2 UDP Datagram Format

Each UDP datagram is sent within a single IP datagram. Although, the IP datagram may be fragmented during transmission, the receiving IP implementation will re-assemble it before presenting it to the UDP layer. All IP implementations are required to accept datagrams of 576 bytes, which, allowing for maximum-size IP header of 60 bytes means that a UDP datagram of 516 bytes is acceptable to all implementations. Many implementations will accept larger datagrams, but this is not guaranteed. The UDP datagram has a 16-byte header which is described in Figure - UDP Datagram Format.

Figure: UDP Datagram Format


Source Port
Indicates the port of the sending process. It is the port to which replies should be addressed.
Destination Port
Specifies the port of the destination process on the destination host.
Is the length (in bytes) of this user datagram including the header.
Is an optional 16-bit one's complement of the one's complement sum of a pseudo-IP header, the UDP header and the UDP data. The pseudo-IP header contains the source and destination IP addresses, the protocol and the UDP length:

Figure: Pseudo-IP Header

The pseudo-IP header effectively extends the checksum to include the original (unfragmented) IP datagram.

2.11.3 UDP Application Programming Interface

The application interface offered by UDP is described in RFC 768. It provides for:

The way this should be implemented is left to the discretion of each vendor.

Be aware that UDP and IP do not provide guaranteed delivery, flow-control or error recovery, so these must be provided by the application.

Standard applications using UDP include:

Table of Contents Transmission Control Protocol (TCP)