summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_win.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-05-12 07:31:50 +0200
committerLiang Qi <liang.qi@qt.io>2016-05-12 08:33:08 +0200
commit990969655c5fb4d03682e96df9b12101f5ee9815 (patch)
treeb8fb5c50285105c8bc5a938fb50f93ff9f24889d /src/network/socket/qnativesocketengine_win.cpp
parenta213011a53f12f101d08a04afc8fdacd2d54a232 (diff)
parente64b2234e829cc47872225debcf80d6c06db18f0 (diff)
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts: config_help.txt configure src/corelib/io/qprocess_wince.cpp src/plugins/platforms/windows/qwindowstheme.cpp src/plugins/platforms/xcb/qxcbbackingstore.cpp tests/auto/corelib/tools/qtimezone/BLACKLIST tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp Change-Id: I26644d1cb3b78412c8ff285e2a55bea1bd641c01
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;