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
qnetworkinterface.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 QNETWORKINTERFACE_H
6#define QNETWORKINTERFACE_H
7
8#include <QtNetwork/qtnetworkglobal.h>
9#include <QtCore/qshareddata.h>
10#include <QtCore/qscopedpointer.h>
11#include <QtNetwork/qhostaddress.h>
12
13#include <memory>
14
15#ifndef QT_NO_NETWORKINTERFACE
16
17QT_BEGIN_NAMESPACE
18
19class QDeadlineTimer;
20
21class QNetworkAddressEntryPrivate;
22class Q_NETWORK_EXPORT QNetworkAddressEntry
23{
24public:
25 enum DnsEligibilityStatus : qint8 {
26 DnsEligibilityUnknown = -1,
27 DnsIneligible = 0,
28 DnsEligible = 1
29 };
30
31 QNetworkAddressEntry();
32 QNetworkAddressEntry(const QNetworkAddressEntry &other);
33 QNetworkAddressEntry &operator=(QNetworkAddressEntry &&other) noexcept { swap(other); return *this; }
34 QNetworkAddressEntry &operator=(const QNetworkAddressEntry &other);
35 ~QNetworkAddressEntry();
36
37 void swap(QNetworkAddressEntry &other) noexcept { d.swap(other.d); }
38
39 bool operator==(const QNetworkAddressEntry &other) const;
40 inline bool operator!=(const QNetworkAddressEntry &other) const
41 { return !(*this == other); }
42
43 DnsEligibilityStatus dnsEligibility() const;
44 void setDnsEligibility(DnsEligibilityStatus status);
45
46 QHostAddress ip() const;
47 void setIp(const QHostAddress &newIp);
48
49 QHostAddress netmask() const;
50 void setNetmask(const QHostAddress &newNetmask);
51 int prefixLength() const;
52 void setPrefixLength(int length);
53
54 QHostAddress broadcast() const;
55 void setBroadcast(const QHostAddress &newBroadcast);
56
57 bool isLifetimeKnown() const;
58 QDeadlineTimer preferredLifetime() const;
59 QDeadlineTimer validityLifetime() const;
60 void setAddressLifetime(QDeadlineTimer preferred, QDeadlineTimer validity);
61 void clearAddressLifetime();
62 bool isPermanent() const;
63 bool isTemporary() const { return !isPermanent(); }
64
65private:
66 // ### Qt 7: make implicitly shared
67 std::unique_ptr<QNetworkAddressEntryPrivate> d;
68};
69
71
73class Q_NETWORK_EXPORT QNetworkInterface
74{
75 Q_GADGET
76public:
77 enum InterfaceFlag {
78 IsUp = 0x1,
79 IsRunning = 0x2,
80 CanBroadcast = 0x4,
81 IsLoopBack = 0x8,
82 IsPointToPoint = 0x10,
83 CanMulticast = 0x20
84 };
85 Q_DECLARE_FLAGS(InterfaceFlags, InterfaceFlag)
86 Q_FLAG(InterfaceFlags)
87
88 enum InterfaceType {
89 Loopback = 1,
90 Virtual,
91 Ethernet,
92 Slip,
93 CanBus,
94 Ppp,
95 Fddi,
96 Wifi,
97 Ieee80211 = Wifi, // alias
98 Phonet,
99 Ieee802154,
100 SixLoWPAN, // 6LoWPAN, but we can't start with a digit
101 Ieee80216,
102 Ieee1394,
103
104 Unknown = 0
105 };
106 Q_ENUM(InterfaceType)
107
108 QNetworkInterface();
109 QNetworkInterface(const QNetworkInterface &other);
110 QNetworkInterface &operator=(QNetworkInterface &&other) noexcept { swap(other); return *this; }
111 QNetworkInterface &operator=(const QNetworkInterface &other);
112 ~QNetworkInterface();
113
114 void swap(QNetworkInterface &other) noexcept { d.swap(other.d); }
115
116 bool isValid() const;
117
118 int index() const;
119 int maximumTransmissionUnit() const;
120 QString name() const;
121 QString humanReadableName() const;
122 InterfaceFlags flags() const;
123 InterfaceType type() const;
124 QString hardwareAddress() const;
125 QList<QNetworkAddressEntry> addressEntries() const;
126
127 static int interfaceIndexFromName(const QString &name);
128 static QNetworkInterface interfaceFromName(const QString &name);
129 static QNetworkInterface interfaceFromIndex(int index);
130 static QString interfaceNameFromIndex(int index);
131 static QList<QNetworkInterface> allInterfaces();
132 static QList<QHostAddress> allAddresses();
133
134private:
135 friend class QNetworkInterfacePrivate;
136 QSharedDataPointer<QNetworkInterfacePrivate> d;
137};
138
140
141Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkInterface::InterfaceFlags)
142
143#ifndef QT_NO_DEBUG_STREAM
144Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry);
145Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface);
146#endif
147
148QT_END_NAMESPACE
149
150QT_DECL_METATYPE_EXTERN(QNetworkAddressEntry, Q_NETWORK_EXPORT)
151QT_DECL_METATYPE_EXTERN(QNetworkInterface, Q_NETWORK_EXPORT)
152
153#endif // QT_NO_NETWORKINTERFACE
154
155#endif
The QNetworkAddressEntry class stores one IP address supported by a network interface,...
QSharedDataPointer< QNetworkInterfacePrivate > interfaceFromName(const QString &name)
QList< QSharedDataPointer< QNetworkInterfacePrivate > > allInterfaces()
QSharedDataPointer< QNetworkInterfacePrivate > interfaceFromIndex(int index)
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
static QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags)