Commit 4ef26996 authored by Alex Trotsenko's avatar Alex Trotsenko
Browse files

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: default avatarThiago Macieira <thiago.macieira@intel.com>
Showing with 13 additions and 0 deletions
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment