How to fill the UDP length in the first UDP fragment when UDP package divided to IP fragment?

Viewed 291

For example, one 2000 bytes UDP package(contains UDP header) and network MTU is 1500. So this UDP package should be split to two IP fragments. Only the first IP package contains the UDP header. What value should be filled into UDP length in the UDP header of first IP package? 1480 or 2000? Is there any document to confirm this?

2 Answers

UDP Length is the length of the UDP header AND the UDP data, in bytes. The fragmentation will/should NOT change this.

[UDP] "Length is the length in octets of this user datagram including this header and the data" --RFC768, an Internet Standard. It is also in the Stevens link referenced: "Referring to Figure 10-2, the UDP Length field is the length of the UDP header and the UDP data in bytes."

I think you may be overthinking this. Just set the UDP length to however big your data is.

IP fragmenting can occur at any router hop, without your knowledge (assuming you are the sender). It's the IP layer's responsibility to fragment and re-assemble the packet before the UDP datagram is delivered to the application. Unless you're plugged in to the NIC driver, you won't be able to reliably tell if the packet was fragmented on the way.

If there's an IP fragment lost on the way, you won't get any UDP datagram at all, it will simply be lost from the application's point of view, even though the IP layer may have gotten 9 out of 10 fragments.

Everything about this is brilliantly described in Richard Stevens et al's seminal work: TCP/IP Illustrated, Volume 1: The protocols , section 10.7 IP Fragementation.

Related