QtBase  v6.3.1
qhostaddress.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Copyright (C) 2016 Intel Corporation.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the QtNetwork module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #include "qhostaddress.h"
42 #include "qhostaddress_p.h"
43 #include "private/qipaddress_p.h"
44 #include "qdebug.h"
45 #if defined(Q_OS_WIN)
46 # include <winsock2.h>
47 # include <ws2tcpip.h>
48 #else
49 # include <netinet/in.h>
50 #endif
51 #include "qplatformdefs.h"
52 #include "qstringlist.h"
53 #include "qendian.h"
54 #ifndef QT_NO_DATASTREAM
55 #include <qdatastream.h>
56 #endif
57 #ifdef __SSE2__
58 # include <private/qsimd_p.h>
59 #endif
60 
61 #ifdef QT_LINUXBASE
62 # include <arpa/inet.h>
63 #endif
64 
66 
68  : a(0), protocol(QHostAddress::UnknownNetworkLayerProtocol)
69 {
70  memset(&a6, 0, sizeof(a6));
71 }
72 
74 {
75  a = a_;
77 
78  //create mapped address, except for a_ == 0 (any)
79  a6_64.c[0] = 0;
80  if (a) {
81  a6_32.c[2] = qToBigEndian(0xffff);
82  a6_32.c[3] = qToBigEndian(a);
83  } else {
84  a6_64.c[1] = 0;
85  }
86 }
87 
90 static bool convertToIpv4(quint32& a, const Q_IPV6ADDR &a6, const QHostAddress::ConversionMode mode)
91 {
93  return false;
94 
95  const uchar *ptr = a6.c;
96  if (qFromUnaligned<quint64>(ptr) != 0)
97  return false;
98 
99  const quint32 mid = qFromBigEndian<quint32>(ptr + 8);
100  if ((mid == 0xffff) && (mode & QHostAddress::ConvertV4MappedToIPv4)) {
101  a = qFromBigEndian<quint32>(ptr + 12);
102  return true;
103  }
104  if (mid != 0)
105  return false;
106 
107  const quint32 low = qFromBigEndian<quint32>(ptr + 12);
108  if ((low == 0) && (mode & QHostAddress::ConvertUnspecifiedAddress)) {
109  a = 0;
110  return true;
111  }
112  if ((low == 1) && (mode & QHostAddress::ConvertLocalHost)) {
113  a = INADDR_LOOPBACK;
114  return true;
115  }
116  if ((low != 1) && (mode & QHostAddress::ConvertV4CompatToIPv4)) {
117  a = low;
118  return true;
119  }
120  return false;
121 }
122 
124 {
126  memcpy(a6.c, a_, sizeof(a6));
127  a = 0;
128  convertToIpv4(a, a6, (QHostAddress::ConvertV4MappedToIPv4
130 }
131 
133 {
134  setAddress(a_.c);
135 }
136 
137 static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId)
138 {
139  QStringView tmp(address);
140  int scopeIdPos = tmp.lastIndexOf(QLatin1Char('%'));
141  if (scopeIdPos != -1) {
142  *scopeId = tmp.mid(scopeIdPos + 1).toString();
143  tmp.chop(tmp.size() - scopeIdPos);
144  } else {
145  scopeId->clear();
146  }
147  return QIPAddressUtils::parseIp6(addr, tmp.begin(), tmp.end()) == nullptr;
148 }
149 
150 bool QHostAddressPrivate::parse(const QString &ipString)
151 {
153  QString a = ipString.simplified();
154  if (a.isEmpty())
155  return false;
156 
157  // All IPv6 addresses contain a ':', and may contain a '.'.
158  if (a.contains(QLatin1Char(':'))) {
159  quint8 maybeIp6[16];
160  if (parseIp6(a, maybeIp6, &scopeId)) {
161  setAddress(maybeIp6);
162  return true;
163  }
164  }
165 
166  quint32 maybeIp4 = 0;
167  if (QIPAddressUtils::parseIp4(maybeIp4, a.constBegin(), a.constEnd())) {
168  setAddress(maybeIp4);
169  return true;
170  }
171 
172  return false;
173 }
174 
176 {
177  a = 0;
179  memset(&a6, 0, sizeof(a6));
180 }
181 
183 {
184  if (a) {
185  // This is an IPv4 address or an IPv6 v4-mapped address includes all
186  // IPv6 v4-compat addresses, except for ::ffff:0.0.0.0 (because `a' is
187  // zero). See setAddress(quint8*) below, which calls convertToIpv4(),
188  // for details.
189  // Source: RFC 5735
190  if ((a & 0xff000000U) == 0x7f000000U) // 127.0.0.0/8
191  return LoopbackAddress;
192  if ((a & 0xf0000000U) == 0xe0000000U) // 224.0.0.0/4
193  return MulticastAddress;
194  if ((a & 0xffff0000U) == 0xa9fe0000U) // 169.254.0.0/16
195  return LinkLocalAddress;
196  if ((a & 0xff000000U) == 0) // 0.0.0.0/8 except 0.0.0.0 (handled below)
197  return LocalNetAddress;
198  if ((a & 0xf0000000U) == 0xf0000000U) { // 240.0.0.0/4
199  if (a == 0xffffffffU) // 255.255.255.255
200  return BroadcastAddress;
201  return UnknownAddress;
202  }
203 
204  // Not testing for PrivateNetworkAddress and TestNetworkAddress
205  // since we don't need them yet.
206  return GlobalAddress;
207  }
208 
209  // As `a' is zero, this address is either ::ffff:0.0.0.0 or a non-v4-mapped IPv6 address.
210  // Source: https://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.xhtml
211  if (a6_64.c[0]) {
212  quint32 high16 = qFromBigEndian(a6_32.c[0]) >> 16;
213  switch (high16 >> 8) {
214  case 0xff: // ff00::/8
215  return MulticastAddress;
216  case 0xfe:
217  switch (high16 & 0xffc0) {
218  case 0xfec0: // fec0::/10
219  return SiteLocalAddress;
220 
221  case 0xfe80: // fe80::/10
222  return LinkLocalAddress;
223 
224  default: // fe00::/9
225  return UnknownAddress;
226  }
227  case 0xfd: // fc00::/7
228  case 0xfc:
229  return UniqueLocalAddress;
230  default:
231  return GlobalAddress;
232  }
233  }
234 
235  quint64 low64 = qFromBigEndian(a6_64.c[1]);
236  if (low64 == 1) // ::1
237  return LoopbackAddress;
238  if (low64 >> 32 == 0xffff) { // ::ffff:0.0.0.0/96
239  Q_ASSERT(quint32(low64) == 0);
240  return LocalNetAddress;
241  }
242  if (low64) // not ::
243  return GlobalAddress;
244 
246  return UnknownAddress;
247 
248  // only :: and 0.0.0.0 remain now
249  return LocalNetAddress;
250 }
251 
253 {
254  static const quint8 zeroes[16] = { 0 };
255  union {
256  quint32 v4;
257  quint8 v6[16];
258  } ip;
259 
260  int netmask = 0;
261  quint8 *ptr = ip.v6;
262  quint8 *end;
263  length = 255;
264 
265  if (address.protocol() == QHostAddress::IPv4Protocol) {
266  ip.v4 = qToBigEndian(address.toIPv4Address());
267  end = ptr + 4;
268  } else if (address.protocol() == QHostAddress::IPv6Protocol) {
269  memcpy(ip.v6, address.toIPv6Address().c, 16);
270  end = ptr + 16;
271  } else {
272  return false;
273  }
274 
275  while (ptr < end) {
276  switch (*ptr) {
277  case 255:
278  netmask += 8;
279  ++ptr;
280  continue;
281 
282  default:
283  return false; // invalid IP-style netmask
284 
285  case 254:
286  ++netmask;
287  Q_FALLTHROUGH();
288  case 252:
289  ++netmask;
290  Q_FALLTHROUGH();
291  case 248:
292  ++netmask;
293  Q_FALLTHROUGH();
294  case 240:
295  ++netmask;
296  Q_FALLTHROUGH();
297  case 224:
298  ++netmask;
299  Q_FALLTHROUGH();
300  case 192:
301  ++netmask;
302  Q_FALLTHROUGH();
303  case 128:
304  ++netmask;
305  Q_FALLTHROUGH();
306  case 0:
307  break;
308  }
309  break;
310  }
311 
312  // confirm that the rest is only zeroes
313  if (ptr < end && memcmp(ptr + 1, zeroes, end - ptr - 1) != 0)
314  return false;
315 
316  length = netmask;
317  return true;
318 }
319 
320 static void clearBits(quint8 *where, int start, int end)
321 {
322  Q_ASSERT(end == 32 || end == 128);
323  if (start == end)
324  return;
325 
326  // for the byte where 'start' is, clear the lower bits only
327  quint8 bytemask = 256 - (1 << (8 - (start & 7)));
328  where[start / 8] &= bytemask;
329 
330  // for the tail part, clear everything
331  memset(where + (start + 7) / 8, 0, end / 8 - (start + 7) / 8);
332 }
333 
335 {
336  if (length == 255 || protocol == QHostAddress::AnyIPProtocol ||
338  return QHostAddress();
339  } else if (protocol == QHostAddress::IPv4Protocol) {
340  quint32 a;
341  if (length == 0)
342  a = 0;
343  else if (length == 32)
344  a = quint32(0xffffffff);
345  else
346  a = quint32(0xffffffff) >> (32 - length) << (32 - length);
347  return QHostAddress(a);
348  } else {
349  Q_IPV6ADDR a6;
350  memset(a6.c, 0xFF, sizeof(a6));
351  clearBits(a6.c, length, 128);
352  return QHostAddress(a6);
353  }
354 }
355 
412  : d(new QHostAddressPrivate)
413 {
414 }
415 
420  : d(new QHostAddressPrivate)
421 {
422  setAddress(ip4Addr);
423 }
424 
433  : d(new QHostAddressPrivate)
434 {
435  setAddress(ip6Addr);
436 }
437 
442  : d(new QHostAddressPrivate)
443 {
444  setAddress(ip6Addr);
445 }
446 
454  : d(new QHostAddressPrivate)
455 {
456  d->parse(address);
457 }
458 
467 QHostAddress::QHostAddress(const struct sockaddr *sockaddr)
468  : d(new QHostAddressPrivate)
469 {
470  if (sockaddr->sa_family == AF_INET)
471  setAddress(htonl(((const sockaddr_in *)sockaddr)->sin_addr.s_addr));
472  else if (sockaddr->sa_family == AF_INET6)
473  setAddress(((const sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr);
474 }
475 
480  : d(address.d)
481 {
482 }
483 
488  : d(new QHostAddressPrivate)
489 {
491 }
492 
497 {
498 }
499 
505 {
506  d = address.d;
507  return *this;
508 }
509 
518 {
520  return *this;
521 }
522 
553 {
554  d.detach();
555  d->clear();
556 }
557 
562 {
563  d.detach();
564  d->setAddress(ip4Addr);
565 }
566 
576 void QHostAddress::setAddress(const quint8 *ip6Addr)
577 {
578  d.detach();
579  d->setAddress(ip6Addr);
580 }
581 
588 {
589  d.detach();
590  d->setAddress(ip6Addr);
591 }
592 
602 {
603  d.detach();
604  return d->parse(address);
605 }
606 
615 void QHostAddress::setAddress(const struct sockaddr *sockaddr)
616 {
617  d.detach();
618  clear();
619  if (sockaddr->sa_family == AF_INET)
620  setAddress(htonl(((const sockaddr_in *)sockaddr)->sin_addr.s_addr));
621  else if (sockaddr->sa_family == AF_INET6)
622  setAddress(((const sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr);
623 }
624 
632 {
633  clear();
634 
635  Q_IPV6ADDR ip6;
636  memset(&ip6, 0, sizeof ip6);
637  quint32 ip4 = INADDR_ANY;
638 
639  switch (address) {
640  case Null:
641  return;
642 
643  case Broadcast:
644  ip4 = INADDR_BROADCAST;
645  break;
646  case LocalHost:
647  ip4 = INADDR_LOOPBACK;
648  break;
649  case AnyIPv4:
650  break;
651 
652  case LocalHostIPv6:
653  ip6[15] = 1;
654  Q_FALLTHROUGH();
655  case AnyIPv6:
656  d->setAddress(ip6);
657  return;
658 
659  case Any:
661  return;
662  }
663 
664  // common IPv4 part
665  d->setAddress(ip4);
666 }
667 
684 {
685  quint32 dummy;
686  if (ok)
691  return d->a;
692 }
693 
698 {
700 }
701 
717 {
718  return d->a6;
719 }
720 
732 {
733  QString s;
736  quint32 i = toIPv4Address();
738  } else if (d->protocol == QHostAddress::IPv6Protocol) {
740  if (!d->scopeId.isEmpty())
741  s.append(QLatin1Char('%') + d->scopeId);
742  }
743  return s;
744 }
745 
783 {
785 }
786 
800 {
801  d.detach();
803  d->scopeId = id;
804 }
805 
813 {
814  return d == other.d || isEqual(other, StrictConversion);
815 }
816 
830 {
831  if (d == other.d)
832  return true;
833 
835  switch (other.d->protocol) {
837  return d->a == other.d->a;
839  quint32 a4;
840  return convertToIpv4(a4, other.d->a6, mode) && (a4 == d->a);
842  return (mode & QHostAddress::ConvertUnspecifiedAddress) && d->a == 0;
844  return false;
845  }
846  }
847 
849  switch (other.d->protocol) {
851  quint32 a4;
852  return convertToIpv4(a4, d->a6, mode) && (a4 == other.d->a);
854  return memcmp(&d->a6, &other.d->a6, sizeof(Q_IPV6ADDR)) == 0;
857  && (other.d->a6_64.c[0] == 0) && (other.d->a6_64.c[1] == 0);
859  return false;
860  }
861  }
862 
865  switch (other.d->protocol) {
867  return other.d->a == 0;
869  return (other.d->a6_64.c[0] == 0) && (other.d->a6_64.c[1] == 0);
870  default:
871  break;
872  }
873  }
874 
875  return d->protocol == other.d->protocol;
876 }
877 
883 {
884  quint32 ip4 = INADDR_ANY;
885  switch (other) {
886  case Null:
888 
889  case Broadcast:
890  ip4 = INADDR_BROADCAST;
891  break;
892 
893  case LocalHost:
894  ip4 = INADDR_LOOPBACK;
895  break;
896 
897  case Any:
899 
900  case AnyIPv4:
901  break;
902 
903  case LocalHostIPv6:
904  case AnyIPv6:
906  quint64 second = quint8(other == LocalHostIPv6); // 1 for localhost, 0 for any
907  return d->a6_64.c[0] == 0 && d->a6_64.c[1] == qToBigEndian(second);
908  }
909  return false;
910  }
911 
912  // common IPv4 part
913  return d->protocol == QHostAddress::IPv4Protocol && d->a == ip4;
914 }
915 
924 {
926 }
927 
947 bool QHostAddress::isInSubnet(const QHostAddress &subnet, int netmask) const
948 {
949  if (subnet.protocol() != d->protocol || netmask < 0)
950  return false;
951 
952  union {
953  quint32 ip;
954  quint8 data[4];
955  } ip4, net4;
956  const quint8 *ip;
957  const quint8 *net;
959  if (netmask > 32)
960  netmask = 32;
961  ip4.ip = qToBigEndian(d->a);
962  net4.ip = qToBigEndian(subnet.d->a);
963  ip = ip4.data;
964  net = net4.data;
965  } else if (d->protocol == QHostAddress::IPv6Protocol) {
966  if (netmask > 128)
967  netmask = 128;
968  ip = d->a6.c;
969  net = subnet.d->a6.c;
970  } else {
971  return false;
972  }
973 
974  if (netmask >= 8 && memcmp(ip, net, netmask / 8) != 0)
975  return false;
976  if ((netmask & 7) == 0)
977  return true;
978 
979  // compare the last octet now
980  quint8 bytemask = 256 - (1 << (8 - (netmask & 7)));
981  quint8 ipbyte = ip[netmask / 8];
982  quint8 netbyte = net[netmask / 8];
983  return (ipbyte & bytemask) == (netbyte & bytemask);
984 }
985 
996 {
997  return isInSubnet(subnet.first, subnet.second);
998 }
999 
1000 
1026 {
1027  // We support subnets in the form:
1028  // ddd.ddd.ddd.ddd/nn
1029  // ddd.ddd.ddd/nn
1030  // ddd.ddd/nn
1031  // ddd/nn
1032  // ddd.ddd.ddd.
1033  // ddd.ddd.ddd
1034  // ddd.ddd.
1035  // ddd.ddd
1036  // ddd.
1037  // ddd
1038  // <ipv6-address>/nn
1039  //
1040  // where nn can be an IPv4-style netmask for the IPv4 forms
1041 
1042  const QPair<QHostAddress, int> invalid = qMakePair(QHostAddress(), -1);
1043  if (subnet.isEmpty())
1044  return invalid;
1045 
1046  int slash = subnet.indexOf(QLatin1Char('/'));
1047  QStringView netStr(subnet);
1048  if (slash != -1)
1049  netStr.truncate(slash);
1050 
1051  int netmask = -1;
1052  bool isIpv6 = netStr.contains(QLatin1Char(':'));
1053 
1054  if (slash != -1) {
1055  // is the netmask given in IP-form or in bit-count form?
1056  if (!isIpv6 && subnet.indexOf(QLatin1Char('.'), slash + 1) != -1) {
1057  // IP-style, convert it to bit-count form
1059  QNetmask parser;
1060  if (!mask.setAddress(subnet.mid(slash + 1)))
1061  return invalid;
1062  if (!parser.setAddress(mask))
1063  return invalid;
1064  netmask = parser.prefixLength();
1065  } else {
1066  bool ok;
1067  netmask = QStringView{subnet}.mid(slash + 1).toUInt(&ok);
1068  if (!ok)
1069  return invalid; // failed to parse the subnet
1070  }
1071  }
1072 
1073  if (isIpv6) {
1074  // looks like it's an IPv6 address
1075  if (netmask > 128)
1076  return invalid; // invalid netmask
1077  if (netmask < 0)
1078  netmask = 128;
1079 
1080  QHostAddress net;
1081  if (!net.setAddress(netStr.toString()))
1082  return invalid; // failed to parse the IP
1083 
1084  clearBits(net.d->a6.c, netmask, 128);
1085  return qMakePair(net, netmask);
1086  }
1087 
1088  if (netmask > 32)
1089  return invalid; // invalid netmask
1090 
1091  // parse the address manually
1092  auto parts = netStr.split(QLatin1Char('.'));
1093  if (parts.isEmpty() || parts.count() > 4)
1094  return invalid; // invalid IPv4 address
1095 
1096  if (parts.constLast().isEmpty())
1097  parts.removeLast();
1098 
1099  quint32 addr = 0;
1100  for (int i = 0; i < parts.count(); ++i) {
1101  bool ok;
1102  uint byteValue = parts.at(i).toUInt(&ok);
1103  if (!ok || byteValue > 255)
1104  return invalid; // invalid IPv4 address
1105 
1106  addr <<= 8;
1107  addr += byteValue;
1108  }
1109  addr <<= 8 * (4 - parts.count());
1110  if (netmask == -1) {
1111  netmask = 8 * parts.count();
1112  } else if (netmask == 0) {
1113  // special case here
1114  // x86's instructions "shr" and "shl" do not operate when
1115  // their argument is 32, so the code below doesn't work as expected
1116  addr = 0;
1117  } else if (netmask != 32) {
1118  // clear remaining bits
1119  quint32 mask = quint32(0xffffffff) >> (32 - netmask) << (32 - netmask);
1120  addr &= mask;
1121  }
1122 
1123  return qMakePair(QHostAddress(addr), netmask);
1124 }
1125 
1133 {
1134  return d->classify() == LoopbackAddress;
1135 }
1136 
1155 {
1156  return d->classify() & GlobalAddress; // GlobalAddress is a bit
1157 }
1158 
1173 {
1174  return d->classify() == LinkLocalAddress;
1175 }
1176 
1196 {
1197  return d->classify() == SiteLocalAddress;
1198 }
1199 
1217 {
1218  return d->classify() == UniqueLocalAddress;
1219 }
1220 
1230 {
1231  return d->classify() == MulticastAddress;
1232 }
1233 
1247 {
1248  return d->classify() == BroadcastAddress;
1249 }
1250 
1251 #ifndef QT_NO_DEBUG_STREAM
1253 {
1254  QDebugStateSaver saver(d);
1255  d.resetFormat().nospace();
1256  if (address == QHostAddress::Any)
1257  d << "QHostAddress(QHostAddress::Any)";
1258  else
1259  d << "QHostAddress(" << address.toString() << ')';
1260  return d;
1261 }
1262 #endif
1263 
1269 size_t qHash(const QHostAddress &key, size_t seed) noexcept
1270 {
1271  return qHashBits(key.d->a6.c, 16, seed);
1272 }
1273 
1293 #ifndef QT_NO_DATASTREAM
1294 
1303 {
1304  qint8 prot;
1305  prot = qint8(address.protocol());
1306  out << prot;
1307  switch (address.protocol()) {
1310  break;
1312  out << address.toIPv4Address();
1313  break;
1315  {
1316  Q_IPV6ADDR ipv6 = address.toIPv6Address();
1317  for (int i = 0; i < 16; ++i)
1318  out << ipv6[i];
1319  out << address.scopeId();
1320  }
1321  break;
1322  }
1323  return out;
1324 }
1325 
1334 {
1335  qint8 prot;
1336  in >> prot;
1337  switch (QHostAddress::NetworkLayerProtocol(prot)) {
1339  address.clear();
1340  break;
1342  {
1343  quint32 ipv4;
1344  in >> ipv4;
1345  address.setAddress(ipv4);
1346  }
1347  break;
1349  {
1350  Q_IPV6ADDR ipv6;
1351  for (int i = 0; i < 16; ++i)
1352  in >> ipv6[i];
1353  address.setAddress(ipv6);
1354 
1355  QString scope;
1356  in >> scope;
1357  address.setScopeId(scope);
1358  }
1359  break;
1362  break;
1363  default:
1364  address.clear();
1365  in.setStatus(QDataStream::ReadCorruptData);
1366  }
1367  return in;
1368 }
1369 
1370 #endif //QT_NO_DATASTREAM
1371 
1373 
1374 #include "moc_qhostaddress.cpp"
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
Convenience class for custom QDebug operators.
Definition: qdebug.h:176
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
size_t qHashBits(const void *p, size_t len, size_t seed=0)
Definition: qhash.cpp:771
The QHostAddress class provides an IP address.\inmodule QtNetwork.
Definition: qhostaddress.h:74
bool isLinkLocal() const
bool isGlobal() const
QString scopeId() const
QExplicitlySharedDataPointer< QHostAddressPrivate > d
Definition: qhostaddress.h:178
@ ConvertV4MappedToIPv4
Definition: qhostaddress.h:87
@ ConvertUnspecifiedAddress
Definition: qhostaddress.h:89
@ ConvertV4CompatToIPv4
Definition: qhostaddress.h:88
quint32 toIPv4Address(bool *ok=nullptr) const
bool isLoopback() const
bool isUniqueLocalUnicast() const
QHostAddress & operator=(QHostAddress &&other) noexcept
Definition: qhostaddress.h:123
QDataStream & operator<<(QDataStream &out, const QHostAddress &address)
bool operator==(const QHostAddress &address) const
bool isNull() const
QDataStream & operator>>(QDataStream &in, QHostAddress &address)
bool isInSubnet(const QHostAddress &subnet, int netmask) const
bool isBroadcast() const
void setAddress(quint32 ip4Addr)
static QPair< QHostAddress, int > parseSubnet(const QString &subnet)
Q_IPV6ADDR toIPv6Address() const
bool isSiteLocal() const
@ UnknownNetworkLayerProtocol
Definition: qhostaddress.h:108
bool isEqual(const QHostAddress &address, ConversionMode mode=TolerantConversion) const
void setScopeId(const QString &id)
QString toString() const
NetworkLayerProtocol protocol() const
bool isMulticast() const
void setAddress(quint32 a_=0)
bool parse(const QString &ipString)
AddressClassification classify() const
struct QHostAddressPrivate::@711::@714 a6_32
struct QHostAddressPrivate::@711::@713 a6_64
quint8 c[16]
Definition: qhostaddress.h:64
void removeLast() noexcept
Definition: qlist.h:819
bool setAddress(const QHostAddress &address)
QHostAddress address(QAbstractSocket::NetworkLayerProtocol protocol) const
The QString class provides a Unicode character string.
Definition: qstring.h:388
void chop(qsizetype n)
Definition: qstring.cpp:5955
void clear()
Definition: qstring.h:1240
uint toUInt(bool *ok=nullptr, int base=10) const
Definition: qstring.h:850
QString mid(qsizetype position, qsizetype n=-1) const
Definition: qstring.cpp:4994
QString simplified() const &
Definition: qstring.h:627
bool isEmpty() const
Definition: qstring.h:1216
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:4197
The QStringView class provides a unified view on UTF-16 strings with a read-only subset of the QStrin...
Definition: qstringview.h:122
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition: qstringview.h:334
constexpr void truncate(qsizetype n) noexcept
Definition: qstringview.h:291
Q_CORE_EXPORT QList< QStringView > split(QStringView sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:7702
QString toString() const
Definition: qstring.h:1165
quint8 IPv6Address[16]
Definition: qipaddress_p.h:62
void toString(QString &appendTo, IPv4Address address)
Definition: qipaddress.cpp:131
bool parseIp4(IPv4Address &address, const QChar *begin, const QChar *end)
Definition: qipaddress.cpp:75
const QChar * parseIp6(IPv6Address &address, const QChar *begin, const QChar *end)
Definition: qipaddress.cpp:154
parser
Definition: devices.py:74
#define QString()
Definition: parse-defines.h:51
#define Q_FALLTHROUGH()
std::pair< T1, T2 > QPair
Definition: qcontainerfwd.h:56
constexpr T qToBigEndian(T source)
Definition: qendian.h:187
constexpr T qFromBigEndian(T source)
Definition: qendian.h:189
unsigned int quint32
Definition: qglobal.h:288
QT_BEGIN_INCLUDE_NAMESPACE typedef unsigned char uchar
Definition: qglobal.h:332
unsigned long long quint64
Definition: qglobal.h:299
unsigned int uint
Definition: qglobal.h:334
QT_BEGIN_NAMESPACE typedef signed char qint8
Definition: qglobal.h:283
unsigned char quint8
Definition: qglobal.h:284
AddressClassification
@ MulticastAddress
@ LocalNetAddress
@ GlobalAddress
@ UniqueLocalAddress
@ SiteLocalAddress
@ UnknownAddress
@ BroadcastAddress
@ LoopbackAddress
@ LinkLocalAddress
ConversionMode
Definition: qjsoncbor.cpp:58
#define AF_INET6
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLenum GLuint id
[6]
Definition: qopengl.h:270
GLenum mode
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLuint end
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint start
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLuint in
Definition: qopenglext.h:8870
GLuint GLuint64EXT address
Definition: qopenglext.h:11428
GLdouble s
[6]
Definition: qopenglext.h:235
constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
Definition: qpair.h:55
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
QTextStream out(stdout)
[7]
QSharedPointer< T > other(t)
[5]
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:53
QThreadStorage< int * > dummy[8]