qnetworkinterface.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/kernel/qnetworkinterface.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7static QList<QNetworkInterfacePrivate *> postProcess(QList<QNetworkInterfacePrivate *> list)-
8{-
9 QList<QNetworkInterfacePrivate *>::Iterator it = list.begin();-
10 const QList<QNetworkInterfacePrivate *>::Iterator end = list.end();-
11 for ( ; it != end; ++it) {-
12 QList<QNetworkAddressEntry>::Iterator addr_it = (*it)->addressEntries.begin();-
13 const QList<QNetworkAddressEntry>::Iterator addr_end = (*it)->addressEntries.end();-
14 for ( ; addr_it != addr_end; ++addr_it) {-
15 if (addr_it->ip().protocol() != QAbstractSocket::IPv4Protocol)-
16 continue;-
17-
18 if (!addr_it->netmask().isNull() && addr_it->broadcast().isNull()) {-
19 QHostAddress bcast = addr_it->ip();-
20 bcast = QHostAddress(bcast.toIPv4Address() | ~addr_it->netmask().toIPv4Address());-
21 addr_it->setBroadcast(bcast);-
22 }-
23 }-
24 }-
25-
26 return list;-
27}-
28-
29namespace { namespace Q_QGS_manager { typedef QNetworkInterfaceManager Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QNetworkInterfaceManager, Q_QGS_manager::innerFunction, Q_QGS_manager::guard> manager;-
30-
31QNetworkInterfaceManager::QNetworkInterfaceManager()-
32{-
33}-
34-
35QNetworkInterfaceManager::~QNetworkInterfaceManager()-
36{-
37}-
38-
39QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interfaceFromName(const QString &name)-
40{-
41 QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();-
42 QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();-
43-
44 bool ok;-
45 uint index = name.toUInt(&ok);-
46-
47 for ( ; it != interfaceList.constEnd(); ++it) {-
48 if (ok && (*it)->index == int(index))-
49 return *it;-
50 else if ((*it)->name == name)-
51 return *it;-
52 }-
53-
54 return empty;-
55}-
56-
57QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interfaceFromIndex(int index)-
58{-
59 QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();-
60 QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();-
61 for ( ; it != interfaceList.constEnd(); ++it)-
62 if ((*it)->index == index)-
63 return *it;-
64-
65 return empty;-
66}-
67-
68QList<QSharedDataPointer<QNetworkInterfacePrivate> > QNetworkInterfaceManager::allInterfaces()-
69{-
70 const QList<QNetworkInterfacePrivate *> list = postProcess(scan());-
71 QList<QSharedDataPointer<QNetworkInterfacePrivate> > result;-
72 result.reserve(list.size());-
73-
74 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(list)>::type> _container_((list)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (QNetworkInterfacePrivate *ptr = *_container_.i; _container_.control; _container_.control = 0: list)-
75 result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr);
executed 612 times by 19 tests: result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr);
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkConfiguration
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_QXmlStream
  • tst_qtcpsocket - unknown status
612
76-
77 return
executed 204 times by 19 tests: return result;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkConfiguration
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_QXmlStream
  • tst_qtcpsocket - unknown status
result;
executed 204 times by 19 tests: return result;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkConfiguration
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_QXmlStream
  • tst_qtcpsocket - unknown status
204
78}-
79-
80QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data)-
81{-
82 const int outLen = qMax(len * 2 + (len - 1) * 1, 0);-
83 QString result(outLen, Qt::Uninitialized);-
84 QChar *out = result.data();-
85 for (int i = 0; i < len; ++i) {-
86 if (i)-
87 *out++ = QLatin1Char(':');-
88 *out++ = QLatin1Char(QtMiscUtils::toHexUpper(data[i] / 16));-
89 *out++ = QLatin1Char(QtMiscUtils::toHexUpper(data[i] % 16));-
90 }-
91 return result;-
92}-
93QNetworkAddressEntry::QNetworkAddressEntry()-
94 : d(new QNetworkAddressEntryPrivate)-
95{-
96}-
97-
98-
99-
100-
101-
102QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other)-
103 : d(new QNetworkAddressEntryPrivate(*other.d.data()))-
104{-
105}-
106-
107-
108-
109-
110QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry &other)-
111{-
112 *d.data() = *other.d.data();-
113 return *this;-
114}-
115QNetworkAddressEntry::~QNetworkAddressEntry()-
116{-
117}-
118-
119-
120-
121-
122-
123bool QNetworkAddressEntry::operator==(const QNetworkAddressEntry &other) const-
124{-
125 if (d == other.d) return true;-
126 if (!d || !other.d) return false;-
127 return d->address == other.d->address &&-
128 d->netmask == other.d->netmask &&-
129 d->broadcast == other.d->broadcast;-
130}-
131QHostAddress QNetworkAddressEntry::ip() const-
132{-
133 return d->address;-
134}-
135-
136-
137-
138-
139-
140void QNetworkAddressEntry::setIp(const QHostAddress &newIp)-
141{-
142 d->address = newIp;-
143}-
144QHostAddress QNetworkAddressEntry::netmask() const-
145{-
146 return d->netmask;-
147}-
148void QNetworkAddressEntry::setNetmask(const QHostAddress &newNetmask)-
149{-
150 if (newNetmask.protocol() != ip().protocol()) {-
151 d->netmask = QNetmaskAddress();-
152 return;-
153 }-
154-
155 d->netmask.setAddress(newNetmask);-
156}-
157int QNetworkAddressEntry::prefixLength() const-
158{-
159 return d->netmask.prefixLength();-
160}-
161void QNetworkAddressEntry::setPrefixLength(int length)-
162{-
163 d->netmask.setPrefixLength(d->address.protocol(), length);-
164}-
165QHostAddress QNetworkAddressEntry::broadcast() const-
166{-
167 return d->broadcast;-
168}-
169-
170-
171-
172-
173-
174void QNetworkAddressEntry::setBroadcast(const QHostAddress &newBroadcast)-
175{-
176 d->broadcast = newBroadcast;-
177}-
178QNetworkInterface::QNetworkInterface()-
179 : d(0)-
180{-
181}-
182-
183-
184-
185-
186QNetworkInterface::~QNetworkInterface()-
187{-
188}-
189-
190-
191-
192-
193-
194QNetworkInterface::QNetworkInterface(const QNetworkInterface &other)-
195 : d(other.d)-
196{-
197}-
198-
199-
200-
201-
202-
203QNetworkInterface &QNetworkInterface::operator=(const QNetworkInterface &other)-
204{-
205 d = other.d;-
206 return *this;-
207}-
208bool QNetworkInterface::isValid() const-
209{-
210 return !name().isEmpty();-
211}-
212int QNetworkInterface::index() const-
213{-
214 return d ? d->index : 0;-
215}-
216-
217-
218-
219-
220-
221-
222-
223QString QNetworkInterface::name() const-
224{-
225 return d ? d->name : QString();-
226}-
227QString QNetworkInterface::humanReadableName() const-
228{-
229 return d ? !d->friendlyName.isEmpty() ? d->friendlyName : name() : QString();-
230}-
231-
232-
233-
234-
235QNetworkInterface::InterfaceFlags QNetworkInterface::flags() const-
236{-
237 return d ? d->flags : InterfaceFlags(0);-
238}-
239QString QNetworkInterface::hardwareAddress() const-
240{-
241 return d ? d->hardwareAddress : QString();-
242}-
243QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const-
244{-
245 return d ? d->addressEntries : QList<QNetworkAddressEntry>();-
246}-
247int QNetworkInterface::interfaceIndexFromName(const QString &name)-
248{-
249 if (name.isEmpty()
name.isEmpty()Description
TRUEevaluated 1556 times by 15 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QHostInfo
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_platformsocketengine - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qimagereader - unknown status
  • tst_qobject - unknown status
  • tst_qsocketnotifier - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlsimplereader - unknown status
FALSEevaluated 27 times by 3 tests
Evaluated by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
)
27-1556
250 return
executed 1556 times by 15 tests: return 0;
Executed by:
  • tst_NetworkSelfTest
  • tst_QHostInfo
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_platformsocketengine - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qimagereader - unknown status
  • tst_qobject - unknown status
  • tst_qsocketnotifier - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlsimplereader - unknown status
0;
executed 1556 times by 15 tests: return 0;
Executed by:
  • tst_NetworkSelfTest
  • tst_QHostInfo
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_platformsocketengine - unknown status
  • tst_qhttpsocketengine - unknown status
  • tst_qimagereader - unknown status
  • tst_qobject - unknown status
  • tst_qsocketnotifier - unknown status
  • tst_qsocks5socketengine - unknown status
  • tst_qsslsocket - unknown status
  • tst_qtcpsocket - unknown status
  • tst_qxmlsimplereader - unknown status
1556
251-
252 bool ok;-
253 uint id = name.toUInt(&ok);-
254 if (!ok
!okDescription
TRUEevaluated 27 times by 3 tests
Evaluated by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
FALSEnever evaluated
)
0-27
255 id = QNetworkInterfaceManager::interfaceIndexFromName(name);
executed 27 times by 3 tests: id = QNetworkInterfaceManager::interfaceIndexFromName(name);
Executed by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
27
256 return
executed 27 times by 3 tests: return int(id);
Executed by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
int(id);
executed 27 times by 3 tests: return int(id);
Executed by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
27
257}-
258QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name)-
259{-
260 QNetworkInterface result;-
261 result.d = manager()->interfaceFromName(name);-
262 return result;-
263}-
264QNetworkInterface QNetworkInterface::interfaceFromIndex(int index)-
265{-
266 QNetworkInterface result;-
267 result.d = manager()->interfaceFromIndex(index);-
268 return result;-
269}-
270QString QNetworkInterface::interfaceNameFromIndex(int index)-
271{-
272 if (!index
!indexDescription
TRUEnever evaluated
FALSEevaluated 33 times by 3 tests
Evaluated by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
)
0-33
273 return
never executed: return QString();
QString();
never executed: return QString();
0
274 return
executed 33 times by 3 tests: return QNetworkInterfaceManager::interfaceNameFromIndex(index);
Executed by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
QNetworkInterfaceManager::interfaceNameFromIndex(index);
executed 33 times by 3 tests: return QNetworkInterfaceManager::interfaceNameFromIndex(index);
Executed by:
  • tst_QNetworkInterface
  • tst_QTcpServer
  • tst_QUdpSocket
33
275}-
276-
277-
278-
279-
280-
281QList<QNetworkInterface> QNetworkInterface::allInterfaces()-
282{-
283 const QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();-
284 QList<QNetworkInterface> result;-
285 result.reserve(privs.size());-
286 for (QForeachContainer<typename QtPrivate::remove_reference<decltype(privs)>::type> _container_((privs)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QSharedDataPointer<QNetworkInterfacePrivate>auto &p = *_container_.i; _container_.control; _container_.control = 0: privs) {-
287 QNetworkInterface item;-
288 item.d = p;-
289 result << item;-
290 }
executed 507 times by 19 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkConfiguration
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_QXmlStream
  • tst_qtcpsocket - unknown status
507
291-
292 return
executed 169 times by 19 tests: return result;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkConfiguration
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_QXmlStream
  • tst_qtcpsocket - unknown status
result;
executed 169 times by 19 tests: return result;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractNetworkCache
  • tst_QFtp
  • tst_QHostInfo
  • tst_QHttpNetworkConnection
  • tst_QNetworkAccessManager
  • tst_QNetworkAccessManager_And_QProgressDialog
  • tst_QNetworkConfiguration
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
  • tst_QNetworkReply
  • tst_QNetworkSession
  • tst_QTcpServer
  • tst_QUdpSocket
  • tst_QXmlInputSource
  • tst_QXmlStream
  • tst_qtcpsocket - unknown status
169
293}-
294-
295-
296-
297-
298-
299-
300-
301QList<QHostAddress> QNetworkInterface::allAddresses()-
302{-
303 const QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();-
304 QList<QHostAddress> result;-
for (QForeachContainer<typename QtPrivate::remove_reference<decltype(privs)>::type> _container_((privs)); _container_.control && _container_.i != _container_.e;
305 ++_container_.i, _container_.control ^= 1)for (const QSharedDataPointer<QNetworkInterfacePrivate>auto &p = *_container_.i; _container_.control; _container_.control = 0: privs) {-
306 for (QForeachContainer<typename QtPrivate::remove_reference<decltypeconst QNetworkAddressEntry &entry : qAsConst(p->addressEntries)>::type> _container_((p->addressEntries)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QNetworkAddressEntry &entry = *_container_.i; _container_.control; _container_.control = 0)))-
307 result += entry.ip();
executed 24 times by 2 tests: result += entry.ip();
Executed by:
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
24
308 }
executed 12 times by 2 tests: end of block
Executed by:
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
12
309-
310 return
executed 4 times by 2 tests: return result;
Executed by:
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
result;
executed 4 times by 2 tests: return result;
Executed by:
  • tst_QNetworkInterface
  • tst_QNetworkProxyFactory
4
311}-
312-
313-
314static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags)-
315{-
316 if (flags & QNetworkInterface::IsUp)-
317 debug << "IsUp ";-
318 if (flags & QNetworkInterface::IsRunning)-
319 debug << "IsRunning ";-
320 if (flags & QNetworkInterface::CanBroadcast)-
321 debug << "CanBroadcast ";-
322 if (flags & QNetworkInterface::IsLoopBack)-
323 debug << "IsLoopBack ";-
324 if (flags & QNetworkInterface::IsPointToPoint)-
325 debug << "IsPointToPoint ";-
326 if (flags & QNetworkInterface::CanMulticast)-
327 debug << "CanMulticast ";-
328 return debug;-
329}-
330-
331static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry)-
332{-
333 debug << "(address = " << entry.ip();-
334 if (!entry.netmask().isNull())-
335 debug << ", netmask = " << entry.netmask();-
336 if (!entry.broadcast().isNull())-
337 debug << ", broadcast = " << entry.broadcast();-
338 debug << ')';-
339 return debug;-
340}-
341-
342QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface)-
343{-
344 QDebugStateSaver saver(debug);-
345 debug.resetFormat().nospace();-
346 debug << "QNetworkInterface(name = " << networkInterface.name()-
347 << ", hardware address = " << networkInterface.hardwareAddress()-
348 << ", flags = ";-
349 flagsDebug(debug, networkInterface.flags());-
350 debug << ", entries = " << networkInterface.addressEntries()-
351 << ")\n";-
352 return debug;-
353}-
354-
355-
356-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9