0

From what I have read, when using IPv4 addresses, sending 508 bytes, or less, will ensure the packet will not be fragmented, if sent.

I am interested in finding out if one could calculate run-time the packet size to maximize efficiency, with the added constraint of using only the WinSock2 library.

Marc Grec
  • 135
  • 4
  • 3
    You can't, because you can't establish the path MTU in UDP. The generally accepted figure is not 508 but 534. – user207421 Mar 22 '20 at 09:26
  • 1
    In practice it's much higher, often >1400. And you can still do path MTU discovery, see [this question](https://stackoverflow.com/questions/973439/how-to-set-the-dont-fragment-df-flag-on-a-socket) – rustyx Mar 22 '20 at 09:42
  • Winsock offers the [getsockopt](https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockopt) function (use it with optname set to SO_MAX_MSG_SIZE) **after** you bind to the socket. Notice though that this will only tell you what your local NIC will allow (it´s related to the NIC´s MTU), not what will happen further along the path. Pretty safe within a LAN, also over Internet nowadays, but certainly not bulletproof... – C. Gonzalez Mar 23 '20 at 17:28

0 Answers0