K10148_C059
K10148_C059
User Datagram
Protocol—UDP
Aleksander
Malinowski 59.1 Introduction..................................................................................... 59-1
Bradley University 59.2 Protocol Operation.......................................................................... 59-1
UDP Datagram • Port Number Assignments • Connectionless
Bogdan M. Service—Flow and Error Control
Wilamowski 59.3 Programming Samples...................................................................59-8
Auburn University References................................................................................................... 59-10
59.1 Introduction
User datagram protocol (UDP) is a part of TCP/IP suite [STD6,C02-1,F10,GW03,PD07]. It provides
full transport layer services to applications. It belongs to the transport layer in the TCP/IP suite model,
as shown in Figure 59.1. UDP provides a connection between two processes at both ends of transmis-
sion. This connection is provided with minimal overhead, without flow control or acknowledgment of
received data. The minimal error control is provided by ignoring (dropping) received packets that fail
the checksum test.
The UDP is standardized by Internet Society, which is an independent international not-for-profit
organization. A complete information about UDP-related standards is published by RFC Editor [RFC].
Several relevant RFC articles as well as further reading materials are listed at the end of this article.
59-1
Application layer
Transport layer
TCP UDP
Network layer
Physical layer
Processes Processes
(running application program) (running application program)
Internet
Domain of IP protocol
Domain of UDP protocol
pattern or protocol but there is no guarantee that all data reach the destination and that the order of
their receiving would be the same as the order they were sent. The client–server approach, which is
usually used to describe interaction between two processes, still can be used. The process that may be
identified as waiting for the data exchange is called the server. The process that may be identified as one
that initializes that exchange is called the client.
8 bytes
Header Data
• Total length: This is a 16 bit field that contains the total length of the packet. Although the num-
ber could be in the range from 0 to 65,535, the minimum length is 8 bytes that correspond to the
packet with the header and no data. The maximum length is 65,507 because 20 bytes are used by
the IP header and 8 bytes by the UDP header. Thus, this information is redundant to the packet
length stored in the IP header. An extension to UDP that allows for transmission of larger data-
grams over IPv6 packets has been standardized [RFC2675] [RFC2147]. In such a case, the UDP
header specified total length is ignored.
• Checksum: This 16 bit field contains the checksum. The checksum is calculated by
• Initially filling it with 0’s.
• Adding a pseudoheader with information from IP, as illustrated in Figure 59.4.
• Treating the whole segment with the pseudoheader prepended as a stream of 16 bit
numbers. If the number of bytes is odd, 0 is appended at the end.
• Adding all 16 bit numbers using 1’s complement binary arithmetic.
• Complementing the result. This complemented result is inserted into the checksum field.
• Checksum verification: The receiver calculates the new checksum for the received packet that
includes the original checksum, after adding the so-called pseudoheader (see Figure 59.4). If the
new checksum is nonzero, then the datagram is corrupt and is discarded.
8 bit
All 0s 16 bit UDP total length
protocol
Data
(padding must be added to make the data
a multiple of 16 bits)
In case of UDP, the use of checksum is optional. If it is not calculated then the field is filled with 0’s.
The receiver can determine whether checksum was calculated by inspecting the field. Even in case the
checksum is 0 the field does not contain 0 as the calculated checksum is complemented at the end of the
process and negative 0 (the field filled with 1’s) is stored.
FIGURE 59.7 Sample C program that illustrates a UDP server utilizing multicasting.
(continued)
other error control than the checksum discussed above. The sender cannot be requested to resend any
datagram. However, an upper level protocol that utilizes UDP may implement some kind of control. In
that case, unlike in TCP, no data is repeated by resending the same datagram. Instead, the communicat-
ing process sends a request to send some information again. Trivial file transfer protocol (TFTP) is a
very good example of that situation [STD33]. Since it has its own higher level flow and error control, it
can use UDP as a transport layer protocol instead of TCP. Other examples of UDP utilization are simple
network management protocol (SNMP) [STD62] or any other protocol that requires only simple short
request-response communication.
Internet socket is an end point of a bidirectional interprocess communication flow across an IP-based
computer network. Interface to the socket library is standardized only on Unix/Linux and Windows. Other
operating systems including various embedded systems may employ different functions to carry out the same
functionality. Programs of the same functionality implemented in other languages may combine several
steps into calling a single function. This is especially true for the socket initialization and connection set up.
FIGURE 59.8 Sample C program that illustrates a UDP client utilizing multicasting.
(continued)
References
[C02–1] D. Comer, Internetworking with TCP/IP Vol. 1: Principles, Protocols, and Architecture, 5th edn.,
Prentice Hall, Upper Saddle River, NJ, 2005.
[C02–3] D. Comer et al., Internetworking with TCP/IP, Vol. III: Client-Server Programming and
Applications, Linux/Posix Sockets Version, Prentice Hall, Upper Saddle River, NJ, 2000.
[F10] B.A. Forouzan, TCP/IP Protocol Suite, 4th edn., McGraw-Hill, New York, 2010.
[GW03] A. Leon-Garcia, I. Widjaja, Communication Networks, 2nd edn., McGraw-Hill, New York, 2003.
[IANA] Web Site for IANA - Internet Assigned Numbers Authority, http://www.iana.org/
[PD07] L.L. Peterson, B.S. Davie, Computer Networks: A System Approach, 4th edn., Morgan Kaufmann
Publishers, San Francisco, CA, 2007.
[RFC] Web Site for RFC Editor, http://www.rfc-editor.org/
[RFC2147] D. Borman et al., TCP and UDP over IPv6 Jumbograms, May 1997. http://www.rfc-editor.org/
[RFC2675] D. Borman et al., IPv6 Jumbograms, August 1999. http://www.rfc-editor.org/
[RFC3171] Z. Albana, K. Almeroth, D. Meyer, M. Schipper, IANA Guidelines for IPv4 Multicast Address
Assignments, August 2001. http://www.rfc-editor.org/
[RFC3493] R. Gilligan et al., Basic Socket Interface Extensions for IPv6, February 2003. http://www.rfc-
editor.org/
[STD2] J. Reynolds, J. Postel, Assigned Numbers, October 1994. http://www.rfc-editor.org/
[STD5] J. Postel, Internet Protocol, September 1981. http://www.rfc-editor.org/
[STD6] RFC0768/STD0006, J. Postel, User Datagram Protocol, August 1980. http://www.rfc-editor.org/
[STD33] K. Sollins, The Tftp Protocol (Revision 2), July 1992. http://www.rfc-editor.org/
[STD62] D. Harrington, R. Presuhn, B. Wijnen, An Architecture for Describing Simple Network Management
Protocol (SNMP) Management Frameworks, December 2002. http://www.rfc-editor.org/