Winsock UDP sendto returning error 10040 (WSAEMSGSIZE)
18:11 28 Jul 2026

I'm having an issue where I am trying to send ~2kB UDP frames without fragmentation. But, I am getting an error when sending frames to the socket that exceed the 1.4kB limit.

If I set:

DWORD val = 1;
setsockopt( m_nSocket, IPPROTO_IP, IP_DONTFRAGMENT, (char*)&val, sizeof( val ) );

Then, read SO_MAX_MESSAGE_SIZE then it returns 65507 bytes.

int os = 0;
int osl = 4;
getsockopt( m_nSocket, SOL_SOCKET, SO_MAX_MSG_SIZE, ( char * )&os, &osl );

But, if I send packets that are of size 2072 bytes, then sendto returns -1, and WSAGetLastError() reports error 10040.

I've tried searching around for a while from what people have talked about on forums, but I feel like there may be something I am missing.

winsock2 mtu