Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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"
21
#
include
"qabstractsocket.h"
22
23
QT_BEGIN_NAMESPACE
24
25
enum
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
41
class
QNetmask
42
{
43
// stores 0-32 for IPv4, 0-128 for IPv6, or 255 for invalid
44
quint8 length;
45
public
:
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
69
class
QHostAddressPrivate
:
public
QSharedData
70
{
71
public
:
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
{
79
a6 = {};
80
a = 0;
81
protocol = QHostAddress::UnknownNetworkLayerProtocol;
82
scopeId.clear();
83
}
84
85
QString
scopeId
;
86
87
union
{
88
Q_IPV6ADDR
a6 = {};
// IPv6 address
89
struct
{ quint64 c[2]; } a6_64;
90
struct
{ quint32 c[4]; } a6_32;
91
};
92
quint32
a
= 0;
// IPv4 address
93
qint8
protocol
=
QHostAddress
::
UnknownNetworkLayerProtocol
;
94
95
AddressClassification
classify
()
const
;
96
static
AddressClassification
classify
(
const
QHostAddress &address)
97
{
return
address.d->classify(); }
98
99
friend
class
QHostAddress;
100
};
101
102
QT_END_NAMESPACE
103
104
#
endif
QDataStream
\inmodule QtCore\reentrant
Definition
qdatastream.h:50
QHostAddressPrivate
Definition
qhostaddress_p.h:70
QHostAddressPrivate::parse
bool parse(const QString &ipString)
Definition
qhostaddress.cpp:118
QHostAddressPrivate::setAddress
void setAddress(const quint8 *a_)
Definition
qhostaddress.cpp:91
QHostAddressPrivate::a
quint32 a
Definition
qhostaddress_p.h:92
QHostAddressPrivate::classify
AddressClassification classify() const
Definition
qhostaddress.cpp:143
QHostAddressPrivate::protocol
qint8 protocol
Definition
qhostaddress_p.h:93
QHostAddressPrivate::setAddress
void setAddress(const Q_IPV6ADDR &a_)
Definition
qhostaddress.cpp:100
QHostAddressPrivate::classify
static AddressClassification classify(const QHostAddress &address)
Definition
qhostaddress_p.h:96
QHostAddressPrivate::scopeId
QString scopeId
Definition
qhostaddress_p.h:85
QHostAddressPrivate::clear
void clear()
Definition
qhostaddress_p.h:77
QHostAddressPrivate::setAddress
void setAddress(quint32 a_=0)
Definition
qhostaddress.cpp:41
QHostAddress
The QHostAddress class provides an IP address.
Definition
qhostaddress.h:43
QHostAddress::operator>>
QDataStream & operator>>(QDataStream &in, QHostAddress &address)
Reads a host address into address from the stream in and returns a reference to the stream.
Definition
qhostaddress.cpp:1324
QNetmask
Definition
qhostaddress_p.h:42
QNetmask::setAddress
bool setAddress(const QHostAddress &address)
Definition
qhostaddress.cpp:217
QNetmask::prefixLength
int prefixLength() const
Definition
qhostaddress_p.h:51
QNetmask::setPrefixLength
void setPrefixLength(QAbstractSocket::NetworkLayerProtocol proto, int len)
Definition
qhostaddress_p.h:52
QNetmask::QNetmask
constexpr QNetmask()
Definition
qhostaddress_p.h:46
QNetmask::address
QHostAddress address(QAbstractSocket::NetworkLayerProtocol protocol) const
Definition
qhostaddress.cpp:299
QNetmask::operator==
friend bool operator==(QNetmask n1, QNetmask n2)
Definition
qhostaddress_p.h:65
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
convertToIpv4
static bool convertToIpv4(quint32 &a, const Q_IPV6ADDR &a6, const QHostAddress::ConversionMode mode)
Definition
qhostaddress.cpp:58
qHash
size_t qHash(const QHostAddress &key, size_t seed) noexcept
Definition
qhostaddress.cpp:1260
parseIp6
static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId)
Definition
qhostaddress.cpp:105
clearBits
static void clearBits(quint8 *where, int start, int end)
Definition
qhostaddress.cpp:285
Q_IPV6ADDR
QIPv6Address Q_IPV6ADDR
Definition
qhostaddress.h:36
AF_INET6
#define AF_INET6
Definition
qnativesocketengine_win.cpp:111
qtbase
src
network
kernel
qhostaddress_p.h
Generated on
for Qt by
1.18.0