From a9b9dfe5e91e4a272a644869dcbda8b62560255a Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sun, 5 Mar 2017 21:48:19 +0100 Subject: [PATCH] Meta: enable both IPv4 and IPv6 if we're unable to query network interfaces. On systems using systemd, Murmur is often started early, even before Murmur can query the network interfaces. This commit adds a fallback, where Murmur will expect such a system to support both IPv4 and IPv6. Fixes mumble-voip/mumble#1629 Fixes mumble-voip/mumble#1904 --- src/murmur/Meta.cpp | 50 +++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/murmur/Meta.cpp b/src/murmur/Meta.cpp index f21be0415..b2a1ab969 100644 --- a/src/murmur/Meta.cpp +++ b/src/murmur/Meta.cpp @@ -206,30 +206,44 @@ void MetaParams::read(QString fname) { if (qlBind.isEmpty()) { bool hasipv6 = false; bool hasipv4 = false; + int nif = 0; - foreach(const QNetworkInterface &qni, QNetworkInterface::allInterfaces()) { - if (!(qni.flags() & QNetworkInterface::IsUp)) - continue; - if (!(qni.flags() & QNetworkInterface::IsRunning)) - continue; - if (qni.flags() & QNetworkInterface::IsLoopBack) - continue; + QList interfaces = QNetworkInterface::allInterfaces(); + if (interfaces.isEmpty()) { + qWarning("Meta: Unable to acquire list of network interfaces."); + } else { + foreach(const QNetworkInterface &qni, interfaces) { + if (!(qni.flags() & QNetworkInterface::IsUp)) + continue; + if (!(qni.flags() & QNetworkInterface::IsRunning)) + continue; + if (qni.flags() & QNetworkInterface::IsLoopBack) + continue; - foreach(const QNetworkAddressEntry &qna, qni.addressEntries()) { - const QHostAddress &qha = qna.ip(); - switch (qha.protocol()) { - case QAbstractSocket::IPv4Protocol: - hasipv4 = true; - break; - case QAbstractSocket::IPv6Protocol: - hasipv6 = true; - break; - default: - break; + foreach(const QNetworkAddressEntry &qna, qni.addressEntries()) { + const QHostAddress &qha = qna.ip(); + switch (qha.protocol()) { + case QAbstractSocket::IPv4Protocol: + hasipv4 = true; + break; + case QAbstractSocket::IPv6Protocol: + hasipv6 = true; + break; + default: + break; + } } + + ++nif; } } + if (nif == 0) { + qWarning("Meta: Could not determine IPv4/IPv6 support via network interfaces, assuming support for both."); + hasipv6 = true; + hasipv4 = true; + } + #if QT_VERSION >= 0x050000 if (hasipv6) { if (SslServer::hasDualStackSupport() && hasipv4) {