From 843ef11eb8ae7d2a9bf275c2ff5ac81144545580 Mon Sep 17 00:00:00 2001 From: Bruno Jesus <00cpxxx@gmail.com> Date: Thu, 8 May 2014 21:30:27 -0300 Subject: [PATCH] ws2_32: Return the correct error if SO_REUSEADDR is set in bind error. --- dlls/ws2_32/socket.c | 14 ++++++++++++++ dlls/ws2_32/tests/sock.c | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index a8fb9a5609f..519ce855f1c 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -2682,6 +2682,20 @@ int WINAPI WS_bind(SOCKET s, const struct WS_sockaddr* name, int namelen) case EADDRNOTAVAIL: SetLastError(WSAEINVAL); break; + case EADDRINUSE: + { + int optval = 0; + socklen_t optlen = sizeof(optval); + /* Windows >= 2003 will return different results depending on + * SO_REUSEADDR, WSAEACCES may be returned representing that + * the socket hijacking protection prevented the bind */ + if (!getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&optval, &optlen) && optval) + { + SetLastError(WSAEACCES); + break; + } + /* fall through */ + } default: SetLastError(wsaErrno()); break; diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 1752d35ca40..0bbce275d61 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -1529,7 +1529,6 @@ static void test_so_reuseaddr(void) { trace(">= Win 2003 behavior of SO_REUSEADDR\n"); err = WSAGetLastError(); -todo_wine ok(err==WSAEACCES, "expected 10013, got %d\n", err); closesocket(s1); -- 2.11.4.GIT