2.6. UDPThe User Datagram Protocol (UDP) enables user applications to send and receive connectionless, unreliable datagrams. As a transport-layer protocol, UDP is carried in IP datagrams, as shown in Figure 2.13. Figure 2.13. UDP Datagram Encapsulation
UDP adds very little to the basic IP service on which it depends. First, UDP provides the ability to associate a UDP datagram with the sending and receiving processes through the source and destination port numbers. Recalling our earlier analogy of IP being like sending a letter, we could say that the IP address corresponds to the street address of an apartment building, whereas the port number corresponds to individual apartments. In any event, the receiving UDP uses the destination port number to demultiplex the UDP datagram to the proper application. If the application sends a reply, it will address the reply to the host given in the source address field of the IP header and the application given by the source port number. The other addition that UDP brings to the basic IP service is an optional checksum. We call the checksum optional because a host can disable its validation by setting it to 0. When present, the checksum covers the entire UDP datagramheader and data.
The UDP header is shown in Figure 2.14. The source port and destination port hold the port numbers. The checksum field is either the UDP checksum or 0. Figure 2.14. The UDP Header
The length field holds the total length of the datagram, including the header. Note that this field isn't really necessary, because the UDP datagram's length can be inferred from the length field of the encapsulating IP datagram. We shall see, in fact, that TCP does not have an explicit length field. UDP is specified in RFC 768 [Postel 1980]. |