diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index e58fc21c9f2..31e8be5b6b0 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1511,13 +1511,14 @@ int WINAPI getsockopt( SOCKET s, int level, int optname, char *optval, int *optl /* As mentioned in setsockopt, Windows ignores this, so we * always return true here */ case SO_DONTROUTE: - if (*optlen < sizeof(BOOL) || !optval) + if (*optlen < 1 || !optval) { - SetLastError(WSAEFAULT); + SetLastError( WSAEFAULT ); return SOCKET_ERROR; } - *(BOOL *)optval = TRUE; - *optlen = sizeof(BOOL); + *optval = TRUE; + *optlen = 1; + SetLastError( ERROR_SUCCESS ); return 0; case SO_ERROR: @@ -2859,7 +2860,13 @@ int WINAPI setsockopt( SOCKET s, int level, int optname, const char *optval, int /* For some reason the game GrandPrixLegends does set SO_DONTROUTE on its * socket. According to MSDN, this option is silently ignored.*/ case SO_DONTROUTE: - TRACE("Ignoring SO_DONTROUTE\n"); + TRACE( "Ignoring SO_DONTROUTE.\n" ); + if (optlen <= 0) + { + SetLastError( optlen ? WSAENOBUFS : WSAEFAULT ); + return -1; + } + SetLastError( ERROR_SUCCESS ); return 0; /* Stops two sockets from being bound to the same port. Always happens diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 5200fb185b4..3da68b0e4a8 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1171,6 +1171,7 @@ static void test_set_getsockopt(void) { {AF_INET, SOCK_DGRAM, SOL_SOCKET, SO_BROADCAST, TRUE, {1, 1, 4}, {0, 0xdead0001, 0}, TRUE, TRUE}, {AF_INET, SOCK_STREAM, SOL_SOCKET, SO_DONTLINGER, TRUE, {1, 1, 4}, {0, 0xdead0001, 0}, TRUE, TRUE}, + {AF_INET, SOCK_STREAM, SOL_SOCKET, SO_DONTROUTE, TRUE, {1, 1, 1}, {0}, TRUE}, {AF_INET, SOCK_STREAM, SOL_SOCKET, SO_RCVTIMEO, FALSE, {1, 2, 4}, {0}, TRUE}, {AF_INET, SOCK_STREAM, SOL_SOCKET, SO_SNDTIMEO, FALSE, {1, 2, 4}, {0}, TRUE}, {AF_INET, SOCK_DGRAM, IPPROTO_IP, IP_MULTICAST_LOOP, TRUE, {1, 1, 4}, {0}, TRUE, TRUE},