feat: support link-local connections in Preferences dialog
most link-local IPs are just noise, but if an entire interface is link-local only, maybe someone is hooking up their computers directly by ethernet cable Still filter virtual interfacts with only local link
This commit is contained in:
parent
4b7491472d
commit
13c5655976
2 changed files with 11 additions and 2 deletions
|
|
@ -71,11 +71,16 @@ QStringList NetworkMonitor::validAddresses()
|
||||||
const bool isVirtualType = interface.type() == QNetworkInterface::Virtual;
|
const bool isVirtualType = interface.type() == QNetworkInterface::Virtual;
|
||||||
const bool isVirtual = isVirtualInterface(interface.humanReadableName()) || isP2P || isVirtualType;
|
const bool isVirtual = isVirtualInterface(interface.humanReadableName()) || isP2P || isVirtualType;
|
||||||
const auto addressEntries = interface.addressEntries();
|
const auto addressEntries = interface.addressEntries();
|
||||||
|
// link-local is only worth offering when it's a physical interface's only address, e.g. a direct ethernet cable
|
||||||
|
const bool hasNonLinkLocal = std::ranges::any_of(addressEntries, [](const QNetworkAddressEntry &entry) {
|
||||||
|
return !entry.ip().isLoopback() && !entry.ip().isLinkLocal();
|
||||||
|
});
|
||||||
|
const bool skipLinkLocal = isVirtual || hasNonLinkLocal;
|
||||||
|
|
||||||
for (const auto &entry : addressEntries) {
|
for (const auto &entry : addressEntries) {
|
||||||
const QHostAddress address = entry.ip();
|
const QHostAddress address = entry.ip();
|
||||||
|
|
||||||
if (address.isLinkLocal() || address.isLoopback() || uniqueAddresses.contains(address)) {
|
if (address.isLoopback() || (skipLinkLocal && address.isLinkLocal()) || uniqueAddresses.contains(address)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,6 +103,8 @@ QStringList NetworkMonitor::validAddresses()
|
||||||
std::ranges::sort(physicalIP4, [](const QHostAddress &a, const QHostAddress &b) {
|
std::ranges::sort(physicalIP4, [](const QHostAddress &a, const QHostAddress &b) {
|
||||||
if (a.isPrivateUse() != b.isPrivateUse())
|
if (a.isPrivateUse() != b.isPrivateUse())
|
||||||
return a.isPrivateUse();
|
return a.isPrivateUse();
|
||||||
|
if (a.isLinkLocal() != b.isLinkLocal())
|
||||||
|
return a.isLinkLocal();
|
||||||
return a.toIPv4Address() < b.toIPv4Address();
|
return a.toIPv4Address() < b.toIPv4Address();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -108,6 +115,8 @@ QStringList NetworkMonitor::validAddresses()
|
||||||
std::ranges::sort(physicalIP6, [](const QHostAddress &a, const QHostAddress &b) {
|
std::ranges::sort(physicalIP6, [](const QHostAddress &a, const QHostAddress &b) {
|
||||||
if (a.isPrivateUse() != b.isPrivateUse())
|
if (a.isPrivateUse() != b.isPrivateUse())
|
||||||
return a.isPrivateUse();
|
return a.isPrivateUse();
|
||||||
|
if (a.isLinkLocal() != b.isLinkLocal())
|
||||||
|
return a.isLinkLocal();
|
||||||
return a.toString() < b.toString();
|
return a.toString() < b.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ public:
|
||||||
void stopMonitoring();
|
void stopMonitoring();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get list of all available IP addresses (excluding local and link-local addresses)
|
* @brief Get list of all available IP addresses (excluding loopback addresses)
|
||||||
* @return IP address list
|
* @return IP address list
|
||||||
*/
|
*/
|
||||||
static QStringList validAddresses();
|
static QStringList validAddresses();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue