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 QNETWORKINTERFACEPRIVATE_H
6#define QNETWORKINTERFACEPRIVATE_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 purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include <QtNetwork/qnetworkinterface.h>
21#include <QtCore/qatomic.h>
22#include <QtCore/qdeadlinetimer.h>
23#include <QtCore/qlist.h>
24#include <QtCore/qstring.h>
25#include <QtNetwork/qhostaddress.h>
26#include <QtNetwork/qabstractsocket.h>
27#include <private/qhostaddress_p.h>
28
29#ifndef QT_NO_NETWORKINTERFACE
30
31QT_BEGIN_NAMESPACE
32
33class QNetworkAddressEntryPrivate
34{
35public:
36 QHostAddress address;
37 QHostAddress broadcast;
38 QDeadlineTimer preferredLifetime = QDeadlineTimer::Forever;
39 QDeadlineTimer validityLifetime = QDeadlineTimer::Forever;
40
41 QNetmask netmask;
42 bool lifetimeKnown = false;
43 QNetworkAddressEntry::DnsEligibilityStatus dnsEligibility = QNetworkAddressEntry::DnsEligibilityUnknown;
44};
45
46class QNetworkInterfacePrivate: public QSharedData
47{
48public:
49 QNetworkInterfacePrivate() : index(0)
50 { }
51 ~QNetworkInterfacePrivate()
52 { }
53
54 int index; // interface index, if know
55 int mtu = 0;
56 QNetworkInterface::InterfaceFlags flags;
57 QNetworkInterface::InterfaceType type = QNetworkInterface::Unknown;
58
59 QString name;
60 QString friendlyName;
61 QString hardwareAddress;
62
63 QList<QNetworkAddressEntry> addressEntries;
64
65 static QString makeHwAddress(int len, uchar *data);
66 static void calculateDnsEligibility(QNetworkAddressEntry *entry, bool isTemporary,
67 bool isDeprecated)
68 {
69 // this implements an algorithm that yields the same results as Windows
70 // produces, for the same input (as far as I can test)
71 if (isTemporary || isDeprecated) {
72 entry->setDnsEligibility(QNetworkAddressEntry::DnsIneligible);
73 } else {
74 AddressClassification cl = QHostAddressPrivate::classify(address: entry->ip());
75 if (cl == LoopbackAddress || cl == LinkLocalAddress)
76 entry->setDnsEligibility(QNetworkAddressEntry::DnsIneligible);
77 else
78 entry->setDnsEligibility(QNetworkAddressEntry::DnsEligible);
79 }
80 }
81
82private:
83 // disallow copying -- avoid detaching
84 QNetworkInterfacePrivate &operator=(const QNetworkInterfacePrivate &other);
85 QNetworkInterfacePrivate(const QNetworkInterfacePrivate &other);
86};
87
88class QNetworkInterfaceManager
89{
90public:
91 QNetworkInterfaceManager();
92 ~QNetworkInterfaceManager();
93
94 QSharedDataPointer<QNetworkInterfacePrivate> interfaceFromName(const QString &name);
95 QSharedDataPointer<QNetworkInterfacePrivate> interfaceFromIndex(int index);
96 QList<QSharedDataPointer<QNetworkInterfacePrivate> > allInterfaces();
97
98 static uint interfaceIndexFromName(const QString &name);
99 static QString interfaceNameFromIndex(uint index);
100
101 // convenience:
102 QSharedDataPointer<QNetworkInterfacePrivate> empty;
103
104private:
105 QList<QNetworkInterfacePrivate *> scan();
106};
107
108
109QT_END_NAMESPACE
110
111#endif // QT_NO_NETWORKINTERFACE
112
113#endif
114

source code of qtbase/src/network/kernel/qnetworkinterface_p.h