Commit 843ef11e authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

ws2_32: Return the correct error if SO_REUSEADDR is set in bind error.

parent 473a3a47
...@@ -2682,6 +2682,20 @@ int WINAPI WS_bind(SOCKET s, const struct WS_sockaddr* name, int namelen) ...@@ -2682,6 +2682,20 @@ int WINAPI WS_bind(SOCKET s, const struct WS_sockaddr* name, int namelen)
case EADDRNOTAVAIL: case EADDRNOTAVAIL:
SetLastError(WSAEINVAL); SetLastError(WSAEINVAL);
break; 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: default:
SetLastError(wsaErrno()); SetLastError(wsaErrno());
break; break;
......
...@@ -1529,7 +1529,6 @@ static void test_so_reuseaddr(void) ...@@ -1529,7 +1529,6 @@ static void test_so_reuseaddr(void)
{ {
trace(">= Win 2003 behavior of SO_REUSEADDR\n"); trace(">= Win 2003 behavior of SO_REUSEADDR\n");
err = WSAGetLastError(); err = WSAGetLastError();
todo_wine
ok(err==WSAEACCES, "expected 10013, got %d\n", err); ok(err==WSAEACCES, "expected 10013, got %d\n", err);
closesocket(s1); closesocket(s1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment