@@ -69,6 +69,28 @@ namespace
6969
7070 return true ;
7171 }
72+
73+ bool isValidIPRange (const QHostAddress &first, const QHostAddress &last)
74+ {
75+ if (first.isNull () || last.isNull ())
76+ return false ;
77+ if (first.protocol () != last.protocol ())
78+ return false ;
79+ if (first.protocol () == QAbstractSocket::IPv4Protocol)
80+ return first.toIPv4Address () <= last.toIPv4Address ();
81+ if (first.protocol () == QAbstractSocket::IPv6Protocol)
82+ {
83+ const Q_IPV6ADDR firstIPv6 = first.toIPv6Address ();
84+ const Q_IPV6ADDR lastIPv6 = last.toIPv6Address ();
85+ QByteArray firstIPv6Bytes, lastIPv6Bytes;
86+ for (const quint8 byte : firstIPv6.c )
87+ firstIPv6Bytes.append (byte);
88+ for (const quint8 byte : lastIPv6.c )
89+ lastIPv6Bytes.append (byte);
90+ return !std::ranges::lexicographical_compare (firstIPv6Bytes, lastIPv6Bytes, std::less<quint8>{});
91+ }
92+ return false ;
93+ }
7294}
7395
7496namespace Utils
@@ -80,23 +102,6 @@ namespace Utils
80102 return !QHostAddress (ip).isNull ();
81103 }
82104
83- bool isValidIPRange (const QHostAddress &first, const QHostAddress &last)
84- {
85- if (first.isNull () || last.isNull ())
86- return false ;
87- if (first.protocol () != last.protocol ())
88- return false ;
89- if (first.protocol () == QAbstractSocket::IPv4Protocol)
90- return first.toIPv4Address () <= last.toIPv4Address ();
91- if (first.protocol () == QAbstractSocket::IPv6Protocol)
92- {
93- const Q_IPV6ADDR firstIPv6 = first.toIPv6Address ();
94- const Q_IPV6ADDR lastIPv6 = last.toIPv6Address ();
95- return memcmp (firstIPv6.c , lastIPv6.c , sizeof (firstIPv6.c )) <= 0 ;
96- }
97- return false ;
98- }
99-
100105 std::optional<Subnet> parseSubnet (const QString &subnetStr)
101106 {
102107 const Subnet subnet = QHostAddress::parseSubnet (subnetStr);
0 commit comments