1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QNETWORKINTERFACE_H
41#define QNETWORKINTERFACE_H
42
43#include <QtNetwork/qtnetworkglobal.h>
44#include <QtCore/qshareddata.h>
45#include <QtCore/qscopedpointer.h>
46#include <QtNetwork/qhostaddress.h>
47
48#ifndef QT_NO_NETWORKINTERFACE
49
50QT_BEGIN_NAMESPACE
51
52class QDeadlineTimer;
53
54class QNetworkAddressEntryPrivate;
55class Q_NETWORK_EXPORT QNetworkAddressEntry
56{
57public:
58 enum DnsEligibilityStatus : qint8 {
59 DnsEligibilityUnknown = -1,
60 DnsIneligible = 0,
61 DnsEligible = 1
62 };
63
64 QNetworkAddressEntry();
65 QNetworkAddressEntry(const QNetworkAddressEntry &other);
66 QNetworkAddressEntry &operator=(QNetworkAddressEntry &&other) noexcept { swap(other); return *this; }
67 QNetworkAddressEntry &operator=(const QNetworkAddressEntry &other);
68 ~QNetworkAddressEntry();
69
70 void swap(QNetworkAddressEntry &other) noexcept { qSwap(d, other.d); }
71
72 bool operator==(const QNetworkAddressEntry &other) const;
73 inline bool operator!=(const QNetworkAddressEntry &other) const
74 { return !(*this == other); }
75
76 DnsEligibilityStatus dnsEligibility() const;
77 void setDnsEligibility(DnsEligibilityStatus status);
78
79 QHostAddress ip() const;
80 void setIp(const QHostAddress &newIp);
81
82 QHostAddress netmask() const;
83 void setNetmask(const QHostAddress &newNetmask);
84 int prefixLength() const;
85 void setPrefixLength(int length);
86
87 QHostAddress broadcast() const;
88 void setBroadcast(const QHostAddress &newBroadcast);
89
90 bool isLifetimeKnown() const;
91 QDeadlineTimer preferredLifetime() const;
92 QDeadlineTimer validityLifetime() const;
93 void setAddressLifetime(QDeadlineTimer preferred, QDeadlineTimer validity);
94 void clearAddressLifetime();
95 bool isPermanent() const;
96 bool isTemporary() const { return !isPermanent(); }
97
98private:
99 QScopedPointer<QNetworkAddressEntryPrivate> d;
100};
101
102Q_DECLARE_SHARED(QNetworkAddressEntry)
103
104class QNetworkInterfacePrivate;
105class Q_NETWORK_EXPORT QNetworkInterface
106{
107 Q_GADGET
108public:
109 enum InterfaceFlag {
110 IsUp = 0x1,
111 IsRunning = 0x2,
112 CanBroadcast = 0x4,
113 IsLoopBack = 0x8,
114 IsPointToPoint = 0x10,
115 CanMulticast = 0x20
116 };
117 Q_DECLARE_FLAGS(InterfaceFlags, InterfaceFlag)
118 Q_FLAG(InterfaceFlags)
119
120 enum InterfaceType {
121 Loopback = 1,
122 Virtual,
123 Ethernet,
124 Slip,
125 CanBus,
126 Ppp,
127 Fddi,
128 Wifi,
129 Ieee80211 = Wifi, // alias
130 Phonet,
131 Ieee802154,
132 SixLoWPAN, // 6LoWPAN, but we can't start with a digit
133 Ieee80216,
134 Ieee1394,
135
136 Unknown = 0
137 };
138 Q_ENUM(InterfaceType)
139
140 QNetworkInterface();
141 QNetworkInterface(const QNetworkInterface &other);
142 QNetworkInterface &operator=(QNetworkInterface &&other) noexcept { swap(other); return *this; }
143 QNetworkInterface &operator=(const QNetworkInterface &other);
144 ~QNetworkInterface();
145
146 void swap(QNetworkInterface &other) noexcept { qSwap(d, other.d); }
147
148 bool isValid() const;
149
150 int index() const;
151 int maximumTransmissionUnit() const;
152 QString name() const;
153 QString humanReadableName() const;
154 InterfaceFlags flags() const;
155 InterfaceType type() const;
156 QString hardwareAddress() const;
157 QList<QNetworkAddressEntry> addressEntries() const;
158
159 static int interfaceIndexFromName(const QString &name);
160 static QNetworkInterface interfaceFromName(const QString &name);
161 static QNetworkInterface interfaceFromIndex(int index);
162 static QString interfaceNameFromIndex(int index);
163 static QList<QNetworkInterface> allInterfaces();
164 static QList<QHostAddress> allAddresses();
165
166private:
167 friend class QNetworkInterfacePrivate;
168 QSharedDataPointer<QNetworkInterfacePrivate> d;
169};
170
171Q_DECLARE_SHARED(QNetworkInterface)
172
173Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkInterface::InterfaceFlags)
174
175#ifndef QT_NO_DEBUG_STREAM
176Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface);
177#endif
178
179QT_END_NAMESPACE
180
181Q_DECLARE_METATYPE(QNetworkAddressEntry)
182Q_DECLARE_METATYPE(QNetworkInterface)
183
184#endif // QT_NO_NETWORKINTERFACE
185
186#endif
187