kernel/qnetworkinterface.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
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) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:815
yes
Evaluation Count:163
163-815
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) {
evaluated: addr_it != addr_end
TRUEFALSE
yes
Evaluation Count:1304
yes
Evaluation Count:815
815-1304
15 if (addr_it->ip().protocol() != QAbstractSocket::IPv4Protocol)
evaluated: addr_it->ip().protocol() != QAbstractSocket::IPv4Protocol
TRUEFALSE
yes
Evaluation Count:652
yes
Evaluation Count:652
652
16 continue;
executed: continue;
Execution Count:652
652
17 -
18 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
19 QHostAddress bcast = addr_it->ip(); -
20 bcast = QHostAddress(bcast.toIPv4Address() | ~addr_it->netmask().toIPv4Address()); -
21 addr_it->setBroadcast(bcast); -
22 }
executed: }
Execution Count:163
163
23 }
executed: }
Execution Count:652
652
24 }
executed: }
Execution Count:815
815
25 -
26 return list;
executed: return list;
Execution Count:163
163
27} -
28 -
29static QNetworkInterfaceManager *manager() { static QGlobalStatic<QNetworkInterfaceManager > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QNetworkInterfaceManager *x = new QNetworkInterfaceManager; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QNetworkInterfaceManager > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
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
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 for ( ; it != interfaceList.constEnd(); ++it)
evaluated: it != interfaceList.constEnd()
TRUEFALSE
yes
Evaluation Count:218
yes
Evaluation Count:1
1-218
44 if ((*it)->name == name)
evaluated: (*it)->name == name
TRUEFALSE
yes
Evaluation Count:59
yes
Evaluation Count:159
59-159
45 return *it;
executed: return *it;
Execution Count:59
59
46 -
47 return empty;
executed: return empty;
Execution Count:1
1
48} -
49 -
50QSharedDataPointer<QNetworkInterfacePrivate> QNetworkInterfaceManager::interfaceFromIndex(int index) -
51{ -
52 QList<QSharedDataPointer<QNetworkInterfacePrivate> > interfaceList = allInterfaces(); -
53 QList<QSharedDataPointer<QNetworkInterfacePrivate> >::ConstIterator it = interfaceList.constBegin(); -
54 for ( ; it != interfaceList.constEnd(); ++it)
evaluated: it != interfaceList.constEnd()
TRUEFALSE
yes
Evaluation Count:82
yes
Evaluation Count:14
14-82
55 if ((*it)->index == index)
evaluated: (*it)->index == index
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:78
4-78
56 return *it;
executed: return *it;
Execution Count:4
4
57 -
58 return empty;
executed: return empty;
Execution Count:14
14
59} -
60 -
61QList<QSharedDataPointer<QNetworkInterfacePrivate> > QNetworkInterfaceManager::allInterfaces() -
62{ -
63 QList<QNetworkInterfacePrivate *> list = postProcess(scan()); -
64 QList<QSharedDataPointer<QNetworkInterfacePrivate> > result; -
65 -
66 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;})) -
67 result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr);
executed: result << QSharedDataPointer<QNetworkInterfacePrivate>(ptr);
Execution Count:815
815
68 -
69 return result;
executed: return result;
Execution Count:163
163
70} -
71 -
72QString QNetworkInterfacePrivate::makeHwAddress(int len, uchar *data) -
73{ -
74 QString result; -
75 for (int i = 0; i < len; ++i) {
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:4890
yes
Evaluation Count:815
815-4890
76 if (i)
evaluated: i
TRUEFALSE
yes
Evaluation Count:4075
yes
Evaluation Count:815
815-4075
77 result += QLatin1Char(':');
executed: result += QLatin1Char(':');
Execution Count:4075
4075
78 -
79 char buf[3]; -
80 -
81 -
82 -
83 sprintf(buf, "%02hX", ushort(data[i])); -
84 -
85 result += QLatin1String(buf); -
86 }
executed: }
Execution Count:4890
4890
87 return result;
executed: return result;
Execution Count:815
815
88} -
89QNetworkAddressEntry::QNetworkAddressEntry() -
90 : d(new QNetworkAddressEntryPrivate) -
91{ -
92}
executed: }
Execution Count:2143
2143
93 -
94 -
95 -
96 -
97 -
98QNetworkAddressEntry::QNetworkAddressEntry(const QNetworkAddressEntry &other) -
99 : d(new QNetworkAddressEntryPrivate(*other.d.data())) -
100{ -
101}
executed: }
Execution Count:1336
1336
102 -
103 -
104 -
105 -
106QNetworkAddressEntry &QNetworkAddressEntry::operator=(const QNetworkAddressEntry &other) -
107{ -
108 *d.data() = *other.d.data(); -
109 return *this;
executed: return *this;
Execution Count:1
1
110} -
111QNetworkAddressEntry::~QNetworkAddressEntry() -
112{ -
113} -
114 -
115 -
116 -
117 -
118 -
119bool QNetworkAddressEntry::operator==(const QNetworkAddressEntry &other) const -
120{ -
121 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
122 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
123 return d->address == other.d->address && 4
124 d->netmask == other.d->netmask && 4
125 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
126} -
127QHostAddress QNetworkAddressEntry::ip() const -
128{ -
129 return d->address;
executed: return d->address;
Execution Count:5103
5103
130} -
131 -
132 -
133 -
134 -
135 -
136void QNetworkAddressEntry::setIp(const QHostAddress &newIp) -
137{ -
138 d->address = newIp; -
139}
executed: }
Execution Count:2144
2144
140QHostAddress QNetworkAddressEntry::netmask() const -
141{ -
142 return d->netmask;
executed: return d->netmask;
Execution Count:976
976
143} -
144void QNetworkAddressEntry::setNetmask(const QHostAddress &newNetmask) -
145{ -
146 if (newNetmask.protocol() != ip().protocol()) {
evaluated: newNetmask.protocol() != ip().protocol()
TRUEFALSE
yes
Evaluation Count:42
yes
Evaluation Count:1324
42-1324
147 d->netmask = QNetmaskAddress(); -
148 return;
executed: return;
Execution Count:42
42
149 } -
150 -
151 d->netmask.setAddress(newNetmask); -
152}
executed: }
Execution Count:1324
1324
153int QNetworkAddressEntry::prefixLength() const -
154{ -
155 return d->netmask.prefixLength();
executed: return d->netmask.prefixLength();
Execution Count:109
109
156} -
157void QNetworkAddressEntry::setPrefixLength(int length) -
158{ -
159 d->netmask.setPrefixLength(d->address.protocol(), length); -
160}
executed: }
Execution Count:60
60
161QHostAddress QNetworkAddressEntry::broadcast() const -
162{ -
163 return d->broadcast;
executed: return d->broadcast;
Execution Count:693
693
164} -
165 -
166 -
167 -
168 -
169 -
170void QNetworkAddressEntry::setBroadcast(const QHostAddress &newBroadcast) -
171{ -
172 d->broadcast = newBroadcast; -
173}
executed: }
Execution Count:1144
1144
174QNetworkInterface::QNetworkInterface() -
175 : d(0) -
176{ -
177}
executed: }
Execution Count:501
501
178 -
179 -
180 -
181 -
182QNetworkInterface::~QNetworkInterface() -
183{ -
184} -
185 -
186 -
187 -
188 -
189 -
190QNetworkInterface::QNetworkInterface(const QNetworkInterface &other) -
191 : d(other.d) -
192{ -
193}
executed: }
Execution Count:773
773
194 -
195 -
196 -
197 -
198 -
199QNetworkInterface &QNetworkInterface::operator=(const QNetworkInterface &other) -
200{ -
201 d = other.d; -
202 return *this;
never executed: return *this;
0
203} -
204bool QNetworkInterface::isValid() const -
205{ -
206 return !name().isEmpty();
executed: return !name().isEmpty();
Execution Count:397
397
207} -
208int QNetworkInterface::index() const -
209{ -
210 return d ? d->index : 0;
executed: return d ? d->index : 0;
Execution Count:573
573
211} -
212 -
213 -
214 -
215 -
216 -
217 -
218 -
219QString QNetworkInterface::name() const -
220{ -
221 return d ? d->name : QString();
executed: return d ? d->name : QString();
Execution Count:1110
1110
222} -
223QString QNetworkInterface::humanReadableName() const -
224{ -
225 return d ? !d->friendlyName.isEmpty() ? d->friendlyName : name() : QString();
executed: return d ? !d->friendlyName.isEmpty() ? d->friendlyName : name() : QString();
Execution Count:290
290
226} -
227 -
228 -
229 -
230 -
231QNetworkInterface::InterfaceFlags QNetworkInterface::flags() const -
232{ -
233 return d ? d->flags : InterfaceFlags(0);
executed: return d ? d->flags : InterfaceFlags(0);
Execution Count:667
667
234} -
235QString QNetworkInterface::hardwareAddress() const -
236{ -
237 return d ? d->hardwareAddress : QString();
executed: return d ? d->hardwareAddress : QString();
Execution Count:24
24
238} -
239QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const -
240{ -
241 return d ? d->addressEntries : QList<QNetworkAddressEntry>();
executed: return d ? d->addressEntries : QList<QNetworkAddressEntry>();
Execution Count:263
263
242} -
243QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name) -
244{ -
245 QNetworkInterface result; -
246 result.d = manager()->interfaceFromName(name); -
247 return result;
executed: return result;
Execution Count:60
60
248} -
249QNetworkInterface QNetworkInterface::interfaceFromIndex(int index) -
250{ -
251 QNetworkInterface result; -
252 result.d = manager()->interfaceFromIndex(index); -
253 return result;
executed: return result;
Execution Count:18
18
254} -
255 -
256 -
257 -
258 -
259 -
260QList<QNetworkInterface> QNetworkInterface::allInterfaces() -
261{ -
262 QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces(); -
263 QList<QNetworkInterface> result; -
264 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;})) { -
265 QNetworkInterface item; -
266 item.d = p; -
267 result << item; -
268 }
executed: }
Execution Count:395
395
269 -
270 return result;
executed: return result;
Execution Count:79
79
271} -
272 -
273 -
274 -
275 -
276 -
277 -
278 -
279QList<QHostAddress> QNetworkInterface::allAddresses() -
280{ -
281 QList<QSharedDataPointer<QNetworkInterfacePrivate> > privs = manager()->allInterfaces(); -
282 QList<QHostAddress> result; -
283 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;})) { -
284 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;})) -
285 result += entry.ip();
executed: result += entry.ip();
Execution Count:48
48
286 }
executed: }
Execution Count:30
30
287 -
288 return result;
executed: return result;
Execution Count:6
6
289} -
290 -
291 -
292static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags) -
293{ -
294 if (flags & QNetworkInterface::IsUp)
never evaluated: flags & QNetworkInterface::IsUp
0
295 debug.nospace() << "IsUp ";
never executed: debug.nospace() << "IsUp ";
0
296 if (flags & QNetworkInterface::IsRunning)
never evaluated: flags & QNetworkInterface::IsRunning
0
297 debug.nospace() << "IsRunning ";
never executed: debug.nospace() << "IsRunning ";
0
298 if (flags & QNetworkInterface::CanBroadcast)
never evaluated: flags & QNetworkInterface::CanBroadcast
0
299 debug.nospace() << "CanBroadcast ";
never executed: debug.nospace() << "CanBroadcast ";
0
300 if (flags & QNetworkInterface::IsLoopBack)
never evaluated: flags & QNetworkInterface::IsLoopBack
0
301 debug.nospace() << "IsLoopBack ";
never executed: debug.nospace() << "IsLoopBack ";
0
302 if (flags & QNetworkInterface::IsPointToPoint)
never evaluated: flags & QNetworkInterface::IsPointToPoint
0
303 debug.nospace() << "IsPointToPoint ";
never executed: debug.nospace() << "IsPointToPoint ";
0
304 if (flags & QNetworkInterface::CanMulticast)
never evaluated: flags & QNetworkInterface::CanMulticast
0
305 debug.nospace() << "CanMulticast ";
never executed: debug.nospace() << "CanMulticast ";
0
306 return debug.nospace();
never executed: return debug.nospace();
0
307} -
308 -
309static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry) -
310{ -
311 debug.nospace() << "(address = " << entry.ip(); -
312 if (!entry.netmask().isNull())
never evaluated: !entry.netmask().isNull()
0
313 debug.nospace() << ", netmask = " << entry.netmask();
never executed: debug.nospace() << ", netmask = " << entry.netmask();
0
314 if (!entry.broadcast().isNull())
never evaluated: !entry.broadcast().isNull()
0
315 debug.nospace() << ", broadcast = " << entry.broadcast();
never executed: debug.nospace() << ", broadcast = " << entry.broadcast();
0
316 debug.nospace() << ')'; -
317 return debug.space();
never executed: return debug.space();
0
318} -
319 -
320QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface) -
321{ -
322 debug.nospace() << "QNetworkInterface(name = " << networkInterface.name() -
323 << ", hardware address = " << networkInterface.hardwareAddress() -
324 << ", flags = "; -
325 flagsDebug(debug, networkInterface.flags()); -
326 -
327 -
328 -
329 -
330 debug.nospace() << ", entries = " << networkInterface.addressEntries() -
331 << ")\n"; -
332 -
333 return debug.space();
never executed: return debug.space();
0
334} -
335 -
336 -
337 -
338 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial