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
parent
f7d293d3da
commit
6800e168d5
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue