mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Some checks failed
Build / Initialization (push) Has been cancelled
Build / Code Format Validation (push) Has been cancelled
Build / Linux (Qt6) (push) Has been cancelled
Build / Linux (Qt6 + 7zip) (push) Has been cancelled
Build / macOS (Qt6 Universal) (push) Has been cancelled
Build / Windows x64 (Qt6) (push) Has been cancelled
Build / Windows ARM64 (Qt6) (push) Has been cancelled
Build / Docker amd64 Image (push) Has been cancelled
Build / Docker arm64 Image (push) Has been cancelled
Build / Publish Dev Builds (push) Has been cancelled
Build / Publish Release (push) Has been cancelled
Build / Publish YACReader10 Pre-release Builds (push) Has been cancelled
36 lines
927 B
C++
36 lines
927 B
C++
#include "ip_config_helper.h"
|
|
|
|
#include "qnaturalsorting.h"
|
|
|
|
#include <QNetworkInterface>
|
|
|
|
// 192.168 (most comon local subnet for ips are always put first)
|
|
// IPs are sorted using natoral sorting
|
|
|
|
QList<QString> getIpAddresses()
|
|
{
|
|
auto ipComparator = [](const QString &ip1, const QString &ip2) {
|
|
if (ip1.startsWith("192.168") && ip2.startsWith("192.168"))
|
|
return naturalSortLessThanCI(ip1, ip2);
|
|
|
|
if (ip1.startsWith("192.168"))
|
|
return true;
|
|
|
|
if (ip2.startsWith("192.168"))
|
|
return false;
|
|
|
|
return naturalSortLessThanCI(ip1, ip2);
|
|
};
|
|
|
|
QList<QString> addresses;
|
|
for (auto add : QNetworkInterface::allAddresses()) {
|
|
// Exclude loopback, local, multicast
|
|
if (add.isGlobal()) {
|
|
addresses.push_back(add.toString());
|
|
}
|
|
}
|
|
|
|
std::sort(addresses.begin(), addresses.end(), ipComparator);
|
|
return addresses;
|
|
}
|