| 34 | } |
| 35 | |
| 36 | QList<NetworkPathCandidate> NetworkPathResolver::enumerateIpv4Candidates() |
| 37 | { |
| 38 | QList<NetworkPathCandidate> out; |
| 39 | |
| 40 | const auto interfaces = QNetworkInterface::allInterfaces(); |
| 41 | for (const QNetworkInterface& iface : interfaces) { |
| 42 | const auto flags = iface.flags(); |
| 43 | if (!(flags & QNetworkInterface::IsUp) || |
| 44 | !(flags & QNetworkInterface::IsRunning) || |
| 45 | (flags & QNetworkInterface::IsLoopBack)) { |
| 46 | continue; |
| 47 | } |
| 48 | |
| 49 | for (const QNetworkAddressEntry& entry : iface.addressEntries()) { |
| 50 | const QHostAddress addr = entry.ip(); |
| 51 | if (!isUsableIpv4(addr)) |
| 52 | continue; |
| 53 | |
| 54 | NetworkPathCandidate candidate; |
| 55 | candidate.interfaceId = iface.name(); |
| 56 | candidate.interfaceName = interfaceLabel(iface); |
| 57 | candidate.address = addr; |
| 58 | out.append(candidate); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | std::sort(out.begin(), out.end(), [](const NetworkPathCandidate& lhs, |
| 63 | const NetworkPathCandidate& rhs) { |
| 64 | if (lhs.interfaceName == rhs.interfaceName) |
| 65 | return lhs.address.toString() < rhs.address.toString(); |
| 66 | return lhs.interfaceName < rhs.interfaceName; |
| 67 | }); |
| 68 | return out; |
| 69 | } |
| 70 | |
| 71 | NetworkPathCandidate NetworkPathResolver::resolveExplicitSelection(const QString& interfaceId, |
| 72 | const QString& interfaceName, |