summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_win.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/socket/qnativesocketengine_win.cpp')
-rw-r--r--src/network/socket/qnativesocketengine_win.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 6ff5c884f7..5ffe7b11b8 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -574,6 +574,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);
@@ -1186,7 +1199,7 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const
#endif
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %li", ret);
+ qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %lli", ret);
#endif
return ret;
@@ -1292,10 +1305,11 @@ qint64 QNativeSocketEnginePrivate::nativeReceiveDatagram(char *data, qint64 maxL
}
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %li, %s, %i) == %li",
+ bool printSender = (ret != -1 && (options & QNativeSocketEngine::WantDatagramSender) != 0);
+ qDebug("QNativeSocketEnginePrivate::nativeReceiveDatagram(%p \"%s\", %lli, %s, %i) == %lli",
data, qt_prettyDebug(data, qMin<qint64>(ret, 16), ret).data(), maxLength,
- address ? address->toString().toLatin1().constData() : "(nil)",
- port ? *port : 0, ret);
+ printSender ? header->senderAddress.toString().toLatin1().constData() : "(unknown)",
+ printSender ? header->senderPort : 0, ret);
#endif
return ret;
@@ -1407,9 +1421,10 @@ qint64 QNativeSocketEnginePrivate::nativeSendDatagram(const char *data, qint64 l
}
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativeSendDatagram(%p \"%s\", %li, \"%s\", %i) == %li", data,
- qt_prettyDebug(data, qMin<qint64>(len, 16), len).data(), 0, address.toString().toLatin1().constData(),
- port, ret);
+ qDebug("QNativeSocketEnginePrivate::nativeSendDatagram(%p \"%s\", %lli, \"%s\", %i) == %lli", data,
+ qt_prettyDebug(data, qMin<qint64>(len, 16), len).data(), len,
+ header.destinationAddress.toString().toLatin1().constData(),
+ header.destinationPort, ret);
#endif
return ret;