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.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/network/socket/qnativesocketengine_win.cpp b/src/network/socket/qnativesocketengine_win.cpp
index 07f4899bae..0c5b8d9264 100644
--- a/src/network/socket/qnativesocketengine_win.cpp
+++ b/src/network/socket/qnativesocketengine_win.cpp
@@ -572,6 +572,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);
@@ -934,7 +947,7 @@ static bool multicastMembershipHelper(QNativeSocketEnginePrivate *d,
mreq4.imr_multiaddr.s_addr = htonl(groupAddress.toIPv4Address());
if (iface.isValid()) {
- QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
+ const QList<QNetworkAddressEntry> addressEntries = iface.addressEntries();
if (!addressEntries.isEmpty()) {
QHostAddress firstIP = addressEntries.first().ip();
mreq4.imr_interface.s_addr = htonl(firstIP.toIPv4Address());
@@ -1158,7 +1171,7 @@ qint64 QNativeSocketEnginePrivate::nativePendingDatagramSize() const
delete[] buf;
#if defined (QNATIVESOCKETENGINE_DEBUG)
- qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %li", ret);
+ qDebug("QNativeSocketEnginePrivate::nativePendingDatagramSize() == %lli", ret);
#endif
return ret;
@@ -1258,10 +1271,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;
@@ -1368,9 +1382,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;