Professional Documents
Culture Documents
(Page 1 of 2)
What's the magic word when it comes to UDP? Right, simple. This is true of the
operation of the protocol, and it is also true of the format used for UDP messages.
Interestingly, however, it is here that we will actually encounter probably the only
aspect of UDP that is not simple. I bet that got you interested, huh? Okay, well, it
was a worth a try.
In keeping with the goal of efficiency, the UDP header is only eight bytes in length;
this contrasts with the TCP header size of 20 bytes or more. Table 147 and Figure
200 show the format of UDP messages.
Figure 200: UDP Message Format
Figure 200: UDP Message Format
The UDP Checksum field is the one area where the protocol actually is a bit
confusing. The concept of a checksum itself is nothing new; they are used widely in
networking protocols to provide protection against errors. What's a bit odd is this
notion of computing the checksum over the regular datagram and also a pseudo
header. What this means is that instead of calculating the checksum over just the
fields in the UDP datagram itself, the UDP software first constructs a “fake”
additional header that contains the following fields (Figure 201):
Figure 201: UDP Pseudo Header Format
The total length of this “pseudo header” is 11 bytes. It is padded to 12 bytes with a
byte of zeroes and then prepended to the real UDP message. The checksum is then
computed over the combination of the pseudo header and the real UDP message,
and the value is placed into the Checksum field. The pseudo header is used only for
this calculation and is then discarded; it is not actually transmitted. The UDP
software in the destination device creates the same pseudo header when calculating
its checksum to compare to the one transmitted in the UDP header.
Computing the checksum over the regular UDP fields protects against bit errors in
the UDP message itself. Adding the pseudo header allows the checksum to also
protect against other types of problems as well, most notably the accidental delivery
of a message to the wrong destination. The checksum calculation in UDP, including
the use of the pseudo header is exactly the same as the method used in TCP
(except the Length field is different in TCP). See the topic describing TCP checksum
calculation for a full description of why the pseudo header is important, and some of
the interesting implications of using IP fields in transport layer datagram calculations.
Key Concept: UDP packages application layer data into a very simple
message format that includes only four header fields. One of these is an
optional checksum field; when used, the checksum is computed over both the
real header and a “pseudo header” of fields from the UDP and IP headers, in a
manner very similar to how the TCP checksum is calculated.
Note that the use of the Checksum field is optional in UDP. If it is not used, it is set to
a value of all zeroes. This could potentially create confusion, however, since when
the checksum is used, the calculation can sometimes result in a value of zero. To
avoid having the destination think the checksum was not used in this case, this zero
value is instead represented as a value of all ones (65,535 decimal).
Description:
The User Datagram Protocol offers only a minimal transport service -- non-guaranteed
datagram delivery -- and gives applications direct access to the datagram service of the IP
layer. UDP is used by applications that do not require the level of service of TCP or that wish
to use communications services (e.g., multicast or broadcast delivery) not available from
TCP.
UDP is almost a null protocol; the only services it provides over IP are checksumming of data
and multiplexing by port number. Therefore, an application program running over UDP must
deal directly with end-to-end communication problems that a connection-oriented protocol
would have handled -- e.g., retransmission for reliable delivery, packetization and
reassembly, flow control, congestion avoidance, etc., when these are required. The fairly
complex coupling between IP and TCP will be mirrored in the coupling between UDP and
many applications using UDP.
UDP header:
1
00 01 02 03 04 05 06 07 08 09 10 11 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2
Source Port Destination Port
Length Checksum
Data :::
Checksum. 16 bits.
Computed as the 16-bit one's complement of the one's complement sum of a pseudo header of
information from the IP header, the UDP header, and the data, padded as needed with zero
bytes at the end to make a multiple of two bytes. If the checksum is cleared to zero, then
checksuming is disabled. If the computed checksum is zero, then this field must be set to
0xFFFF.
When transported by IPv4, the pseudo header contains the following fields:
1
00 01 02 03 04 05 06 07 08 09 10 11 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2
Source IPv4 address
Destination IPv4 address
0 Protocol Total length
The checksum is not optional when transported by IPv6. In this case, the pseudo header
contains the following fields:
1
00 01 02 03 04 05 06 07 08 09 10 11 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2
Source IPv6 address :::
Destination IPv6 address :::
Upper layer packet length
0 Next header