This patch fixes an incompatibility between Windows and Linux with regards to RFC 2553 [1]. Linux is in compliance with the RFC, which states that binding an IPv6 wildcard address to a port should also bind the IPv4 wildcard address to the port. This causes problems when an application tries all available protocols and then receives ``address in use'' when trying to bind with IPv4. Windows [2] and OpenBSD [3] are not in compliance with this behavior. The patch sets IPV6_V6ONLY, if available (note that it is also available for OpenBSD), which disables the behavior. [1] http://www.faqs.org/rfcs/rfc2553.html [2] http://www.microsoft.com/technet/network/ipv6/ipv6faq.mspx [3] http://www.openbsd.org/cgi-bin/man.cgi?query=inet6&sektion=4 --- dlls/ws2_32/socket.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 13878a7..fa486bf 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1405,6 +1405,18 @@ int WINAPI WS_bind(SOCKET s, const struct WS_sockaddr* name, int namelen) } else { +#ifdef IPV6_V6ONLY + const struct sockaddr_in6 *in6 = (const struct sockaddr_in6*) &uaddr; + if (name->sa_family == WS_AF_INET6 && + !memcmp(&in6->sin6_addr, &in6addr_any, sizeof(struct in6_addr))) { + int enable = 1; + if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &enable, sizeof(enable)) == -1) { + SetLastError(WSAEAFNOSUPPORT); + return INVALID_SOCKET; + } + } +#endif + if (bind(fd, &uaddr.addr, uaddrlen) < 0) { int loc_errno = errno; -- 1.5.3.2