Windows - fix connecting to a socket using IPv4 mapped IPv6
authorShane Kearns <ext-shane.2.kearns@nokia.com>
Fri, 17 Feb 2012 20:33:57 +0000 (20:33 +0000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 20 Feb 2012 17:20:20 +0000 (18:20 +0100)
Connecting to an IPv4 mapped IPv6 address (e.g. ::FFFF:127.0.0.1)
requires the IPV6_V6ONLY socket option to be cleared.
This was causing tst_qtcpserver::ipv6ServerMapped autotest to fail.
The same change is not required on MacOS X - the test passes there.

Task-number: QTBUG-24351
Change-Id: I6c08b19f0daa12765da2d44792ffb17299322695
Reviewed-by: Markus Goetz <markus@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/network/socket/qnativesocketengine_win.cpp

index e57bfcb..d7bbe7e 100644 (file)
@@ -615,6 +615,16 @@ bool QNativeSocketEnginePrivate::nativeConnect(const QHostAddress &address, quin
 
     setPortAndAddress(&sockAddrIPv4, &sockAddrIPv6, port, address, &sockAddrPtr, &sockAddrSize);
 
+#if defined (IPV6_V6ONLY)
+    if (socketProtocol == QAbstractSocket::IPv6Protocol && address.toIPv4Address()) {
+        //IPV6_V6ONLY option must be cleared to connect to a V4 mapped address
+        if (QSysInfo::windowsVersion() >= QSysInfo::WV_6_0) {
+            DWORD ipv6only = 0;
+            ipv6only = ::setsockopt(socketDescriptor, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&ipv6only, sizeof(ipv6only) );
+        }
+    }
+#endif
+
     forever {
         int connectResult = ::WSAConnect(socketDescriptor, sockAddrPtr, sockAddrSize, 0,0,0,0);
         if (connectResult == SOCKET_ERROR) {