Fix ipv6_server=true not accepting IPv4 connections on Windows (#7471)
authorsfan5 <sfan5@live.de>
Fri, 22 Jun 2018 18:54:23 +0000 (20:54 +0200)
committerSmallJoker <SmallJoker@users.noreply.github.com>
Fri, 22 Jun 2018 18:54:23 +0000 (20:54 +0200)
src/network/socket.cpp

index 0530136067be701cb8ec0e89117632d04f7085c9..94a9f4180389636dbdb70c908f3d960e582c8a29 100644 (file)
@@ -118,6 +118,15 @@ bool UDPSocket::init(bool ipv6, bool noExceptions)
 
        setTimeoutMs(0);
 
+       if (m_addr_family == AF_INET6) {
+               // Allow our socket to accept both IPv4 and IPv6 connections
+               // required on Windows:
+               // https://msdn.microsoft.com/en-us/library/windows/desktop/bb513665(v=vs.85).aspx
+               int value = 0;
+               setsockopt(m_handle, IPPROTO_IPV6, IPV6_V6ONLY,
+                               reinterpret_cast<char *>(&value), sizeof(value));
+       }
+
        return true;
 }