kernel/qnetworkinterface.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qnetworkinterface.h" -
43#include "qnetworkinterface_p.h" -
44 -
45#include "qdebug.h" -
46#include "qendian.h" -
47 -
48#ifndef QT_NO_NETWORKINTERFACE -
49 -
50QT_BEGIN_NAMESPACE -
51 -
52static QList<QNetworkInterfacePrivate *> postProcess(QList<QNetworkInterfacePrivate *> list) -
53{ -
54 // Some platforms report a netmask but don't report a broadcast address -
55 // Go through all available addresses and calculate the broadcast address -
56 // from the IP and the netmask -
57 // -
58 // This is an IPv4-only thing -- IPv6 has no concept of broadcasts -
59 // The math is: -
60 // broadcast = IP | ~netmask -
61 -
62 QList<QNetworkInterfacePrivate *>::Iterator it = list.begin();
executed (the execution status of this line is deduced): QList<QNetworkInterfacePrivate *>::Iterator it = list.begin();
-
63 const QList<QNetworkInterfacePrivate *>::Iterator end = list.end();
executed (the execution status of this line is deduced): const QList<QNetworkInterfacePrivate *>::Iterator end = list.end();
-
64 for ( ; it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:815
yes
Evaluation Count:163
163-815
65 QList<QNetworkAddressEntry>::Iterator addr_it = (*it)->addressEntries.begin();
executed (the execution status of this line is deduced): QList<QNetworkAddressEntry>::Iterator addr_it = (*it)->addressEntries.begin();
-
66 const QList<QNetworkAddressEntry>::Iterator addr_end = (*it)->addressEntries.end();
executed (the execution status of this line is deduced): const QList<QNetworkAddressEntry>::Iterator addr_end = (*it)->addressEntries.end();
-
67 for ( ; addr_it != addr_end; ++addr_it) {
evaluated: addr_it != addr_end
TRUEFALSE
yes
Evaluation Count:1304
yes
Evaluation Count:815
815-1304
68 if (addr_it->ip().protocol() != QAbstractSocket::IPv4Protocol)
evaluated: addr_it->ip().protocol() != QAbstractSocket::IPv4Protocol
TRUEFALSE
yes
Evaluation Count:652
yes
Evaluation Count:652
652
69 continue;
executed: continue;
Execution Count:652
652
70 -
71 if (!addr_it->netmask().isNull() && addr_it->broadcast().isNull()) {
partially evaluated: !addr_it->netmask().isNull()
TRUEFALSE
yes
Evaluation Count:652
no
Evaluation Count:0
evaluated: addr_it->broadcast().isNull()
TRUEFALSE
yes
Evaluation Count:163
yes
Evaluation Count:489
0-652
72 QHostAddress bcast = addr_it->ip();
executed (the execution status of this line is deduced): QHostAddress bcast = addr_it->ip();
-
73 bcast = QHostAddress(bcast.toIPv4Address() | ~addr_it->netmask().toIPv4Address());
executed (the execution status of this line is deduced): bcast = QHostAddress(bcast.toIPv4Address() | ~addr_it->netmask().toIPv4Address());
-
74 addr_it->setBroadcast(bcast);
executed (the execution status of this line is deduced): addr_it->setBroadcast(bcast);
-
75 }
executed: }
Execution Count:163
163
76 }
executed: }
Execution Count:652
652
77 }
executed: }
Execution Count:815
815
78 -
79 return list;
executed: return list;
Execution Count:163
163
80} -
81 -
82Q_GLOBAL_STATIC(QNetworkInterfaceManager, manager)
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:163
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:14
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:149
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:14
no
Evaluation Count:0
0-163
83 -
84QNetworkInterfaceManager::QNetworkInterfaceManager() -
85{ -
86} -
87 -
88QNetworkInterfaceManager::~QNetworkInterfaceManager() -
89{ -
90} -
91 -
92QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interfaceFromName(const QString &name) -
93{ -
94 QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();
executed (the execution status of this line is deduced): QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();
-
95 QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();
executed (the execution status of this line is deduced): QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();
-
96 for ( ; it != interfaceList.constEnd(); ++it)
evaluated: it != interfaceList.constEnd()
TRUEFALSE
yes
Evaluation Count:218
yes
Evaluation Count:1
1-218
97 if ((*it)->name == name)
evaluated: (*it)->name == name
TRUEFALSE
yes
Evaluation Count:59
yes
Evaluation Count:159
59-159
98 return *it;
executed: return *it;
Execution Count:59
59
99 -
100 return empty;
executed: return empty;
Execution Count:1
1
101} -
102 -
103QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interfaceFromIndex(int index) -
104{ -
105 QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();
executed (the execution status of this line is deduced): QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces();
-
106 QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();
executed (the execution status of this line is deduced): QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin();
-
107 for ( ; it != interfaceList.constEnd(); ++it)
evaluated: it != interfaceList.constEnd()
TRUEFALSE
yes
Evaluation Count:82
yes
Evaluation Count:14
14-82
108 if ((*it)->index == index)
evaluated: (*it)->index == index
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:78
4-78
109 return *it;
executed: return *it;
Execution Count:4
4
110 -
111 return empty;
executed: return empty;
Execution Count:14
14
112} -
113 -
114QList<QSharedDataPointer<QNetworkInterfacePrivate> > QNetworkInterfaceManager::allInterfaces() -
115{ -
116 QList<QNetworkInterfacePrivate *> list = postProcess(scan());
executed (the execution status of this line is deduced): QList<QNetworkInterfacePrivate *> list = postProcess(scan());
-
117 QList<QSharedDataPointer<QNetworkInterfacePrivate> > result;
executed (the execution status of this line is deduced): QList<QSharedDataPointer<QNetworkInterfacePrivate> > result;
-
118 -
119 foreach (QNetworkInterfacePrivate *ptr, list)
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(list)> _container_(list); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QNetworkInterfacePrivate *ptr = *_container_.i;; __extension__ ({--_container_.brk; break;}))
-
120 result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr);
executed: result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr);
Execution Count:815
815
121 -
122 return result;
executed: return result;
Execution Count:163
163
123} -
124 -
125QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data) -
126{ -
127 QString result;
executed (the execution status of this line is deduced): QString result;
-
128 for (int i = 0; i < len; ++i) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:4890
yes
Evaluation Count:815
815-4890
129 if (i)
evaluated: i
TRUEFALSE
yes
Evaluation Count:4075
yes
Evaluation Count:815
815-4075
130 result += QLatin1Char(':');
executed: result += QLatin1Char(':');
Execution Count:4075
4075
131 -
132 char buf[3];
executed (the execution status of this line is deduced): char buf[3];
-
133#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && defined(_MSC_VER) && _MSC_VER >= 1400 -
134 sprintf_s(buf, 3, "%02hX", ushort(data[i])); -
135#else -
136 sprintf(buf, "%02hX", ushort(data[i]));
executed (the execution status of this line is deduced): sprintf(buf, "%02hX", ushort(data[i]));
-
137#endif -
138 result += QLatin1String(buf);
executed (the execution status of this line is deduced): result += QLatin1String(buf);
-
139 }
executed: }
Execution Count:4890
4890
140 return result;
executed: return result;
Execution Count:815
815
141} -
142 -
143/*! -
144 \class QNetworkAddressEntry -
145 \brief The QNetworkAddressEntry class stores one IP address -
146 supported by a network interface, along with its associated -
147 netmask and broadcast address. -
148 -
149 \since 4.2 -
150 \reentrant -
151 \ingroup network -
152 \ingroup shared -
153 \inmodule QtNetwork -
154 -
155 Each network interface can contain zero or more IP addresses, which -
156 in turn can be associated with a netmask and/or a broadcast -
157 address (depending on support from the operating system). -
158 -
159 This class represents one such group. -
160*/ -
161 -
162/*! -
163 Constructs an empty QNetworkAddressEntry object. -
164*/ -
165QNetworkAddressEntry::QNetworkAddressEntry() -
166 : d(new QNetworkAddressEntryPrivate) -
167{ -
168}
executed: }
Execution Count:2143
2143
169 -
170/*! -
171 Constructs a QNetworkAddressEntry object that is a copy of the -
172 object \a other. -
173*/ -
174QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other) -
175 : d(new QNetworkAddressEntryPrivate(*other.d.data())) -
176{ -
177}
executed: }
Execution Count:1336
1336
178 -
179/*! -
180 Makes a copy of the QNetworkAddressEntry object \a other. -
181*/ -
182QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry &other) -
183{ -
184 *d.data() = *other.d.data();
executed (the execution status of this line is deduced): *d.data() = *other.d.data();
-
185 return *this;
executed: return *this;
Execution Count:1
1
186} -
187 -
188/*! -
189 \fn void QNetworkAddressEntry::swap(QNetworkAddressEntry &other) -
190 \since 5.0 -
191 -
192 Swaps this network address entry instance with \a other. This -
193 function is very fast and never fails. -
194*/ -
195 -
196/*! -
197 Destroys this QNetworkAddressEntry object. -
198*/ -
199QNetworkAddressEntry::~QNetworkAddressEntry() -
200{ -
201} -
202 -
203/*! -
204 Returns true if this network address entry is the same as \a -
205 other. -
206*/ -
207bool QNetworkAddressEntry::operator==(const QNetworkAddressEntry &other) const -
208{ -
209 if (d == other.d) return true;
executed: return true;
Execution Count:1
evaluated: d == other.d
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
210 if (!d || !other.d) return false;
never executed: return false;
partially evaluated: !d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
partially evaluated: !other.d
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
211 return d->address == other.d->address &&
executed: return d->address == other.d->address && d->netmask == other.d->netmask && d->broadcast == other.d->broadcast;
Execution Count:4
4
212 d->netmask == other.d->netmask &&
executed: return d->address == other.d->address && d->netmask == other.d->netmask && d->broadcast == other.d->broadcast;
Execution Count:4
4
213 d->broadcast == other.d->broadcast;
executed: return d->address == other.d->address && d->netmask == other.d->netmask && d->broadcast == other.d->broadcast;
Execution Count:4
4
214} -
215 -
216/*! -
217 \fn bool QNetworkAddressEntry::operator!=(const QNetworkAddressEntry &other) const -
218 -
219 Returns true if this network address entry is different from \a -
220 other. -
221*/ -
222 -
223/*! -
224 This function returns one IPv4 or IPv6 address found, that was -
225 found in a network interface. -
226*/ -
227QHostAddress QNetworkAddressEntry::ip() const -
228{ -
229 return d->address;
executed: return d->address;
Execution Count:5103
5103
230} -
231 -
232/*! -
233 Sets the IP address the QNetworkAddressEntry object contains to \a -
234 newIp. -
235*/ -
236void QNetworkAddressEntry::setIp(const QHostAddress &newIp) -
237{ -
238 d->address = newIp;
executed (the execution status of this line is deduced): d->address = newIp;
-
239}
executed: }
Execution Count:2144
2144
240 -
241/*! -
242 Returns the netmask associated with the IP address. The -
243 netmask is expressed in the form of an IP address, such as -
244 255.255.0.0. -
245 -
246 For IPv6 addresses, the prefix length is converted to an address -
247 where the number of bits set to 1 is equal to the prefix -
248 length. For a prefix length of 64 bits (the most common value), -
249 the netmask will be expressed as a QHostAddress holding the -
250 address FFFF:FFFF:FFFF:FFFF:: -
251 -
252 \sa prefixLength() -
253*/ -
254QHostAddress QNetworkAddressEntry::netmask() const -
255{ -
256 return d->netmask;
executed: return d->netmask;
Execution Count:976
976
257} -
258 -
259/*! -
260 Sets the netmask that this QNetworkAddressEntry object contains to -
261 \a newNetmask. Setting the netmask also sets the prefix length to -
262 match the new netmask. -
263 -
264 \sa setPrefixLength() -
265*/ -
266void QNetworkAddressEntry::setNetmask(const QHostAddress &newNetmask) -
267{ -
268 if (newNetmask.protocol() != ip().protocol()) {
evaluated: newNetmask.protocol() != ip().protocol()
TRUEFALSE
yes
Evaluation Count:42
yes
Evaluation Count:1324
42-1324
269 d->netmask = QNetmaskAddress();
executed (the execution status of this line is deduced): d->netmask = QNetmaskAddress();
-
270 return;
executed: return;
Execution Count:42
42
271 } -
272 -
273 d->netmask.setAddress(newNetmask);
executed (the execution status of this line is deduced): d->netmask.setAddress(newNetmask);
-
274}
executed: }
Execution Count:1324
1324
275 -
276/*! -
277 \since 4.5 -
278 Returns the prefix length of this IP address. The prefix length -
279 matches the number of bits set to 1 in the netmask (see -
280 netmask()). For IPv4 addresses, the value is between 0 and 32. For -
281 IPv6 addresses, it's contained between 0 and 128 and is the -
282 preferred form of representing addresses. -
283 -
284 This function returns -1 if the prefix length could not be -
285 determined (i.e., netmask() returns a null QHostAddress()). -
286 -
287 \sa netmask() -
288*/ -
289int QNetworkAddressEntry::prefixLength() const -
290{ -
291 return d->netmask.prefixLength();
executed: return d->netmask.prefixLength();
Execution Count:109
109
292} -
293 -
294/*! -
295 \since 4.5 -
296 Sets the prefix length of this IP address to \a length. The value -
297 of \a length must be valid for this type of IP address: between 0 -
298 and 32 for IPv4 addresses, between 0 and 128 for IPv6 -
299 addresses. Setting to any invalid value is equivalent to setting -
300 to -1, which means "no prefix length". -
301 -
302 Setting the prefix length also sets the netmask (see netmask()). -
303 -
304 \sa setNetmask() -
305*/ -
306void QNetworkAddressEntry::setPrefixLength(int length) -
307{ -
308 d->netmask.setPrefixLength(d->address.protocol(), length);
executed (the execution status of this line is deduced): d->netmask.setPrefixLength(d->address.protocol(), length);
-
309}
executed: }
Execution Count:60
60
310 -
311/*! -
312 Returns the broadcast address associated with the IPv4 -
313 address and netmask. It can usually be derived from those two by -
314 setting to 1 the bits of the IP address where the netmask contains -
315 a 0. (In other words, by bitwise-OR'ing the IP address with the -
316 inverse of the netmask) -
317 -
318 This member is always empty for IPv6 addresses, since the concept -
319 of broadcast has been abandoned in that system in favor of -
320 multicast. In particular, the group of hosts corresponding to all -
321 the nodes in the local network can be reached by the "all-nodes" -
322 special multicast group (address FF02::1). -
323*/ -
324QHostAddress QNetworkAddressEntry::broadcast() const -
325{ -
326 return d->broadcast;
executed: return d->broadcast;
Execution Count:693
693
327} -
328 -
329/*! -
330 Sets the broadcast IP address of this QNetworkAddressEntry object -
331 to \a newBroadcast. -
332*/ -
333void QNetworkAddressEntry::setBroadcast(const QHostAddress &newBroadcast) -
334{ -
335 d->broadcast = newBroadcast;
executed (the execution status of this line is deduced): d->broadcast = newBroadcast;
-
336}
executed: }
Execution Count:1144
1144
337 -
338/*! -
339 \class QNetworkInterface -
340 \brief The QNetworkInterface class provides a listing of the host's IP -
341 addresses and network interfaces. -
342 -
343 \since 4.2 -
344 \reentrant -
345 \ingroup network -
346 \ingroup shared -
347 \inmodule QtNetwork -
348 -
349 QNetworkInterface represents one network interface attached to the -
350 host where the program is being run. Each network interface may -
351 contain zero or more IP addresses, each of which is optionally -
352 associated with a netmask and/or a broadcast address. The list of -
353 such trios can be obtained with addressEntries(). Alternatively, -
354 when the netmask or the broadcast addresses aren't necessary, use -
355 the allAddresses() convenience function to obtain just the IP -
356 addresses. -
357 -
358 QNetworkInterface also reports the interface's hardware address with -
359 hardwareAddress(). -
360 -
361 Not all operating systems support reporting all features. Only the -
362 IPv4 addresses are guaranteed to be listed by this class in all -
363 platforms. In particular, IPv6 address listing is only supported -
364 on Windows XP and more recent versions, Linux, MacOS X and the -
365 BSDs. -
366 -
367 \sa QNetworkAddressEntry -
368*/ -
369 -
370/*! -
371 \enum QNetworkInterface::InterfaceFlag -
372 Specifies the flags associated with this network interface. The -
373 possible values are: -
374 -
375 \value IsUp the network interface is active -
376 \value IsRunning the network interface has resources -
377 allocated -
378 \value CanBroadcast the network interface works in -
379 broadcast mode -
380 \value IsLoopBack the network interface is a loopback -
381 interface: that is, it's a virtual -
382 interface whose destination is the -
383 host computer itself -
384 \value IsPointToPoint the network interface is a -
385 point-to-point interface: that is, -
386 there is one, single other address -
387 that can be directly reached by it. -
388 \value CanMulticast the network interface supports -
389 multicasting -
390 -
391 Note that one network interface cannot be both broadcast-based and -
392 point-to-point. -
393*/ -
394 -
395/*! -
396 Constructs an empty network interface object. -
397*/ -
398QNetworkInterface::QNetworkInterface() -
399 : d(0) -
400{ -
401}
executed: }
Execution Count:501
501
402 -
403/*! -
404 Frees the resources associated with the QNetworkInterface object. -
405*/ -
406QNetworkInterface::~QNetworkInterface() -
407{ -
408} -
409 -
410/*! -
411 Creates a copy of the QNetworkInterface object contained in \a -
412 other. -
413*/ -
414QNetworkInterface::QNetworkInterface(const QNetworkInterface &other) -
415 : d(other.d) -
416{ -
417}
executed: }
Execution Count:773
773
418 -
419/*! -
420 Copies the contents of the QNetworkInterface object contained in \a -
421 other into this one. -
422*/ -
423QNetworkInterface &QNetworkInterface::operator=(const QNetworkInterface &other) -
424{ -
425 d = other.d;
never executed (the execution status of this line is deduced): d = other.d;
-
426 return *this;
never executed: return *this;
0
427} -
428 -
429/*! -
430 \fn void QNetworkInterface::swap(QNetworkInterface &other) -
431 \since 5.0 -
432 -
433 Swaps this network interface instance with \a other. This function -
434 is very fast and never fails. -
435*/ -
436 -
437/*! -
438 Returns true if this QNetworkInterface object contains valid -
439 information about a network interface. -
440*/ -
441bool QNetworkInterface::isValid() const -
442{ -
443 return !name().isEmpty();
executed: return !name().isEmpty();
Execution Count:397
397
444} -
445 -
446/*! -
447 \since 4.5 -
448 Returns the interface system index, if known. This is an integer -
449 assigned by the operating system to identify this interface and it -
450 generally doesn't change. It matches the scope ID field in IPv6 -
451 addresses. -
452 -
453 If the index isn't known, this function returns 0. -
454*/ -
455int QNetworkInterface::index() const -
456{ -
457 return d ? d->index : 0;
executed: return d ? d->index : 0;
Execution Count:573
573
458} -
459 -
460/*! -
461 Returns the name of this network interface. On Unix systems, this -
462 is a string containing the type of the interface and optionally a -
463 sequence number, such as "eth0", "lo" or "pcn0". On Windows, it's -
464 an internal ID that cannot be changed by the user. -
465*/ -
466QString QNetworkInterface::name() const -
467{ -
468 return d ? d->name : QString();
executed: return d ? d->name : QString();
Execution Count:1110
1110
469} -
470 -
471/*! -
472 \since 4.5 -
473 -
474 Returns the human-readable name of this network interface on -
475 Windows, such as "Local Area Connection", if the name could be -
476 determined. If it couldn't, this function returns the same as -
477 name(). The human-readable name is a name that the user can modify -
478 in the Windows Control Panel, so it may change during the -
479 execution of the program. -
480 -
481 On Unix, this function currently always returns the same as -
482 name(), since Unix systems don't store a configuration for -
483 human-readable names. -
484*/ -
485QString QNetworkInterface::humanReadableName() const -
486{ -
487 return d ? !d->friendlyName.isEmpty() ? d->friendlyName : name() : QString();
executed: return d ? !d->friendlyName.isEmpty() ? d->friendlyName : name() : QString();
Execution Count:290
290
488} -
489 -
490/*! -
491 Returns the flags associated with this network interface. -
492*/ -
493QNetworkInterface::InterfaceFlags QNetworkInterface::flags() const -
494{ -
495 return d ? d->flags : InterfaceFlags(0);
executed: return d ? d->flags : InterfaceFlags(0);
Execution Count:667
667
496} -
497 -
498/*! -
499 Returns the low-level hardware address for this interface. On -
500 Ethernet interfaces, this will be a MAC address in string -
501 representation, separated by colons. -
502 -
503 Other interface types may have other types of hardware -
504 addresses. Implementations should not depend on this function -
505 returning a valid MAC address. -
506*/ -
507QString QNetworkInterface::hardwareAddress() const -
508{ -
509 return d ? d->hardwareAddress : QString();
executed: return d ? d->hardwareAddress : QString();
Execution Count:24
24
510} -
511 -
512/*! -
513 Returns the list of IP addresses that this interface possesses -
514 along with their associated netmasks and broadcast addresses. -
515 -
516 If the netmask or broadcast address information is not necessary, -
517 you can call the allAddresses() function to obtain just the IP -
518 addresses. -
519*/ -
520QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const -
521{ -
522 return d ? d->addressEntries : QList<QNetworkAddressEntry>();
executed: return d ? d->addressEntries : QList<QNetworkAddressEntry>();
Execution Count:263
263
523} -
524 -
525/*! -
526 Returns a QNetworkInterface object for the interface named \a -
527 name. If no such interface exists, this function returns an -
528 invalid QNetworkInterface object. -
529 -
530 \sa name(), isValid() -
531*/ -
532QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name) -
533{ -
534 QNetworkInterface result;
executed (the execution status of this line is deduced): QNetworkInterface result;
-
535 result.d = manager()->interfaceFromName(name);
executed (the execution status of this line is deduced): result.d = manager()->interfaceFromName(name);
-
536 return result;
executed: return result;
Execution Count:60
60
537} -
538 -
539/*! -
540 Returns a QNetworkInterface object for the interface whose internal -
541 ID is \a index. Network interfaces have a unique identifier called -
542 the "interface index" to distinguish it from other interfaces on -
543 the system. Often, this value is assigned progressively and -
544 interfaces being removed and then added again get a different -
545 value every time. -
546 -
547 This index is also found in the IPv6 address' scope ID field. -
548*/ -
549QNetworkInterface QNetworkInterface::interfaceFromIndex(int index) -
550{ -
551 QNetworkInterface result;
executed (the execution status of this line is deduced): QNetworkInterface result;
-
552 result.d = manager()->interfaceFromIndex(index);
executed (the execution status of this line is deduced): result.d = manager()->interfaceFromIndex(index);
-
553 return result;
executed: return result;
Execution Count:18
18
554} -
555 -
556/*! -
557 Returns a listing of all the network interfaces found on the host -
558 machine. -
559*/ -
560QList<QNetworkInterface> QNetworkInterface::allInterfaces() -
561{ -
562 QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
executed (the execution status of this line is deduced): QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
-
563 QList<QNetworkInterface> result;
executed (the execution status of this line is deduced): QList<QNetworkInterface> result;
-
564 foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(privs)> _container_(privs); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QSharedDataPointer<QNetworkInterfacePrivate> &p = *_container_.i;; __extension__ ({--_container_.brk; break;})) {
-
565 QNetworkInterface item;
executed (the execution status of this line is deduced): QNetworkInterface item;
-
566 item.d = p;
executed (the execution status of this line is deduced): item.d = p;
-
567 result << item;
executed (the execution status of this line is deduced): result << item;
-
568 }
executed: }
Execution Count:395
395
569 -
570 return result;
executed: return result;
Execution Count:79
79
571} -
572 -
573/*! -
574 This convenience function returns all IP addresses found on the -
575 host machine. It is equivalent to calling addressEntries() on all the -
576 objects returned by allInterfaces() to obtain lists of QHostAddress -
577 objects then calling QHostAddress::ip() on each of these. -
578*/ -
579QList<QHostAddress> QNetworkInterface::allAddresses() -
580{ -
581 QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
executed (the execution status of this line is deduced): QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces();
-
582 QList<QHostAddress> result;
executed (the execution status of this line is deduced): QList<QHostAddress> result;
-
583 foreach (const QSharedDataPointer<QNetworkInterfacePrivate> &p, privs) {
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(privs)> _container_(privs); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QSharedDataPointer<QNetworkInterfacePrivate> &p = *_container_.i;; __extension__ ({--_container_.brk; break;})) {
-
584 foreach (const QNetworkAddressEntry &entry, p->addressEntries)
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(p->addressEntries)> _container_(p->addressEntries); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkAddressEntry &entry = *_container_.i;; __extension__ ({--_container_.brk; break;}))
-
585 result += entry.ip();
executed: result += entry.ip();
Execution Count:48
48
586 }
executed: }
Execution Count:30
30
587 -
588 return result;
executed: return result;
Execution Count:6
6
589} -
590 -
591#ifndef QT_NO_DEBUG_STREAM -
592static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags) -
593{ -
594 if (flags & QNetworkInterface::IsUp)
never evaluated: flags & QNetworkInterface::IsUp
0
595 debug.nospace() << "IsUp ";
never executed: debug.nospace() << "IsUp ";
0
596 if (flags & QNetworkInterface::IsRunning)
never evaluated: flags & QNetworkInterface::IsRunning
0
597 debug.nospace() << "IsRunning ";
never executed: debug.nospace() << "IsRunning ";
0
598 if (flags & QNetworkInterface::CanBroadcast)
never evaluated: flags & QNetworkInterface::CanBroadcast
0
599 debug.nospace() << "CanBroadcast ";
never executed: debug.nospace() << "CanBroadcast ";
0
600 if (flags & QNetworkInterface::IsLoopBack)
never evaluated: flags & QNetworkInterface::IsLoopBack
0
601 debug.nospace() << "IsLoopBack ";
never executed: debug.nospace() << "IsLoopBack ";
0
602 if (flags & QNetworkInterface::IsPointToPoint)
never evaluated: flags & QNetworkInterface::IsPointToPoint
0
603 debug.nospace() << "IsPointToPoint ";
never executed: debug.nospace() << "IsPointToPoint ";
0
604 if (flags & QNetworkInterface::CanMulticast)
never evaluated: flags & QNetworkInterface::CanMulticast
0
605 debug.nospace() << "CanMulticast ";
never executed: debug.nospace() << "CanMulticast ";
0
606 return debug.nospace();
never executed: return debug.nospace();
0
607} -
608 -
609static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry) -
610{ -
611 debug.nospace() << "(address = " << entry.ip();
never executed (the execution status of this line is deduced): debug.nospace() << "(address = " << entry.ip();
-
612 if (!entry.netmask().isNull())
never evaluated: !entry.netmask().isNull()
0
613 debug.nospace() << ", netmask = " << entry.netmask();
never executed: debug.nospace() << ", netmask = " << entry.netmask();
0
614 if (!entry.broadcast().isNull())
never evaluated: !entry.broadcast().isNull()
0
615 debug.nospace() << ", broadcast = " << entry.broadcast();
never executed: debug.nospace() << ", broadcast = " << entry.broadcast();
0
616 debug.nospace() << ')';
never executed (the execution status of this line is deduced): debug.nospace() << ')';
-
617 return debug.space();
never executed: return debug.space();
0
618} -
619 -
620QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface) -
621{ -
622 debug.nospace() << "QNetworkInterface(name = " << networkInterface.name()
never executed (the execution status of this line is deduced): debug.nospace() << "QNetworkInterface(name = " << networkInterface.name()
-
623 << ", hardware address = " << networkInterface.hardwareAddress()
never executed (the execution status of this line is deduced): << ", hardware address = " << networkInterface.hardwareAddress()
-
624 << ", flags = ";
never executed (the execution status of this line is deduced): << ", flags = ";
-
625 flagsDebug(debug, networkInterface.flags());
never executed (the execution status of this line is deduced): flagsDebug(debug, networkInterface.flags());
-
626#if defined(Q_CC_RVCT) -
627 // RVCT gets confused with << networkInterface.addressEntries(), reason unknown. -
628 debug.nospace() << ")\n"; -
629#else -
630 debug.nospace() << ", entries = " << networkInterface.addressEntries()
never executed (the execution status of this line is deduced): debug.nospace() << ", entries = " << networkInterface.addressEntries()
-
631 << ")\n";
never executed (the execution status of this line is deduced): << ")\n";
-
632#endif -
633 return debug.space();
never executed: return debug.space();
0
634} -
635#endif -
636 -
637QT_END_NAMESPACE -
638 -
639#endif // QT_NO_NETWORKINTERFACE -
640 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial