12

I understand that the default max buffer size I can use with these functions is 65507 (5535 - IPv4 header - UDP header). However, is there a way to change this? I need to be able send a larger buffer ~66000 bytes. I tried using the setsockopt() function, but it didn't seem to work.

Thanks!

Albert Myers
  • 121
  • 1
  • 1
  • 4

3 Answers3

13

No.

UDP only provides a datagram as the data part of an IP packet, an IP packet has a 16 bit length field thus limiting the data to 2^16 bytes including the headers, or 65507 bytes for the UDP data part(assuming no ipv4 options), there's no way to handle larger packets with UDP besides splitting them up in several packets and handle the reassembly etc. yourself.

nos
  • 223,662
  • 58
  • 417
  • 506
10

Also it is quite likely to loose "big" UDP packets along the way, because the wrapping IP packet might be fragmented due to MTU limitations. Each of the fragments might get lost and there is no recovery mechanism in UDP. So while the theoretical limit for UDP payload is approx. 64kB the practical limit is around 1kB.

Jonas Bötel
  • 4,452
  • 1
  • 19
  • 28
  • 4
    This is an important point. A 65500 byte UDP packet fragmented into ethernet-sized fragments will turn a 1% underlying fragment loss rate into a ~37% UDP packet loss rate. Big UDP packets - don't do it! – caf Jul 20 '10 at 23:17
  • Where I work we get around this issue by using dedicated interfaces on a private subnet for the UDP traffic with the large packets (and static ARP entries to prevent the periodic ARP drops). If you can't do that though, be prepared for dropped packets. – T.E.D. Jul 23 '12 at 19:05
6

The UDP specification gives you 16bits in the UDP header for the packet size, that means you cannot send more than 65k at once. You cannot change this.

You have to split up your data into multiple packets. Using TCP instead of UDP will make the thing much simpler, since completeness and receiving order are guaranteed.

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
codymanix
  • 28,510
  • 21
  • 92
  • 151