If you attempt to send a UDP packet to an IPv4 address using an IPv6 socket, sendto()
will report the WSAEFAULT
error. This behavior is described by MSDN:
sendto function
Return value
If no error occurs, sendto returns the total number of bytes sent, which can be less than the number indicated by len. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.
...
WSAEFAULT
The buf or to parameters are not part of the user address space, or
the tolen parameter is too small.
Technically that's true because an IPv4 address is smaller than an IPv6 address. It might be a bit misleading to think sizeof was wrong when it's actually the wrong address family used and hence the sizeof represents the wrong size to use.
See also windows error codes here:
Windows Sockets Error Codes