Fix check for IPV6 support without certain features

Without features getifaddrs and ipv6ifname we cannot
get correct IPV6 information for interfaces.

Pick-to: 6.2 6.3
Change-Id: I7f8c4e68d345160d218fde8db640440f3324014e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Pasi Petäjäjärvi 2022-02-24 10:09:31 +02:00
parent e37919b758
commit d0d1d74033
2 changed files with 12 additions and 3 deletions

View File

@ -118,6 +118,7 @@ public:
static bool hasIPv6()
{
#ifdef Q_OS_UNIX
#if !defined(QT_NO_GETIFADDRS) && !defined(QT_NO_IPV6IFNAME)
int s = ::socket(AF_INET6, SOCK_DGRAM, 0);
if (s == -1)
return false;
@ -132,6 +133,9 @@ public:
}
}
::close(s);
#else
return false;
#endif
#endif
return true;
}

View File

@ -71,9 +71,14 @@ tst_QNetworkInterface::~tst_QNetworkInterface()
bool tst_QNetworkInterface::isIPv6Working()
{
QUdpSocket socket;
socket.connectToHost(QHostAddress::LocalHostIPv6, 1234);
return socket.state() == QAbstractSocket::ConnectedState || socket.waitForConnected(100);
// Version without following cannot get IPV6 information
#if !defined(QT_NO_GETIFADDRS) && !defined(QT_NO_IPV6IFNAME)
QUdpSocket socket;
socket.connectToHost(QHostAddress::LocalHostIPv6, 1234);
return socket.state() == QAbstractSocket::ConnectedState || socket.waitForConnected(100);
#else
return false;
#endif
}
void tst_QNetworkInterface::initTestCase()