tst_QDnsLookup: also use the nameservers behind systemd-resolved

If the file exists, we are using systemd-resolved, so let's try directly
using the nameservers it uses.

Change-Id: I455fe22ef4ad4b2f9b01fffd17c7476a2385bf4b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Thiago Macieira 2024-04-17 22:05:04 -07:00
parent f7d293d3da
commit 6800e168d5
1 changed files with 15 additions and 11 deletions

View File

@ -91,19 +91,23 @@ static QList<QHostAddress> systemNameservers()
}
}
#else
QFile f("/etc/resolv.conf");
if (!f.open(QIODevice::ReadOnly))
return result;
auto parseFile = [&](QLatin1StringView path) {
QFile f(path);
if (!f.open(QIODevice::ReadOnly))
return;
while (!f.atEnd()) {
static const char command[] = "nameserver";
QByteArray line = f.readLine().simplified();
if (!line.startsWith(command))
continue;
while (!f.atEnd()) {
static const char command[] = "nameserver";
QByteArray line = f.readLine().simplified();
if (!line.startsWith(command))
continue;
QString addr = QLatin1StringView(line).mid(sizeof(command));
result.emplaceBack(addr);
}
QString addr = QLatin1StringView(line).mid(sizeof(command));
result.emplaceBack(addr);
}
};
parseFile("/etc/resolv.conf"_L1);
parseFile("/run/systemd/resolve/resolv.conf"_L1);
#endif
return result;