refactor: NetworkMonitor, short phyical using isPrivateUse()
this an Ip is considered private when its in a RFC1918 range 10/8, 172.16/12 and 192.168/16 are private IPs
This commit is contained in:
committed by
Chris Rizzitello
parent
a0f06d907f
commit
a73057f3a7
@ -98,16 +98,11 @@ QList<QHostAddress> NetworkMonitor::getAvailableIPv4Addresses() const
|
||||
}
|
||||
}
|
||||
|
||||
auto physicalComparator = [](const QHostAddress &a, const QHostAddress &b) {
|
||||
static const auto localIpFilter = QStringLiteral("192.168/16");
|
||||
if (a.isInSubnet(QHostAddress::parseSubnet(localIpFilter)) !=
|
||||
b.isInSubnet(QHostAddress::parseSubnet(localIpFilter))) {
|
||||
std::sort(physicalIPs.begin(), physicalIPs.end(), [](const QHostAddress &a, const QHostAddress &b) {
|
||||
if (a.isPrivateUse() != b.isPrivateUse())
|
||||
return true;
|
||||
}
|
||||
return a.toIPv4Address() < b.toIPv4Address();
|
||||
};
|
||||
|
||||
std::sort(physicalIPs.begin(), physicalIPs.end(), physicalComparator);
|
||||
});
|
||||
|
||||
std::sort(virtualIPs.begin(), virtualIPs.end(), [](const QHostAddress &a, const QHostAddress &b) {
|
||||
return a.toIPv4Address() < b.toIPv4Address();
|
||||
|
||||
@ -53,7 +53,7 @@ public:
|
||||
QList<QHostAddress> getAvailableIPv4Addresses() const;
|
||||
|
||||
/**
|
||||
* @brief Get recommended IP address (192.168.x.x preferred)
|
||||
* @brief Get recommended IP address (RFC-1918 addresses preferred)
|
||||
* @return Recommended IP address, returns null if none available
|
||||
*/
|
||||
QHostAddress getSuggestedIPv4Address() const;
|
||||
|
||||
Reference in New Issue
Block a user