3
votes

I try to use UDP to transfer large Data over a local Network, using QT as Framework for the Socket Access. Sending simple messages is not a problem so far. However, I do not (fully) understand how segmentation of packages is handled and who does it.

So QT states:

Sending datagrams larger than 512 bytes is in general disadvised, as even if they are sent successfully, they are likely to be fragmented by the IP layer before arriving at their final destination.

Therefore I implemented my own little protocol to handle split and merge of large Data. Playing around with larger sizes than 512 bytes (in the order of 10kBytes), I came across the following snippet from wireshark:

"17","0.145050","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=0, ID=3a47) [Reassembled in #23]"
"18","0.145051","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=1480, ID=3a47) [Reassembled in #23]"
"19","0.145051","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=2960, ID=3a47) [Reassembled in #23]"
"20","0.145051","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=4440, ID=3a47) [Reassembled in #23]"
"21","0.145052","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=5920, ID=3a47) [Reassembled in #23]"
"22","0.145052","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=7400, ID=3a47) [Reassembled in #23]"
"23","0.145052","192.168.2.111","192.168.2.222","UDP","1186","63230  >  8007 Len=10024"

And from that I get one Datagram in QT. So for me it seems that the IP layer is already taking care of splitting/merging my (too large) UDP Packets. So:

  1. Why is it advised to split the Data for UDP by myself?
  2. "Who" handles the IP layer? (QT,Windows, Network-hardware?)
  3. I assume there is a second limit resulting from read/write buffers in the UDP Socket, where can I check on that?
1

1 Answers

3
votes

What QT states is nonsense. Even if datagrams are fragmented on the way through internet they will be reassambled at the destination. They are correct about this being done on the IP layer, so there is nothing for your application to worry about, unless you intend to break the 64k max datagram size (64k - Wikipedia on UDP)

As for your questions:

  1. Plain wrong. Ignore.
  2. IP layer is handled by IP stack, typically on kernel level
  3. The "2nd limit" is defined by the IP protocol (v4 in your case), which defines the length field to 16 bits, making max datagram size 64k (RFC 791)

However, if what you intend to do is to transfer large chunks of data in a reliable way, you should really be using TCP instead of UDP. Let TCP handle these things instead of your application.