Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhostaddress_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QHOSTADDRESSPRIVATE_H
6#define QHOSTADDRESSPRIVATE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the QHostAddress and QNetworkInterface classes. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include "qhostaddress.h"
22
23QT_BEGIN_NAMESPACE
24
25enum AddressClassification {
26 LoopbackAddress = 1,
27 LocalNetAddress, // RFC 1122
28 LinkLocalAddress, // RFC 4291 (v6), RFC 3927 (v4)
29 MulticastAddress, // RFC 4291 (v6), RFC 3171 (v4)
30 BroadcastAddress, // RFC 919, 922
31
32 GlobalAddress = 16,
33 TestNetworkAddress, // RFC 3849 (v6), RFC 5737 (v4),
34 PrivateNetworkAddress, // RFC 1918
35 UniqueLocalAddress, // RFC 4193
36 SiteLocalAddress, // RFC 4291 (deprecated by RFC 3879, should be treated as global)
37
38 UnknownAddress = 0 // unclassified or reserved
39};
40
42{
43 // stores 0-32 for IPv4, 0-128 for IPv6, or 255 for invalid
44 quint8 length;
45public:
46 constexpr QNetmask() : length(255) {}
47
48 bool setAddress(const QHostAddress &address);
49 QHostAddress address(QAbstractSocket::NetworkLayerProtocol protocol) const;
50
51 int prefixLength() const { return length == 255 ? -1 : length; }
52 void setPrefixLength(QAbstractSocket::NetworkLayerProtocol proto, int len)
53 {
54 int maxlen = -1;
55 if (proto == QAbstractSocket::IPv4Protocol)
56 maxlen = 32;
57 else if (proto == QAbstractSocket::IPv6Protocol)
58 maxlen = 128;
59 if (len > maxlen || len < 0)
60 length = 255U;
61 else
62 length = unsigned(len);
63 }
64
65 friend bool operator==(QNetmask n1, QNetmask n2)
66 { return n1.length == n2.length; }
67};
68
70{
71public:
72 void setAddress(quint32 a_ = 0);
73 void setAddress(const quint8 *a_);
74 void setAddress(const Q_IPV6ADDR &a_);
75
76 bool parse(const QString &ipString);
77 void clear();
78
80
81 union {
82 Q_IPV6ADDR a6 = {}; // IPv6 address
83 struct { quint64 c[2]; } a6_64;
84 struct { quint32 c[4]; } a6_32;
85 };
86 quint32 a = 0; // IPv4 address
88
90 static AddressClassification classify(const QHostAddress &address)
91 { return address.d->classify(); }
92
93 friend class QHostAddress;
94};
95
96QT_END_NAMESPACE
97
98#endif
\inmodule QtCore\reentrant
Definition qdatastream.h:50
bool parse(const QString &ipString)
void setAddress(const quint8 *a_)
AddressClassification classify() const
void setAddress(const Q_IPV6ADDR &a_)
static AddressClassification classify(const QHostAddress &address)
void setAddress(quint32 a_=0)
The QHostAddress class provides an IP address.
QDataStream & operator>>(QDataStream &in, QHostAddress &address)
Reads a host address into address from the stream in and returns a reference to the stream.
bool setAddress(const QHostAddress &address)
int prefixLength() const
void setPrefixLength(QAbstractSocket::NetworkLayerProtocol proto, int len)
constexpr QNetmask()
QHostAddress address(QAbstractSocket::NetworkLayerProtocol protocol) const
friend bool operator==(QNetmask n1, QNetmask n2)
static bool convertToIpv4(quint32 &a, const Q_IPV6ADDR &a6, const QHostAddress::ConversionMode mode)
size_t qHash(const QHostAddress &key, size_t seed) noexcept
static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId)
static void clearBits(quint8 *where, int start, int end)
QIPv6Address Q_IPV6ADDR
#define AF_INET6