summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2016-05-02 12:08:00 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2016-05-04 17:16:54 +0000
commit4ef269963bad7a76ed03e81b91b94058c812e31b (patch)
treeb3796c0375c423da9bdd6350e049ad17466e22ac /src/network
parent728a1b4f29f0042fc13299bf6cc78e83cdc9d7f9 (diff)
Avoid use of v4-mapped QHostAddress::AnyIPv4 local address on Windows
Some Windows kernels return a v4-mapped QHostAddress::AnyIPv4 as a local address of the socket which bound on both IPv4 and IPv6 interfaces. This address does not match to any special address and should not be used to send the data. To allow handling of the local addresses properly, replace it with QHostAddress::Any. Already tested by tst_qudpsocket. Task-number: QTBUG-52714 Change-Id: Icb7cb75f48cd7ec9b0a9dfaf861ffe0d3093e20d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 770bae7bf3..41834b21ae 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -573,6 +573,19 @@ bool QNativeSocketEnginePrivate::fetchConnectionParameters()
}
}
+ // Some Windows kernels return a v4-mapped QHostAddress::AnyIPv4 as a
+ // local address of the socket which bound on both IPv4 and IPv6 interfaces.
+ // This address does not match to any special address and should not be used
+ // to send the data. So, replace it with QHostAddress::Any.
+ if (socketProtocol == QAbstractSocket::IPv6Protocol) {
+ bool ok = false;
+ const quint32 localIPv4 = localAddress.toIPv4Address(&ok);
+ if (ok && localIPv4 == INADDR_ANY) {
+ socketProtocol = QAbstractSocket::AnyIPProtocol;
+ localAddress = QHostAddress::Any;
+ }
+ }
+
memset(&sa, 0, sizeof(sa));
if (::getpeername(socketDescriptor, &sa.a, &sockAddrSize) == 0) {
qt_socket_getPortAndAddress(socketDescriptor, &sa, &peerPort, &peerAddress);