Line | Source Code | Coverage |
---|
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 "qhostaddress.h" | - |
43 | #include "qhostaddress_p.h" | - |
44 | #include "private/qipaddress_p.h" | - |
45 | #include "qdebug.h" | - |
46 | #if defined(Q_OS_WIN) | - |
47 | # include <winsock2.h> | - |
48 | #else | - |
49 | # include <netinet/in.h> | - |
50 | #endif | - |
51 | #include "qplatformdefs.h" | - |
52 | #include "qstringlist.h" | - |
53 | #include "qendian.h" | - |
54 | #ifndef QT_NO_DATASTREAM | - |
55 | #include <qdatastream.h> | - |
56 | #endif | - |
57 | | - |
58 | #ifdef QT_LINUXBASE | - |
59 | # include <arpa/inet.h> | - |
60 | #endif | - |
61 | | - |
62 | QT_BEGIN_NAMESPACE | - |
63 | | - |
64 | #define QT_ENSURE_PARSED(a) \ | - |
65 | do { \ | - |
66 | if (!(a)->d->isParsed) \ | - |
67 | (a)->d->parse(); \ | - |
68 | } while (0) | - |
69 | | - |
70 | #ifdef Q_OS_WIN | - |
71 | // sockaddr_in6 size changed between old and new SDK | - |
72 | // Only the new version is the correct one, so always | - |
73 | // use this structure. | - |
74 | #if defined(Q_OS_WINCE) | - |
75 | # if !defined(u_char) | - |
76 | # define u_char unsigned char | - |
77 | # endif | - |
78 | # if !defined(u_short) | - |
79 | # define u_short unsigned short | - |
80 | # endif | - |
81 | # if !defined(u_long) | - |
82 | # define u_long unsigned long | - |
83 | # endif | - |
84 | #endif | - |
85 | struct qt_in6_addr { | - |
86 | u_char qt_s6_addr[16]; | - |
87 | }; | - |
88 | typedef struct { | - |
89 | short sin6_family; /* AF_INET6 */ | - |
90 | u_short sin6_port; /* Transport level port number */ | - |
91 | u_long sin6_flowinfo; /* IPv6 flow information */ | - |
92 | struct qt_in6_addr sin6_addr; /* IPv6 address */ | - |
93 | u_long sin6_scope_id; /* set of interfaces for a scope */ | - |
94 | } qt_sockaddr_in6; | - |
95 | #else | - |
96 | #define qt_sockaddr_in6 sockaddr_in6 | - |
97 | #define qt_s6_addr s6_addr | - |
98 | #endif | - |
99 | | - |
100 | | - |
101 | class QHostAddressPrivate | - |
102 | { | - |
103 | public: | - |
104 | QHostAddressPrivate(); | - |
105 | | - |
106 | void setAddress(quint32 a_ = 0); | - |
107 | void setAddress(const quint8 *a_); | - |
108 | void setAddress(const Q_IPV6ADDR &a_); | - |
109 | | - |
110 | bool parse(); | - |
111 | void clear(); | - |
112 | | - |
113 | QString ipString; | - |
114 | QString scopeId; | - |
115 | | - |
116 | quint32 a; // IPv4 address | - |
117 | Q_IPV6ADDR a6; // IPv6 address | - |
118 | QAbstractSocket::NetworkLayerProtocol protocol; | - |
119 | | - |
120 | bool isParsed; | - |
121 | | - |
122 | friend class QHostAddress; | - |
123 | }; | - |
124 | | - |
125 | QHostAddressPrivate::QHostAddressPrivate() | - |
126 | : a(0), protocol(QAbstractSocket::UnknownNetworkLayerProtocol), isParsed(true) | - |
127 | { | - |
128 | memset(&a6, 0, sizeof(a6)); executed (the execution status of this line is deduced): memset(&a6, 0, sizeof(a6)); | - |
129 | } executed: } Execution Count:434211 | 434211 |
130 | | - |
131 | void QHostAddressPrivate::setAddress(quint32 a_) | - |
132 | { | - |
133 | a = a_; executed (the execution status of this line is deduced): a = a_; | - |
134 | //create mapped address | - |
135 | memset(&a6, 0, sizeof(a6)); executed (the execution status of this line is deduced): memset(&a6, 0, sizeof(a6)); | - |
136 | int i; executed (the execution status of this line is deduced): int i; | - |
137 | for (i=15; a_ != 0; i--) { evaluated: a_ != 0 yes Evaluation Count:114188 | yes Evaluation Count:29938 |
| 29938-114188 |
138 | a6[i] = a_ & 0xFF; executed (the execution status of this line is deduced): a6[i] = a_ & 0xFF; | - |
139 | a_ >>=8; executed (the execution status of this line is deduced): a_ >>=8; | - |
140 | } executed: } Execution Count:114188 | 114188 |
141 | Q_ASSERT(i >= 11); executed (the execution status of this line is deduced): qt_noop(); | - |
142 | a6[11] = 0xFF; executed (the execution status of this line is deduced): a6[11] = 0xFF; | - |
143 | a6[10] = 0xFF; executed (the execution status of this line is deduced): a6[10] = 0xFF; | - |
144 | protocol = QAbstractSocket::IPv4Protocol; executed (the execution status of this line is deduced): protocol = QAbstractSocket::IPv4Protocol; | - |
145 | isParsed = true; executed (the execution status of this line is deduced): isParsed = true; | - |
146 | } executed: } Execution Count:29938 | 29938 |
147 | | - |
148 | static bool parseMappedAddress(quint32& a, const Q_IPV6ADDR &a6) | - |
149 | { | - |
150 | int i; executed (the execution status of this line is deduced): int i; | - |
151 | for (i=0;i<10;i++) evaluated: i<10 yes Evaluation Count:135222 | yes Evaluation Count:13389 |
| 13389-135222 |
152 | if (a6[i]) return false; executed: return false; Execution Count:1302 evaluated: a6[i] yes Evaluation Count:1302 | yes Evaluation Count:133920 |
| 1302-133920 |
153 | for (;i<12;i++) evaluated: i<12 yes Evaluation Count:20391 | yes Evaluation Count:7002 |
| 7002-20391 |
154 | if (a6[i] != 0xFF) return false; executed: return false; Execution Count:6387 evaluated: a6[i] != 0xFF yes Evaluation Count:6387 | yes Evaluation Count:14004 |
| 6387-14004 |
155 | a=(a6[12] << 24) | (a6[13] << 16) | (a6[14] << 8) | a6[15]; executed (the execution status of this line is deduced): a=(a6[12] << 24) | (a6[13] << 16) | (a6[14] << 8) | a6[15]; | - |
156 | return true; executed: return true; Execution Count:7002 | 7002 |
157 | } | - |
158 | | - |
159 | void QHostAddressPrivate::setAddress(const quint8 *a_) | - |
160 | { | - |
161 | for (int i = 0; i < 16; i++) evaluated: i < 16 yes Evaluation Count:23984 | yes Evaluation Count:1499 |
| 1499-23984 |
162 | a6[i] = a_[i]; executed: a6[i] = a_[i]; Execution Count:23984 | 23984 |
163 | a = 0; executed (the execution status of this line is deduced): a = 0; | - |
164 | if (parseMappedAddress(a, a6)) evaluated: parseMappedAddress(a, a6) yes Evaluation Count:12 | yes Evaluation Count:1487 |
| 12-1487 |
165 | protocol = QAbstractSocket::IPv4Protocol; executed: protocol = QAbstractSocket::IPv4Protocol; Execution Count:12 | 12 |
166 | else | - |
167 | protocol = QAbstractSocket::IPv6Protocol; executed: protocol = QAbstractSocket::IPv6Protocol; Execution Count:1487 | 1487 |
168 | isParsed = true; executed (the execution status of this line is deduced): isParsed = true; | - |
169 | } executed: } Execution Count:1499 | 1499 |
170 | | - |
171 | void QHostAddressPrivate::setAddress(const Q_IPV6ADDR &a_) | - |
172 | { | - |
173 | a6 = a_; executed (the execution status of this line is deduced): a6 = a_; | - |
174 | a = 0; executed (the execution status of this line is deduced): a = 0; | - |
175 | if (parseMappedAddress(a, a6)) evaluated: parseMappedAddress(a, a6) yes Evaluation Count:6990 | yes Evaluation Count:6202 |
| 6202-6990 |
176 | protocol = QAbstractSocket::IPv4Protocol; executed: protocol = QAbstractSocket::IPv4Protocol; Execution Count:6990 | 6990 |
177 | else | - |
178 | protocol = QAbstractSocket::IPv6Protocol; executed: protocol = QAbstractSocket::IPv6Protocol; Execution Count:6202 | 6202 |
179 | isParsed = true; executed (the execution status of this line is deduced): isParsed = true; | - |
180 | } executed: } Execution Count:13192 | 13192 |
181 | | - |
182 | static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId) | - |
183 | { | - |
184 | QString tmp = address; executed (the execution status of this line is deduced): QString tmp = address; | - |
185 | int scopeIdPos = tmp.lastIndexOf(QLatin1Char('%')); executed (the execution status of this line is deduced): int scopeIdPos = tmp.lastIndexOf(QLatin1Char('%')); | - |
186 | if (scopeIdPos != -1) { evaluated: scopeIdPos != -1 yes Evaluation Count:8 | yes Evaluation Count:227 |
| 8-227 |
187 | *scopeId = tmp.mid(scopeIdPos + 1); executed (the execution status of this line is deduced): *scopeId = tmp.mid(scopeIdPos + 1); | - |
188 | tmp.chop(tmp.size() - scopeIdPos); executed (the execution status of this line is deduced): tmp.chop(tmp.size() - scopeIdPos); | - |
189 | } else { executed: } Execution Count:8 | 8 |
190 | scopeId->clear(); executed (the execution status of this line is deduced): scopeId->clear(); | - |
191 | } executed: } Execution Count:227 | 227 |
192 | return QIPAddressUtils::parseIp6(addr, tmp.constBegin(), tmp.constEnd()); executed: return QIPAddressUtils::parseIp6(addr, tmp.constBegin(), tmp.constEnd()); Execution Count:235 | 235 |
193 | } | - |
194 | | - |
195 | bool QHostAddressPrivate::parse() | - |
196 | { | - |
197 | isParsed = true; executed (the execution status of this line is deduced): isParsed = true; | - |
198 | protocol = QAbstractSocket::UnknownNetworkLayerProtocol; executed (the execution status of this line is deduced): protocol = QAbstractSocket::UnknownNetworkLayerProtocol; | - |
199 | QString a = ipString.simplified(); executed (the execution status of this line is deduced): QString a = ipString.simplified(); | - |
200 | if (a.isEmpty()) evaluated: a.isEmpty() yes Evaluation Count:1509 | yes Evaluation Count:4875 |
| 1509-4875 |
201 | return false; executed: return false; Execution Count:1509 | 1509 |
202 | | - |
203 | // All IPv6 addresses contain a ':', and may contain a '.'. | - |
204 | if (a.contains(QLatin1Char(':'))) { evaluated: a.contains(QLatin1Char(':')) yes Evaluation Count:235 | yes Evaluation Count:4640 |
| 235-4640 |
205 | quint8 maybeIp6[16]; executed (the execution status of this line is deduced): quint8 maybeIp6[16]; | - |
206 | if (parseIp6(a, maybeIp6, &scopeId)) { evaluated: parseIp6(a, maybeIp6, &scopeId) yes Evaluation Count:192 | yes Evaluation Count:43 |
| 43-192 |
207 | setAddress(maybeIp6); executed (the execution status of this line is deduced): setAddress(maybeIp6); | - |
208 | protocol = QAbstractSocket::IPv6Protocol; executed (the execution status of this line is deduced): protocol = QAbstractSocket::IPv6Protocol; | - |
209 | return true; executed: return true; Execution Count:192 | 192 |
210 | } | - |
211 | } executed: } Execution Count:43 | 43 |
212 | | - |
213 | quint32 maybeIp4 = 0; executed (the execution status of this line is deduced): quint32 maybeIp4 = 0; | - |
214 | if (QIPAddressUtils::parseIp4(maybeIp4, a.constBegin(), a.constEnd())) { evaluated: QIPAddressUtils::parseIp4(maybeIp4, a.constBegin(), a.constEnd()) yes Evaluation Count:1096 | yes Evaluation Count:3586 |
| 1096-3586 |
215 | setAddress(maybeIp4); executed (the execution status of this line is deduced): setAddress(maybeIp4); | - |
216 | protocol = QAbstractSocket::IPv4Protocol; executed (the execution status of this line is deduced): protocol = QAbstractSocket::IPv4Protocol; | - |
217 | return true; executed: return true; Execution Count:1096 | 1096 |
218 | } | - |
219 | | - |
220 | return false; executed: return false; Execution Count:3586 | 3586 |
221 | } | - |
222 | | - |
223 | void QHostAddressPrivate::clear() | - |
224 | { | - |
225 | a = 0; executed (the execution status of this line is deduced): a = 0; | - |
226 | protocol = QAbstractSocket::UnknownNetworkLayerProtocol; executed (the execution status of this line is deduced): protocol = QAbstractSocket::UnknownNetworkLayerProtocol; | - |
227 | isParsed = true; executed (the execution status of this line is deduced): isParsed = true; | - |
228 | memset(&a6, 0, sizeof(a6)); executed (the execution status of this line is deduced): memset(&a6, 0, sizeof(a6)); | - |
229 | } executed: } Execution Count:361595 | 361595 |
230 | | - |
231 | | - |
232 | bool QNetmaskAddress::setAddress(const QString &address) | - |
233 | { | - |
234 | length = -1; executed (the execution status of this line is deduced): length = -1; | - |
235 | QHostAddress other; executed (the execution status of this line is deduced): QHostAddress other; | - |
236 | return other.setAddress(address) && setAddress(other); executed: return other.setAddress(address) && setAddress(other); Execution Count:16 | 16 |
237 | } | - |
238 | | - |
239 | bool QNetmaskAddress::setAddress(const QHostAddress &address) | - |
240 | { | - |
241 | static const quint8 zeroes[16] = { 0 }; | - |
242 | union { executed (the execution status of this line is deduced): union { | - |
243 | quint32 v4; executed (the execution status of this line is deduced): quint32 v4; | - |
244 | quint8 v6[16]; executed (the execution status of this line is deduced): quint8 v6[16]; | - |
245 | } ip; executed (the execution status of this line is deduced): } ip; | - |
246 | | - |
247 | int netmask = 0; executed (the execution status of this line is deduced): int netmask = 0; | - |
248 | quint8 *ptr = ip.v6; executed (the execution status of this line is deduced): quint8 *ptr = ip.v6; | - |
249 | quint8 *end; executed (the execution status of this line is deduced): quint8 *end; | - |
250 | length = -1; executed (the execution status of this line is deduced): length = -1; | - |
251 | | - |
252 | QHostAddress::operator=(address); executed (the execution status of this line is deduced): QHostAddress::operator=(address); | - |
253 | | - |
254 | if (d->protocol == QAbstractSocket::IPv4Protocol) { evaluated: d->protocol == QAbstractSocket::IPv4Protocol yes Evaluation Count:674 | yes Evaluation Count:665 |
| 665-674 |
255 | ip.v4 = qToBigEndian(d->a); executed (the execution status of this line is deduced): ip.v4 = qToBigEndian(d->a); | - |
256 | end = ptr + 4; executed (the execution status of this line is deduced): end = ptr + 4; | - |
257 | } else if (d->protocol == QAbstractSocket::IPv6Protocol) { executed: } Execution Count:674 evaluated: d->protocol == QAbstractSocket::IPv6Protocol yes Evaluation Count:661 | yes Evaluation Count:4 |
| 4-674 |
258 | memcpy(ip.v6, d->a6.c, 16); executed (the execution status of this line is deduced): memcpy(ip.v6, d->a6.c, 16); | - |
259 | end = ptr + 16; executed (the execution status of this line is deduced): end = ptr + 16; | - |
260 | } else { executed: } Execution Count:661 | 661 |
261 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
262 | return false; executed: return false; Execution Count:4 | 4 |
263 | } | - |
264 | | - |
265 | while (ptr < end) { evaluated: ptr < end yes Evaluation Count:9400 | yes Evaluation Count:166 |
| 166-9400 |
266 | switch (*ptr) { | - |
267 | case 255: | - |
268 | netmask += 8; executed (the execution status of this line is deduced): netmask += 8; | - |
269 | ++ptr; executed (the execution status of this line is deduced): ++ptr; | - |
270 | continue; executed: continue; Execution Count:8231 | 8231 |
271 | | - |
272 | default: | - |
273 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
274 | return false; // invalid IP-style netmask executed: return false; Execution Count:4 | 4 |
275 | | - |
276 | // the rest always falls through | - |
277 | case 254: | - |
278 | ++netmask; executed (the execution status of this line is deduced): ++netmask; | - |
279 | case 252: code before this statement executed: case 252: Execution Count:4 | 4 |
280 | ++netmask; executed (the execution status of this line is deduced): ++netmask; | - |
281 | case 248: code before this statement executed: case 248: Execution Count:5 | 5 |
282 | ++netmask; executed (the execution status of this line is deduced): ++netmask; | - |
283 | case 240: code before this statement executed: case 240: Execution Count:6 | 6 |
284 | ++netmask; executed (the execution status of this line is deduced): ++netmask; | - |
285 | case 224: code before this statement executed: case 224: Execution Count:9 | 9 |
286 | ++netmask; executed (the execution status of this line is deduced): ++netmask; | - |
287 | case 192: code before this statement executed: case 192: Execution Count:11 | 11 |
288 | ++netmask; executed (the execution status of this line is deduced): ++netmask; | - |
289 | case 128: code before this statement executed: case 128: Execution Count:12 | 12 |
290 | ++netmask; executed (the execution status of this line is deduced): ++netmask; | - |
291 | case 0: | - |
292 | break; executed: break; Execution Count:1165 | 1165 |
293 | } | - |
294 | break; executed: break; Execution Count:1165 | 1165 |
295 | } | - |
296 | | - |
297 | // confirm that the rest is only zeroes | - |
298 | if (ptr < end && memcmp(ptr + 1, zeroes, end - ptr - 1) != 0) { evaluated: ptr < end yes Evaluation Count:1165 | yes Evaluation Count:166 |
evaluated: memcmp(ptr + 1, zeroes, end - ptr - 1) != 0 yes Evaluation Count:2 | yes Evaluation Count:1163 |
| 2-1165 |
299 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
300 | return false; executed: return false; Execution Count:2 | 2 |
301 | } | - |
302 | | - |
303 | length = netmask; executed (the execution status of this line is deduced): length = netmask; | - |
304 | return true; executed: return true; Execution Count:1329 | 1329 |
305 | } | - |
306 | | - |
307 | static void clearBits(quint8 *where, int start, int end) | - |
308 | { | - |
309 | Q_ASSERT(end == 32 || end == 128); executed (the execution status of this line is deduced): qt_noop(); | - |
310 | if (start == end) evaluated: start == end yes Evaluation Count:2 | yes Evaluation Count:43 |
| 2-43 |
311 | return; executed: return; Execution Count:2 | 2 |
312 | | - |
313 | // for the byte where 'start' is, clear the lower bits only | - |
314 | quint8 bytemask = 256 - (1 << (8 - (start & 7))); executed (the execution status of this line is deduced): quint8 bytemask = 256 - (1 << (8 - (start & 7))); | - |
315 | where[start / 8] &= bytemask; executed (the execution status of this line is deduced): where[start / 8] &= bytemask; | - |
316 | | - |
317 | // for the tail part, clear everything | - |
318 | memset(where + (start + 7) / 8, 0, end / 8 - (start + 7) / 8); executed (the execution status of this line is deduced): memset(where + (start + 7) / 8, 0, end / 8 - (start + 7) / 8); | - |
319 | } executed: } Execution Count:43 | 43 |
320 | | - |
321 | int QNetmaskAddress::prefixLength() const | - |
322 | { | - |
323 | return length; executed: return length; Execution Count:122 | 122 |
324 | } | - |
325 | | - |
326 | void QNetmaskAddress::setPrefixLength(QAbstractSocket::NetworkLayerProtocol proto, int newLength) | - |
327 | { | - |
328 | length = newLength; executed (the execution status of this line is deduced): length = newLength; | - |
329 | if (length < 0 || length > (proto == QAbstractSocket::IPv4Protocol ? 32 : evaluated: length < 0 yes Evaluation Count:32 | yes Evaluation Count:28 |
evaluated: length > (proto == QAbstractSocket::IPv4Protocol ? 32 : proto == QAbstractSocket::IPv6Protocol ? 128 : -1) yes Evaluation Count:16 | yes Evaluation Count:12 |
| 12-32 |
330 | proto == QAbstractSocket::IPv6Protocol ? 128 : -1)) { evaluated: length > (proto == QAbstractSocket::IPv4Protocol ? 32 : proto == QAbstractSocket::IPv6Protocol ? 128 : -1) yes Evaluation Count:16 | yes Evaluation Count:12 |
| 12-16 |
331 | // invalid information, reject | - |
332 | d->protocol = QAbstractSocket::UnknownNetworkLayerProtocol; executed (the execution status of this line is deduced): d->protocol = QAbstractSocket::UnknownNetworkLayerProtocol; | - |
333 | length = -1; executed (the execution status of this line is deduced): length = -1; | - |
334 | return; executed: return; Execution Count:48 | 48 |
335 | } | - |
336 | | - |
337 | d->protocol = proto; executed (the execution status of this line is deduced): d->protocol = proto; | - |
338 | if (d->protocol == QAbstractSocket::IPv4Protocol) { evaluated: d->protocol == QAbstractSocket::IPv4Protocol yes Evaluation Count:5 | yes Evaluation Count:7 |
| 5-7 |
339 | if (length == 0) { evaluated: length == 0 yes Evaluation Count:1 | yes Evaluation Count:4 |
| 1-4 |
340 | d->a = 0; executed (the execution status of this line is deduced): d->a = 0; | - |
341 | } else if (length == 32) { executed: } Execution Count:1 evaluated: length == 32 yes Evaluation Count:1 | yes Evaluation Count:3 |
| 1-3 |
342 | d->a = quint32(0xffffffff); executed (the execution status of this line is deduced): d->a = quint32(0xffffffff); | - |
343 | } else { executed: } Execution Count:1 | 1 |
344 | d->a = quint32(0xffffffff) >> (32 - length) << (32 - length); executed (the execution status of this line is deduced): d->a = quint32(0xffffffff) >> (32 - length) << (32 - length); | - |
345 | } executed: } Execution Count:3 | 3 |
346 | } else { | - |
347 | memset(d->a6.c, 0xFF, sizeof(d->a6)); executed (the execution status of this line is deduced): memset(d->a6.c, 0xFF, sizeof(d->a6)); | - |
348 | clearBits(d->a6.c, length, 128); executed (the execution status of this line is deduced): clearBits(d->a6.c, length, 128); | - |
349 | } executed: } Execution Count:7 | 7 |
350 | } | - |
351 | | - |
352 | /*! | - |
353 | \class QHostAddress | - |
354 | \brief The QHostAddress class provides an IP address. | - |
355 | \ingroup network | - |
356 | \inmodule QtNetwork | - |
357 | | - |
358 | This class holds an IPv4 or IPv6 address in a platform- and | - |
359 | protocol-independent manner. | - |
360 | | - |
361 | QHostAddress is normally used with the QTcpSocket, QTcpServer, | - |
362 | and QUdpSocket to connect to a host or to set up a server. | - |
363 | | - |
364 | A host address is set with setAddress(), and retrieved with | - |
365 | toIPv4Address(), toIPv6Address(), or toString(). You can check the | - |
366 | type with protocol(). | - |
367 | | - |
368 | \note Please note that QHostAddress does not do DNS lookups. | - |
369 | QHostInfo is needed for that. | - |
370 | | - |
371 | The class also supports common predefined addresses: \l Null, \l | - |
372 | LocalHost, \l LocalHostIPv6, \l Broadcast, and \l Any. | - |
373 | | - |
374 | \sa QHostInfo, QTcpSocket, QTcpServer, QUdpSocket | - |
375 | */ | - |
376 | | - |
377 | /*! \enum QHostAddress::SpecialAddress | - |
378 | | - |
379 | \value Null The null address object. Equivalent to QHostAddress(). | - |
380 | \value LocalHost The IPv4 localhost address. Equivalent to QHostAddress("127.0.0.1"). | - |
381 | \value LocalHostIPv6 The IPv6 localhost address. Equivalent to QHostAddress("::1"). | - |
382 | \value Broadcast The IPv4 broadcast address. Equivalent to QHostAddress("255.255.255.255"). | - |
383 | \value AnyIPv4 The IPv4 any-address. Equivalent to QHostAddress("0.0.0.0"). A socket bound with this address will listen only on IPv4 interaces. | - |
384 | \value AnyIPv6 The IPv6 any-address. Equivalent to QHostAddress("::"). A socket bound with this address will listen only on IPv6 interaces. | - |
385 | \value Any The dual stack any-address. A socket bound with this address will listen on both IPv4 and IPv6 interfaces. | - |
386 | */ | - |
387 | | - |
388 | /*! Constructs a host address object with the IP address 0.0.0.0. | - |
389 | | - |
390 | \sa clear() | - |
391 | */ | - |
392 | QHostAddress::QHostAddress() | - |
393 | : d(new QHostAddressPrivate) | - |
394 | { | - |
395 | } executed: } Execution Count:104596 | 104596 |
396 | | - |
397 | /*! | - |
398 | Constructs a host address object with the IPv4 address \a ip4Addr. | - |
399 | */ | - |
400 | QHostAddress::QHostAddress(quint32 ip4Addr) | - |
401 | : d(new QHostAddressPrivate) | - |
402 | { | - |
403 | setAddress(ip4Addr); executed (the execution status of this line is deduced): setAddress(ip4Addr); | - |
404 | } executed: } Execution Count:216 | 216 |
405 | | - |
406 | /*! | - |
407 | Constructs a host address object with the IPv6 address \a ip6Addr. | - |
408 | | - |
409 | \a ip6Addr must be a 16-byte array in network byte order (big | - |
410 | endian). | - |
411 | */ | - |
412 | QHostAddress::QHostAddress(quint8 *ip6Addr) | - |
413 | : d(new QHostAddressPrivate) | - |
414 | { | - |
415 | setAddress(ip6Addr); never executed (the execution status of this line is deduced): setAddress(ip6Addr); | - |
416 | } | 0 |
417 | | - |
418 | /*! | - |
419 | Constructs a host address object with the IPv6 address \a ip6Addr. | - |
420 | */ | - |
421 | QHostAddress::QHostAddress(const Q_IPV6ADDR &ip6Addr) | - |
422 | : d(new QHostAddressPrivate) | - |
423 | { | - |
424 | setAddress(ip6Addr); never executed (the execution status of this line is deduced): setAddress(ip6Addr); | - |
425 | } | 0 |
426 | | - |
427 | /*! | - |
428 | Constructs an IPv4 or IPv6 address based on the string \a address | - |
429 | (e.g., "127.0.0.1"). | - |
430 | | - |
431 | \sa setAddress() | - |
432 | */ | - |
433 | QHostAddress::QHostAddress(const QString &address) | - |
434 | : d(new QHostAddressPrivate) | - |
435 | { | - |
436 | d->ipString = address; executed (the execution status of this line is deduced): d->ipString = address; | - |
437 | d->isParsed = false; executed (the execution status of this line is deduced): d->isParsed = false; | - |
438 | } executed: } Execution Count:207 | 207 |
439 | | - |
440 | /*! | - |
441 | \fn QHostAddress::QHostAddress(const sockaddr *sockaddr) | - |
442 | | - |
443 | Constructs an IPv4 or IPv6 address using the address specified by | - |
444 | the native structure \a sockaddr. | - |
445 | | - |
446 | \sa setAddress() | - |
447 | */ | - |
448 | QHostAddress::QHostAddress(const struct sockaddr *sockaddr) | - |
449 | : d(new QHostAddressPrivate) | - |
450 | { | - |
451 | if (sockaddr->sa_family == AF_INET) never evaluated: sockaddr->sa_family == 2 | 0 |
452 | setAddress(htonl(((sockaddr_in *)sockaddr)->sin_addr.s_addr)); never executed: setAddress((__extension__ ({ register unsigned int __v, __x = (((sockaddr_in *)sockaddr)->sin_addr.s_addr); if (__builtin_constant_p (__x)) __v = ((((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24)); else __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); __v; }))); never executed: __v = ((((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24)); never executed: __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); never evaluated: __builtin_constant_p (__x) | 0 |
453 | else if (sockaddr->sa_family == AF_INET6) never evaluated: sockaddr->sa_family == 10 | 0 |
454 | setAddress(((qt_sockaddr_in6 *)sockaddr)->sin6_addr.qt_s6_addr); never executed: setAddress(((sockaddr_in6 *)sockaddr)->sin6_addr.__in6_u.__u6_addr8); | 0 |
455 | } | - |
456 | | - |
457 | /*! | - |
458 | Constructs a copy of the given \a address. | - |
459 | */ | - |
460 | QHostAddress::QHostAddress(const QHostAddress &address) | - |
461 | : d(new QHostAddressPrivate(*address.d.data())) | - |
462 | { | - |
463 | } executed: } Execution Count:75283 | 75283 |
464 | | - |
465 | /*! | - |
466 | Constructs a QHostAddress object for \a address. | - |
467 | */ | - |
468 | QHostAddress::QHostAddress(SpecialAddress address) | - |
469 | : d(new QHostAddressPrivate) | - |
470 | { | - |
471 | Q_IPV6ADDR ip6; executed (the execution status of this line is deduced): Q_IPV6ADDR ip6; | - |
472 | memset(&ip6, 0, sizeof ip6); executed (the execution status of this line is deduced): memset(&ip6, 0, sizeof ip6); | - |
473 | | - |
474 | switch (address) { | - |
475 | case Null: | - |
476 | break; executed: break; Execution Count:16 | 16 |
477 | case Broadcast: | - |
478 | d->setAddress(quint32(-1)); executed (the execution status of this line is deduced): d->setAddress(quint32(-1)); | - |
479 | break; executed: break; Execution Count:1618 | 1618 |
480 | case LocalHost: | - |
481 | d->setAddress(0x7f000001); executed (the execution status of this line is deduced): d->setAddress(0x7f000001); | - |
482 | break; executed: break; Execution Count:146 | 146 |
483 | case LocalHostIPv6: | - |
484 | ip6[15] = 1; executed (the execution status of this line is deduced): ip6[15] = 1; | - |
485 | d->setAddress(ip6); executed (the execution status of this line is deduced): d->setAddress(ip6); | - |
486 | break; executed: break; Execution Count:66 | 66 |
487 | case AnyIPv4: | - |
488 | setAddress(0u); executed (the execution status of this line is deduced): setAddress(0u); | - |
489 | break; executed: break; Execution Count:1001 | 1001 |
490 | case AnyIPv6: | - |
491 | d->setAddress(ip6); executed (the execution status of this line is deduced): d->setAddress(ip6); | - |
492 | break; executed: break; Execution Count:826 | 826 |
493 | case Any: | - |
494 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
495 | d->protocol = QAbstractSocket::AnyIPProtocol; executed (the execution status of this line is deduced): d->protocol = QAbstractSocket::AnyIPProtocol; | - |
496 | break; executed: break; Execution Count:325519 | 325519 |
497 | } | - |
498 | } executed: } Execution Count:329192 | 329192 |
499 | | - |
500 | /*! | - |
501 | Destroys the host address object. | - |
502 | */ | - |
503 | QHostAddress::~QHostAddress() | - |
504 | { | - |
505 | } | - |
506 | | - |
507 | /*! | - |
508 | Assigns another host \a address to this object, and returns a reference | - |
509 | to this object. | - |
510 | */ | - |
511 | QHostAddress &QHostAddress::operator=(const QHostAddress &address) | - |
512 | { | - |
513 | *d.data() = *address.d.data(); executed (the execution status of this line is deduced): *d.data() = *address.d.data(); | - |
514 | return *this; executed: return *this; Execution Count:53025 | 53025 |
515 | } | - |
516 | | - |
517 | /*! | - |
518 | Assigns the host address \a address to this object, and returns a | - |
519 | reference to this object. | - |
520 | | - |
521 | \sa setAddress() | - |
522 | */ | - |
523 | QHostAddress &QHostAddress::operator=(const QString &address) | - |
524 | { | - |
525 | setAddress(address); executed (the execution status of this line is deduced): setAddress(address); | - |
526 | return *this; executed: return *this; Execution Count:2 | 2 |
527 | } | - |
528 | | - |
529 | /*! | - |
530 | \fn bool QHostAddress::operator!=(const QHostAddress &other) const | - |
531 | \since 4.2 | - |
532 | | - |
533 | Returns true if this host address is not the same as the \a other | - |
534 | address given; otherwise returns false. | - |
535 | */ | - |
536 | | - |
537 | /*! | - |
538 | \fn bool QHostAddress::operator!=(SpecialAddress other) const | - |
539 | | - |
540 | Returns true if this host address is not the same as the \a other | - |
541 | address given; otherwise returns false. | - |
542 | */ | - |
543 | | - |
544 | /*! | - |
545 | Sets the host address to 0.0.0.0. | - |
546 | */ | - |
547 | void QHostAddress::clear() | - |
548 | { | - |
549 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
550 | } executed: } Execution Count:36066 | 36066 |
551 | | - |
552 | /*! | - |
553 | Set the IPv4 address specified by \a ip4Addr. | - |
554 | */ | - |
555 | void QHostAddress::setAddress(quint32 ip4Addr) | - |
556 | { | - |
557 | d->setAddress(ip4Addr); executed (the execution status of this line is deduced): d->setAddress(ip4Addr); | - |
558 | } executed: } Execution Count:27078 | 27078 |
559 | | - |
560 | /*! | - |
561 | \overload | - |
562 | | - |
563 | Set the IPv6 address specified by \a ip6Addr. | - |
564 | | - |
565 | \a ip6Addr must be an array of 16 bytes in network byte order | - |
566 | (high-order byte first). | - |
567 | */ | - |
568 | void QHostAddress::setAddress(quint8 *ip6Addr) | - |
569 | { | - |
570 | d->setAddress(ip6Addr); executed (the execution status of this line is deduced): d->setAddress(ip6Addr); | - |
571 | } executed: } Execution Count:1307 | 1307 |
572 | | - |
573 | /*! | - |
574 | \overload | - |
575 | | - |
576 | Set the IPv6 address specified by \a ip6Addr. | - |
577 | */ | - |
578 | void QHostAddress::setAddress(const Q_IPV6ADDR &ip6Addr) | - |
579 | { | - |
580 | d->setAddress(ip6Addr); executed (the execution status of this line is deduced): d->setAddress(ip6Addr); | - |
581 | } executed: } Execution Count:12300 | 12300 |
582 | | - |
583 | /*! | - |
584 | \overload | - |
585 | | - |
586 | Sets the IPv4 or IPv6 address specified by the string | - |
587 | representation specified by \a address (e.g. "127.0.0.1"). | - |
588 | Returns true and sets the address if the address was successfully | - |
589 | parsed; otherwise returns false. | - |
590 | */ | - |
591 | bool QHostAddress::setAddress(const QString &address) | - |
592 | { | - |
593 | d->ipString = address; executed (the execution status of this line is deduced): d->ipString = address; | - |
594 | return d->parse(); executed: return d->parse(); Execution Count:6174 | 6174 |
595 | } | - |
596 | | - |
597 | /*! | - |
598 | \fn void QHostAddress::setAddress(const sockaddr *sockaddr) | - |
599 | \overload | - |
600 | | - |
601 | Sets the IPv4 or IPv6 address specified by the native structure \a | - |
602 | sockaddr. Returns true and sets the address if the address was | - |
603 | successfully parsed; otherwise returns false. | - |
604 | */ | - |
605 | void QHostAddress::setAddress(const struct sockaddr *sockaddr) | - |
606 | { | - |
607 | clear(); executed (the execution status of this line is deduced): clear(); | - |
608 | if (sockaddr->sa_family == AF_INET) partially evaluated: sockaddr->sa_family == 2 yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
609 | setAddress(htonl(((sockaddr_in *)sockaddr)->sin_addr.s_addr)); executed: setAddress((__extension__ ({ register unsigned int __v, __x = (((sockaddr_in *)sockaddr)->sin_addr.s_addr); if (__builtin_constant_p (__x)) __v = ((((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24)); else __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); __v; }))); Execution Count:1 never executed: __v = ((((__x) & 0xff000000) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) << 24)); executed: __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); Execution Count:1 partially evaluated: __builtin_constant_p (__x) no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
610 | else if (sockaddr->sa_family == AF_INET6) never evaluated: sockaddr->sa_family == 10 | 0 |
611 | setAddress(((qt_sockaddr_in6 *)sockaddr)->sin6_addr.qt_s6_addr); never executed: setAddress(((sockaddr_in6 *)sockaddr)->sin6_addr.__in6_u.__u6_addr8); | 0 |
612 | } | - |
613 | | - |
614 | /*! | - |
615 | Returns the IPv4 address as a number. | - |
616 | | - |
617 | For example, if the address is 127.0.0.1, the returned value is | - |
618 | 2130706433 (i.e. 0x7f000001). | - |
619 | | - |
620 | This value is valid if the protocol() is | - |
621 | \l{QAbstractSocket::}{IPv4Protocol}, | - |
622 | or if the protocol is | - |
623 | \l{QAbstractSocket::}{IPv6Protocol}, | - |
624 | and the IPv6 address is an IPv4 mapped address. (RFC4291) | - |
625 | | - |
626 | \sa toString() | - |
627 | */ | - |
628 | quint32 QHostAddress::toIPv4Address() const | - |
629 | { | - |
630 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:1 executed: } Execution Count:630717 evaluated: !(this)->d->isParsed yes Evaluation Count:1 | yes Evaluation Count:630716 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:630717 |
| 0-630717 |
631 | return d->a; executed: return d->a; Execution Count:630717 | 630717 |
632 | } | - |
633 | | - |
634 | /*! | - |
635 | Returns the network layer protocol of the host address. | - |
636 | */ | - |
637 | QAbstractSocket::NetworkLayerProtocol QHostAddress::protocol() const | - |
638 | { | - |
639 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:105 executed: } Execution Count:1293772 evaluated: !(this)->d->isParsed yes Evaluation Count:105 | yes Evaluation Count:1293667 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:1293772 |
| 0-1293772 |
640 | return d->protocol; executed: return d->protocol; Execution Count:1293772 | 1293772 |
641 | } | - |
642 | | - |
643 | /*! | - |
644 | Returns the IPv6 address as a Q_IPV6ADDR structure. The structure | - |
645 | consists of 16 unsigned characters. | - |
646 | | - |
647 | \snippet code/src_network_kernel_qhostaddress.cpp 0 | - |
648 | | - |
649 | This value is valid if the protocol() is | - |
650 | \l{QAbstractSocket::}{IPv6Protocol}. | - |
651 | If the protocol is | - |
652 | \l{QAbstractSocket::}{IPv4Protocol}, | - |
653 | then the address is returned an an IPv4 mapped IPv6 address. (RFC4291) | - |
654 | | - |
655 | \sa toString() | - |
656 | */ | - |
657 | Q_IPV6ADDR QHostAddress::toIPv6Address() const | - |
658 | { | - |
659 | QT_ENSURE_PARSED(this); never executed: (this)->d->parse(); executed: } Execution Count:11852 partially evaluated: !(this)->d->isParsed no Evaluation Count:0 | yes Evaluation Count:11852 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:11852 |
| 0-11852 |
660 | return d->a6; executed: return d->a6; Execution Count:11852 | 11852 |
661 | } | - |
662 | | - |
663 | /*! | - |
664 | Returns the address as a string. | - |
665 | | - |
666 | For example, if the address is the IPv4 address 127.0.0.1, the | - |
667 | returned string is "127.0.0.1". For IPv6 the string format will | - |
668 | follow the RFC5952 recommendation. | - |
669 | For QHostAddress::Any, its IPv4 address will be returned ("0.0.0.0") | - |
670 | | - |
671 | \sa toIPv4Address() | - |
672 | */ | - |
673 | QString QHostAddress::toString() const | - |
674 | { | - |
675 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:2 executed: } Execution Count:654 evaluated: !(this)->d->isParsed yes Evaluation Count:2 | yes Evaluation Count:652 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:654 |
| 0-654 |
676 | if (d->protocol == QAbstractSocket::IPv4Protocol evaluated: d->protocol == QAbstractSocket::IPv4Protocol yes Evaluation Count:199 | yes Evaluation Count:455 |
| 199-455 |
677 | || d->protocol == QAbstractSocket::AnyIPProtocol) { evaluated: d->protocol == QAbstractSocket::AnyIPProtocol yes Evaluation Count:21 | yes Evaluation Count:434 |
| 21-434 |
678 | quint32 i = toIPv4Address(); executed (the execution status of this line is deduced): quint32 i = toIPv4Address(); | - |
679 | QString s; executed (the execution status of this line is deduced): QString s; | - |
680 | QIPAddressUtils::toString(s, i); executed (the execution status of this line is deduced): QIPAddressUtils::toString(s, i); | - |
681 | return s; executed: return s; Execution Count:220 | 220 |
682 | } | - |
683 | | - |
684 | if (d->protocol == QAbstractSocket::IPv6Protocol) { evaluated: d->protocol == QAbstractSocket::IPv6Protocol yes Evaluation Count:148 | yes Evaluation Count:286 |
| 148-286 |
685 | QString s; executed (the execution status of this line is deduced): QString s; | - |
686 | QIPAddressUtils::toString(s, d->a6.c); executed (the execution status of this line is deduced): QIPAddressUtils::toString(s, d->a6.c); | - |
687 | | - |
688 | if (!d->scopeId.isEmpty()) evaluated: !d->scopeId.isEmpty() yes Evaluation Count:29 | yes Evaluation Count:119 |
| 29-119 |
689 | s.append(QLatin1Char('%') + d->scopeId); executed: s.append(QLatin1Char('%') + d->scopeId); Execution Count:29 | 29 |
690 | return s; executed: return s; Execution Count:148 | 148 |
691 | } | - |
692 | | - |
693 | return QString(); executed: return QString(); Execution Count:286 | 286 |
694 | } | - |
695 | | - |
696 | /*! | - |
697 | \since 4.1 | - |
698 | | - |
699 | Returns the scope ID of an IPv6 address. For IPv4 addresses, or if the | - |
700 | address does not contain a scope ID, an empty QString is returned. | - |
701 | | - |
702 | The IPv6 scope ID specifies the scope of \e reachability for non-global | - |
703 | IPv6 addresses, limiting the area in which the address can be used. All | - |
704 | IPv6 addresses are associated with such a reachability scope. The scope ID | - |
705 | is used to disambiguate addresses that are not guaranteed to be globally | - |
706 | unique. | - |
707 | | - |
708 | IPv6 specifies the following four levels of reachability: | - |
709 | | - |
710 | \list | - |
711 | | - |
712 | \li Node-local: Addresses that are only used for communicating with | - |
713 | services on the same interface (e.g., the loopback interface "::1"). | - |
714 | | - |
715 | \li Link-local: Addresses that are local to the network interface | - |
716 | (\e{link}). There is always one link-local address for each IPv6 interface | - |
717 | on your host. Link-local addresses ("fe80...") are generated from the MAC | - |
718 | address of the local network adaptor, and are not guaranteed to be unique. | - |
719 | | - |
720 | \li Site-local: Addresses that are local to the site / private network | - |
721 | (e.g., the company intranet). Site-local addresses ("fec0...") are | - |
722 | usually distributed by the site router, and are not guaranteed to be | - |
723 | unique outside of the local site. | - |
724 | | - |
725 | \li Global: For globally routable addresses, such as public servers on the | - |
726 | Internet. | - |
727 | | - |
728 | \endlist | - |
729 | | - |
730 | When using a link-local or site-local address for IPv6 connections, you | - |
731 | must specify the scope ID. The scope ID for a link-local address is | - |
732 | usually the same as the interface name (e.g., "eth0", "en1") or number | - |
733 | (e.g., "1", "2"). | - |
734 | | - |
735 | \sa setScopeId() | - |
736 | */ | - |
737 | QString QHostAddress::scopeId() const | - |
738 | { | - |
739 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:2 executed: } Execution Count:11852 evaluated: !(this)->d->isParsed yes Evaluation Count:2 | yes Evaluation Count:11850 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:11852 |
| 0-11852 |
740 | return (d->protocol == QAbstractSocket::IPv6Protocol) ? d->scopeId : QString(); executed: return (d->protocol == QAbstractSocket::IPv6Protocol) ? d->scopeId : QString(); Execution Count:11852 | 11852 |
741 | } | - |
742 | | - |
743 | /*! | - |
744 | \since 4.1 | - |
745 | | - |
746 | Sets the IPv6 scope ID of the address to \a id. If the address | - |
747 | protocol is not IPv6, this function does nothing. | - |
748 | */ | - |
749 | void QHostAddress::setScopeId(const QString &id) | - |
750 | { | - |
751 | QT_ENSURE_PARSED(this); never executed: (this)->d->parse(); executed: } Execution Count:12790 partially evaluated: !(this)->d->isParsed no Evaluation Count:0 | yes Evaluation Count:12790 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:12790 |
| 0-12790 |
752 | if (d->protocol == QAbstractSocket::IPv6Protocol) evaluated: d->protocol == QAbstractSocket::IPv6Protocol yes Evaluation Count:5800 | yes Evaluation Count:6990 |
| 5800-6990 |
753 | d->scopeId = id; executed: d->scopeId = id; Execution Count:5800 | 5800 |
754 | } executed: } Execution Count:12790 | 12790 |
755 | | - |
756 | /*! | - |
757 | Returns true if this host address is the same as the \a other address | - |
758 | given; otherwise returns false. | - |
759 | */ | - |
760 | bool QHostAddress::operator==(const QHostAddress &other) const | - |
761 | { | - |
762 | QT_ENSURE_PARSED(this); never executed: (this)->d->parse(); executed: } Execution Count:254 partially evaluated: !(this)->d->isParsed no Evaluation Count:0 | yes Evaluation Count:254 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:254 |
| 0-254 |
763 | QT_ENSURE_PARSED(&other); never executed: (&other)->d->parse(); executed: } Execution Count:254 partially evaluated: !(&other)->d->isParsed no Evaluation Count:0 | yes Evaluation Count:254 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:254 |
| 0-254 |
764 | | - |
765 | if (d->protocol == QAbstractSocket::IPv4Protocol) evaluated: d->protocol == QAbstractSocket::IPv4Protocol yes Evaluation Count:152 | yes Evaluation Count:102 |
| 102-152 |
766 | return other.d->protocol == QAbstractSocket::IPv4Protocol && d->a == other.d->a; executed: return other.d->protocol == QAbstractSocket::IPv4Protocol && d->a == other.d->a; Execution Count:152 | 152 |
767 | if (d->protocol == QAbstractSocket::IPv6Protocol) { evaluated: d->protocol == QAbstractSocket::IPv6Protocol yes Evaluation Count:65 | yes Evaluation Count:37 |
| 37-65 |
768 | return other.d->protocol == QAbstractSocket::IPv6Protocol executed: return other.d->protocol == QAbstractSocket::IPv6Protocol && memcmp(&d->a6, &other.d->a6, sizeof(Q_IPV6ADDR)) == 0; Execution Count:65 | 65 |
769 | && memcmp(&d->a6, &other.d->a6, sizeof(Q_IPV6ADDR)) == 0; executed: return other.d->protocol == QAbstractSocket::IPv6Protocol && memcmp(&d->a6, &other.d->a6, sizeof(Q_IPV6ADDR)) == 0; Execution Count:65 | 65 |
770 | } | - |
771 | return d->protocol == other.d->protocol; executed: return d->protocol == other.d->protocol; Execution Count:37 | 37 |
772 | } | - |
773 | | - |
774 | /*! | - |
775 | Returns true if this host address is the same as the \a other | - |
776 | address given; otherwise returns false. | - |
777 | */ | - |
778 | bool QHostAddress::operator ==(SpecialAddress other) const | - |
779 | { | - |
780 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:15 executed: } Execution Count:1603 evaluated: !(this)->d->isParsed yes Evaluation Count:15 | yes Evaluation Count:1588 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:1603 |
| 0-1603 |
781 | QHostAddress otherAddress(other); executed (the execution status of this line is deduced): QHostAddress otherAddress(other); | - |
782 | QT_ENSURE_PARSED(&otherAddress); never executed: (&otherAddress)->d->parse(); executed: } Execution Count:1603 partially evaluated: !(&otherAddress)->d->isParsed no Evaluation Count:0 | yes Evaluation Count:1603 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:1603 |
| 0-1603 |
783 | | - |
784 | if (d->protocol == QAbstractSocket::IPv4Protocol) evaluated: d->protocol == QAbstractSocket::IPv4Protocol yes Evaluation Count:592 | yes Evaluation Count:1011 |
| 592-1011 |
785 | return otherAddress.d->protocol == QAbstractSocket::IPv4Protocol && d->a == otherAddress.d->a; executed: return otherAddress.d->protocol == QAbstractSocket::IPv4Protocol && d->a == otherAddress.d->a; Execution Count:592 | 592 |
786 | if (d->protocol == QAbstractSocket::IPv6Protocol) { evaluated: d->protocol == QAbstractSocket::IPv6Protocol yes Evaluation Count:963 | yes Evaluation Count:48 |
| 48-963 |
787 | return otherAddress.d->protocol == QAbstractSocket::IPv6Protocol executed: return otherAddress.d->protocol == QAbstractSocket::IPv6Protocol && memcmp(&d->a6, &otherAddress.d->a6, sizeof(Q_IPV6ADDR)) == 0; Execution Count:963 | 963 |
788 | && memcmp(&d->a6, &otherAddress.d->a6, sizeof(Q_IPV6ADDR)) == 0; executed: return otherAddress.d->protocol == QAbstractSocket::IPv6Protocol && memcmp(&d->a6, &otherAddress.d->a6, sizeof(Q_IPV6ADDR)) == 0; Execution Count:963 | 963 |
789 | } | - |
790 | if (d->protocol == QAbstractSocket::AnyIPProtocol) evaluated: d->protocol == QAbstractSocket::AnyIPProtocol yes Evaluation Count:40 | yes Evaluation Count:8 |
| 8-40 |
791 | return other == QHostAddress::Any; executed: return other == QHostAddress::Any; Execution Count:40 | 40 |
792 | return int(other) == int(Null); executed: return int(other) == int(Null); Execution Count:8 | 8 |
793 | } | - |
794 | | - |
795 | /*! | - |
796 | Returns true if this host address is null (INADDR_ANY or in6addr_any). | - |
797 | The default constructor creates a null address, and that address is | - |
798 | not valid for any host or interface. | - |
799 | */ | - |
800 | bool QHostAddress::isNull() const | - |
801 | { | - |
802 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:55 executed: } Execution Count:3727 evaluated: !(this)->d->isParsed yes Evaluation Count:55 | yes Evaluation Count:3672 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:3727 |
| 0-3727 |
803 | return d->protocol == QAbstractSocket::UnknownNetworkLayerProtocol; executed: return d->protocol == QAbstractSocket::UnknownNetworkLayerProtocol; Execution Count:3727 | 3727 |
804 | } | - |
805 | | - |
806 | /*! | - |
807 | \since 4.5 | - |
808 | | - |
809 | Returns true if this IP is in the subnet described by the network | - |
810 | prefix \a subnet and netmask \a netmask. | - |
811 | | - |
812 | An IP is considered to belong to a subnet if it is contained | - |
813 | between the lowest and the highest address in that subnet. In the | - |
814 | case of IP version 4, the lowest address is the network address, | - |
815 | while the highest address is the broadcast address. | - |
816 | | - |
817 | The \a subnet argument does not have to be the actual network | - |
818 | address (the lowest address in the subnet). It can be any valid IP | - |
819 | belonging to that subnet. In particular, if it is equal to the IP | - |
820 | address held by this object, this function will always return true | - |
821 | (provided the netmask is a valid value). | - |
822 | | - |
823 | \sa parseSubnet() | - |
824 | */ | - |
825 | bool QHostAddress::isInSubnet(const QHostAddress &subnet, int netmask) const | - |
826 | { | - |
827 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:12 executed: } Execution Count:96 evaluated: !(this)->d->isParsed yes Evaluation Count:12 | yes Evaluation Count:84 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:96 |
| 0-96 |
828 | if (subnet.protocol() != d->protocol || netmask < 0) evaluated: subnet.protocol() != d->protocol yes Evaluation Count:34 | yes Evaluation Count:62 |
evaluated: netmask < 0 yes Evaluation Count:1 | yes Evaluation Count:61 |
| 1-62 |
829 | return false; executed: return false; Execution Count:35 | 35 |
830 | | - |
831 | union { executed (the execution status of this line is deduced): union { | - |
832 | quint32 ip; executed (the execution status of this line is deduced): quint32 ip; | - |
833 | quint8 data[4]; executed (the execution status of this line is deduced): quint8 data[4]; | - |
834 | } ip4, net4; executed (the execution status of this line is deduced): } ip4, net4; | - |
835 | const quint8 *ip; executed (the execution status of this line is deduced): const quint8 *ip; | - |
836 | const quint8 *net; executed (the execution status of this line is deduced): const quint8 *net; | - |
837 | if (d->protocol == QAbstractSocket::IPv4Protocol) { evaluated: d->protocol == QAbstractSocket::IPv4Protocol yes Evaluation Count:33 | yes Evaluation Count:28 |
| 28-33 |
838 | if (netmask > 32) partially evaluated: netmask > 32 no Evaluation Count:0 | yes Evaluation Count:33 |
| 0-33 |
839 | netmask = 32; never executed: netmask = 32; | 0 |
840 | ip4.ip = qToBigEndian(d->a); executed (the execution status of this line is deduced): ip4.ip = qToBigEndian(d->a); | - |
841 | net4.ip = qToBigEndian(subnet.d->a); executed (the execution status of this line is deduced): net4.ip = qToBigEndian(subnet.d->a); | - |
842 | ip = ip4.data; executed (the execution status of this line is deduced): ip = ip4.data; | - |
843 | net = net4.data; executed (the execution status of this line is deduced): net = net4.data; | - |
844 | } else if (d->protocol == QAbstractSocket::IPv6Protocol) { executed: } Execution Count:33 evaluated: d->protocol == QAbstractSocket::IPv6Protocol yes Evaluation Count:27 | yes Evaluation Count:1 |
| 1-33 |
845 | if (netmask > 128) partially evaluated: netmask > 128 no Evaluation Count:0 | yes Evaluation Count:27 |
| 0-27 |
846 | netmask = 128; never executed: netmask = 128; | 0 |
847 | ip = d->a6.c; executed (the execution status of this line is deduced): ip = d->a6.c; | - |
848 | net = subnet.d->a6.c; executed (the execution status of this line is deduced): net = subnet.d->a6.c; | - |
849 | } else { executed: } Execution Count:27 | 27 |
850 | return false; executed: return false; Execution Count:1 | 1 |
851 | } | - |
852 | | - |
853 | if (netmask >= 8 && memcmp(ip, net, netmask / 8) != 0) evaluated: netmask >= 8 yes Evaluation Count:44 | yes Evaluation Count:16 |
evaluated: memcmp(ip, net, netmask / 8) != 0 yes Evaluation Count:21 | yes Evaluation Count:23 |
| 16-44 |
854 | return false; executed: return false; Execution Count:21 | 21 |
855 | if ((netmask & 7) == 0) evaluated: (netmask & 7) == 0 yes Evaluation Count:18 | yes Evaluation Count:21 |
| 18-21 |
856 | return true; executed: return true; Execution Count:18 | 18 |
857 | | - |
858 | // compare the last octet now | - |
859 | quint8 bytemask = 256 - (1 << (8 - (netmask & 7))); executed (the execution status of this line is deduced): quint8 bytemask = 256 - (1 << (8 - (netmask & 7))); | - |
860 | quint8 ipbyte = ip[netmask / 8]; executed (the execution status of this line is deduced): quint8 ipbyte = ip[netmask / 8]; | - |
861 | quint8 netbyte = net[netmask / 8]; executed (the execution status of this line is deduced): quint8 netbyte = net[netmask / 8]; | - |
862 | return (ipbyte & bytemask) == (netbyte & bytemask); executed: return (ipbyte & bytemask) == (netbyte & bytemask); Execution Count:21 | 21 |
863 | } | - |
864 | | - |
865 | /*! | - |
866 | \since 4.5 | - |
867 | \overload | - |
868 | | - |
869 | Returns true if this IP is in the subnet described by \a | - |
870 | subnet. The QHostAddress member of \a subnet contains the network | - |
871 | prefix and the int (second) member contains the netmask (prefix | - |
872 | length). | - |
873 | */ | - |
874 | bool QHostAddress::isInSubnet(const QPair<QHostAddress, int> &subnet) const | - |
875 | { | - |
876 | return isInSubnet(subnet.first, subnet.second); executed: return isInSubnet(subnet.first, subnet.second); Execution Count:26 | 26 |
877 | } | - |
878 | | - |
879 | | - |
880 | /*! | - |
881 | \since 4.5 | - |
882 | | - |
883 | Parses the IP and subnet information contained in \a subnet and | - |
884 | returns the network prefix for that network and its prefix length. | - |
885 | | - |
886 | The IP address and the netmask must be separated by a slash | - |
887 | (/). | - |
888 | | - |
889 | This function supports arguments in the form: | - |
890 | \list | - |
891 | \li 123.123.123.123/n where n is any value between 0 and 32 | - |
892 | \li 123.123.123.123/255.255.255.255 | - |
893 | \li <ipv6-address>/n where n is any value between 0 and 128 | - |
894 | \endlist | - |
895 | | - |
896 | For IP version 4, this function accepts as well missing trailing | - |
897 | components (i.e., less than 4 octets, like "192.168.1"), followed | - |
898 | or not by a dot. If the netmask is also missing in that case, it | - |
899 | is set to the number of octets actually passed (in the example | - |
900 | above, it would be 24, for 3 octets). | - |
901 | | - |
902 | \sa isInSubnet() | - |
903 | */ | - |
904 | QPair<QHostAddress, int> QHostAddress::parseSubnet(const QString &subnet) | - |
905 | { | - |
906 | // We support subnets in the form: | - |
907 | // ddd.ddd.ddd.ddd/nn | - |
908 | // ddd.ddd.ddd/nn | - |
909 | // ddd.ddd/nn | - |
910 | // ddd/nn | - |
911 | // ddd.ddd.ddd. | - |
912 | // ddd.ddd.ddd | - |
913 | // ddd.ddd. | - |
914 | // ddd.ddd | - |
915 | // ddd. | - |
916 | // ddd | - |
917 | // <ipv6-address>/nn | - |
918 | // | - |
919 | // where nn can be an IPv4-style netmask for the IPv4 forms | - |
920 | | - |
921 | const QPair<QHostAddress, int> invalid = qMakePair(QHostAddress(), -1); executed (the execution status of this line is deduced): const QPair<QHostAddress, int> invalid = qMakePair(QHostAddress(), -1); | - |
922 | if (subnet.isEmpty()) evaluated: subnet.isEmpty() yes Evaluation Count:1 | yes Evaluation Count:101 |
| 1-101 |
923 | return invalid; executed: return invalid; Execution Count:1 | 1 |
924 | | - |
925 | int slash = subnet.indexOf(QLatin1Char('/')); executed (the execution status of this line is deduced): int slash = subnet.indexOf(QLatin1Char('/')); | - |
926 | QString netStr = subnet; executed (the execution status of this line is deduced): QString netStr = subnet; | - |
927 | if (slash != -1) evaluated: slash != -1 yes Evaluation Count:88 | yes Evaluation Count:13 |
| 13-88 |
928 | netStr.truncate(slash); executed: netStr.truncate(slash); Execution Count:88 | 88 |
929 | | - |
930 | int netmask = -1; executed (the execution status of this line is deduced): int netmask = -1; | - |
931 | bool isIpv6 = netStr.contains(QLatin1Char(':')); executed (the execution status of this line is deduced): bool isIpv6 = netStr.contains(QLatin1Char(':')); | - |
932 | | - |
933 | if (slash != -1) { evaluated: slash != -1 yes Evaluation Count:88 | yes Evaluation Count:13 |
| 13-88 |
934 | // is the netmask given in IP-form or in bit-count form? | - |
935 | if (!isIpv6 && subnet.indexOf(QLatin1Char('.'), slash + 1) != -1) { evaluated: !isIpv6 yes Evaluation Count:46 | yes Evaluation Count:42 |
evaluated: subnet.indexOf(QLatin1Char('.'), slash + 1) != -1 yes Evaluation Count:16 | yes Evaluation Count:30 |
| 16-46 |
936 | // IP-style, convert it to bit-count form | - |
937 | QNetmaskAddress parser; executed (the execution status of this line is deduced): QNetmaskAddress parser; | - |
938 | if (!parser.setAddress(subnet.mid(slash + 1))) evaluated: !parser.setAddress(subnet.mid(slash + 1)) yes Evaluation Count:3 | yes Evaluation Count:13 |
| 3-13 |
939 | return invalid; executed: return invalid; Execution Count:3 | 3 |
940 | netmask = parser.prefixLength(); executed (the execution status of this line is deduced): netmask = parser.prefixLength(); | - |
941 | } else { executed: } Execution Count:13 | 13 |
942 | bool ok; executed (the execution status of this line is deduced): bool ok; | - |
943 | netmask = subnet.mid(slash + 1).toUInt(&ok); executed (the execution status of this line is deduced): netmask = subnet.mid(slash + 1).toUInt(&ok); | - |
944 | if (!ok) evaluated: !ok yes Evaluation Count:4 | yes Evaluation Count:68 |
| 4-68 |
945 | return invalid; // failed to parse the subnet executed: return invalid; Execution Count:4 | 4 |
946 | } executed: } Execution Count:68 | 68 |
947 | } | - |
948 | | - |
949 | if (isIpv6) { evaluated: isIpv6 yes Evaluation Count:40 | yes Evaluation Count:54 |
| 40-54 |
950 | // looks like it's an IPv6 address | - |
951 | if (netmask > 128) evaluated: netmask > 128 yes Evaluation Count:1 | yes Evaluation Count:39 |
| 1-39 |
952 | return invalid; // invalid netmask executed: return invalid; Execution Count:1 | 1 |
953 | if (netmask < 0) evaluated: netmask < 0 yes Evaluation Count:1 | yes Evaluation Count:38 |
| 1-38 |
954 | netmask = 128; executed: netmask = 128; Execution Count:1 | 1 |
955 | | - |
956 | QHostAddress net; executed (the execution status of this line is deduced): QHostAddress net; | - |
957 | if (!net.setAddress(netStr)) evaluated: !net.setAddress(netStr) yes Evaluation Count:1 | yes Evaluation Count:38 |
| 1-38 |
958 | return invalid; // failed to parse the IP executed: return invalid; Execution Count:1 | 1 |
959 | | - |
960 | clearBits(net.d->a6.c, netmask, 128); executed (the execution status of this line is deduced): clearBits(net.d->a6.c, netmask, 128); | - |
961 | return qMakePair(net, netmask); executed: return qMakePair(net, netmask); Execution Count:38 | 38 |
962 | } | - |
963 | | - |
964 | if (netmask > 32) evaluated: netmask > 32 yes Evaluation Count:1 | yes Evaluation Count:53 |
| 1-53 |
965 | return invalid; // invalid netmask executed: return invalid; Execution Count:1 | 1 |
966 | | - |
967 | // parse the address manually | - |
968 | QStringList parts = netStr.split(QLatin1Char('.')); executed (the execution status of this line is deduced): QStringList parts = netStr.split(QLatin1Char('.')); | - |
969 | if (parts.isEmpty() || parts.count() > 4) partially evaluated: parts.isEmpty() no Evaluation Count:0 | yes Evaluation Count:53 |
evaluated: parts.count() > 4 yes Evaluation Count:2 | yes Evaluation Count:51 |
| 0-53 |
970 | return invalid; // invalid IPv4 address executed: return invalid; Execution Count:2 | 2 |
971 | | - |
972 | if (parts.last().isEmpty()) evaluated: parts.last().isEmpty() yes Evaluation Count:2 | yes Evaluation Count:49 |
| 2-49 |
973 | parts.removeLast(); executed: parts.removeLast(); Execution Count:2 | 2 |
974 | | - |
975 | quint32 addr = 0; executed (the execution status of this line is deduced): quint32 addr = 0; | - |
976 | for (int i = 0; i < parts.count(); ++i) { evaluated: i < parts.count() yes Evaluation Count:166 | yes Evaluation Count:48 |
| 48-166 |
977 | bool ok; executed (the execution status of this line is deduced): bool ok; | - |
978 | uint byteValue = parts.at(i).toUInt(&ok); executed (the execution status of this line is deduced): uint byteValue = parts.at(i).toUInt(&ok); | - |
979 | if (!ok || byteValue > 255) evaluated: !ok yes Evaluation Count:3 | yes Evaluation Count:163 |
partially evaluated: byteValue > 255 no Evaluation Count:0 | yes Evaluation Count:163 |
| 0-163 |
980 | return invalid; // invalid IPv4 address executed: return invalid; Execution Count:3 | 3 |
981 | | - |
982 | addr <<= 8; executed (the execution status of this line is deduced): addr <<= 8; | - |
983 | addr += byteValue; executed (the execution status of this line is deduced): addr += byteValue; | - |
984 | } executed: } Execution Count:163 | 163 |
985 | addr <<= 8 * (4 - parts.count()); executed (the execution status of this line is deduced): addr <<= 8 * (4 - parts.count()); | - |
986 | if (netmask == -1) { evaluated: netmask == -1 yes Evaluation Count:7 | yes Evaluation Count:41 |
| 7-41 |
987 | netmask = 8 * parts.count(); executed (the execution status of this line is deduced): netmask = 8 * parts.count(); | - |
988 | } else if (netmask == 0) { executed: } Execution Count:7 evaluated: netmask == 0 yes Evaluation Count:3 | yes Evaluation Count:38 |
| 3-38 |
989 | // special case here | - |
990 | // x86's instructions "shr" and "shl" do not operate when | - |
991 | // their argument is 32, so the code below doesn't work as expected | - |
992 | addr = 0; executed (the execution status of this line is deduced): addr = 0; | - |
993 | } else if (netmask != 32) { executed: } Execution Count:3 evaluated: netmask != 32 yes Evaluation Count:36 | yes Evaluation Count:2 |
| 2-36 |
994 | // clear remaining bits | - |
995 | quint32 mask = quint32(0xffffffff) >> (32 - netmask) << (32 - netmask); executed (the execution status of this line is deduced): quint32 mask = quint32(0xffffffff) >> (32 - netmask) << (32 - netmask); | - |
996 | addr &= mask; executed (the execution status of this line is deduced): addr &= mask; | - |
997 | } executed: } Execution Count:36 | 36 |
998 | | - |
999 | return qMakePair(QHostAddress(addr), netmask); executed: return qMakePair(QHostAddress(addr), netmask); Execution Count:48 | 48 |
1000 | } | - |
1001 | | - |
1002 | /*! | - |
1003 | \since 5.0 | - |
1004 | | - |
1005 | returns true if the address is the IPv6 loopback address, or any | - |
1006 | of the IPv4 loopback addresses. | - |
1007 | */ | - |
1008 | bool QHostAddress::isLoopback() const | - |
1009 | { | - |
1010 | QT_ENSURE_PARSED(this); executed: (this)->d->parse(); Execution Count:18 executed: } Execution Count:4803 evaluated: !(this)->d->isParsed yes Evaluation Count:18 | yes Evaluation Count:4785 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:4803 |
| 0-4803 |
1011 | if ((d->a & 0xFF000000) == 0x7F000000) evaluated: (d->a & 0xFF000000) == 0x7F000000 yes Evaluation Count:2140 | yes Evaluation Count:2663 |
| 2140-2663 |
1012 | return true; // v4 range (including IPv6 wrapped IPv4 addresses) executed: return true; Execution Count:2140 | 2140 |
1013 | if (d->protocol == QAbstractSocket::IPv6Protocol) { evaluated: d->protocol == QAbstractSocket::IPv6Protocol yes Evaluation Count:135 | yes Evaluation Count:2528 |
| 135-2528 |
1014 | if (d->a6.c[15] != 1) evaluated: d->a6.c[15] != 1 yes Evaluation Count:67 | yes Evaluation Count:68 |
| 67-68 |
1015 | return false; executed: return false; Execution Count:67 | 67 |
1016 | for (int i = 0; i < 15; i++) evaluated: i < 15 yes Evaluation Count:908 | yes Evaluation Count:60 |
| 60-908 |
1017 | if (d->a6[i] != 0) evaluated: d->a6[i] != 0 yes Evaluation Count:8 | yes Evaluation Count:900 |
| 8-900 |
1018 | return false; executed: return false; Execution Count:8 | 8 |
1019 | return true; executed: return true; Execution Count:60 | 60 |
1020 | } | - |
1021 | return false; executed: return false; Execution Count:2528 | 2528 |
1022 | } | - |
1023 | | - |
1024 | #ifndef QT_NO_DEBUG_STREAM | - |
1025 | QDebug operator<<(QDebug d, const QHostAddress &address) | - |
1026 | { | - |
1027 | d.maybeSpace() << "QHostAddress(" << address.toString() << ')'; executed (the execution status of this line is deduced): d.maybeSpace() << "QHostAddress(" << address.toString() << ')'; | - |
1028 | return d.space(); executed: return d.space(); Execution Count:6 | 6 |
1029 | } | - |
1030 | #endif | - |
1031 | | - |
1032 | uint qHash(const QHostAddress &key, uint seed) | - |
1033 | { | - |
1034 | // both lines might throw | - |
1035 | QT_ENSURE_PARSED(&key); never executed: (&key)->d->parse(); executed: } Execution Count:10 partially evaluated: !(&key)->d->isParsed no Evaluation Count:0 | yes Evaluation Count:10 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:10 |
| 0-10 |
1036 | return qHash(QByteArray::fromRawData(reinterpret_cast<const char *>(key.d->a6.c), 16), seed); executed: return qHash(QByteArray::fromRawData(reinterpret_cast<const char *>(key.d->a6.c), 16), seed); Execution Count:10 | 10 |
1037 | } | - |
1038 | | - |
1039 | #ifndef QT_NO_DATASTREAM | - |
1040 | | - |
1041 | /*! \relates QHostAddress | - |
1042 | | - |
1043 | Writes host address \a address to the stream \a out and returns a reference | - |
1044 | to the stream. | - |
1045 | | - |
1046 | \sa {Serializing Qt Data Types} | - |
1047 | */ | - |
1048 | QDataStream &operator<<(QDataStream &out, const QHostAddress &address) | - |
1049 | { | - |
1050 | qint8 prot; executed (the execution status of this line is deduced): qint8 prot; | - |
1051 | prot = qint8(address.protocol()); executed (the execution status of this line is deduced): prot = qint8(address.protocol()); | - |
1052 | out << prot; executed (the execution status of this line is deduced): out << prot; | - |
1053 | switch (address.protocol()) { | - |
1054 | case QAbstractSocket::UnknownNetworkLayerProtocol: | - |
1055 | case QAbstractSocket::AnyIPProtocol: | - |
1056 | break; executed: break; Execution Count:4 | 4 |
1057 | case QAbstractSocket::IPv4Protocol: | - |
1058 | out << address.toIPv4Address(); executed (the execution status of this line is deduced): out << address.toIPv4Address(); | - |
1059 | break; executed: break; Execution Count:5 | 5 |
1060 | case QAbstractSocket::IPv6Protocol: | - |
1061 | { | - |
1062 | Q_IPV6ADDR ipv6 = address.toIPv6Address(); executed (the execution status of this line is deduced): Q_IPV6ADDR ipv6 = address.toIPv6Address(); | - |
1063 | for (int i = 0; i < 16; ++i) evaluated: i < 16 yes Evaluation Count:64 | yes Evaluation Count:4 |
| 4-64 |
1064 | out << ipv6[i]; executed: out << ipv6[i]; Execution Count:64 | 64 |
1065 | out << address.scopeId(); executed (the execution status of this line is deduced): out << address.scopeId(); | - |
1066 | } | - |
1067 | break; executed: break; Execution Count:4 | 4 |
1068 | } | - |
1069 | return out; executed: return out; Execution Count:13 | 13 |
1070 | } | - |
1071 | | - |
1072 | /*! \relates QHostAddress | - |
1073 | | - |
1074 | Reads a host address into \a address from the stream \a in and returns a | - |
1075 | reference to the stream. | - |
1076 | | - |
1077 | \sa {Serializing Qt Data Types} | - |
1078 | */ | - |
1079 | QDataStream &operator>>(QDataStream &in, QHostAddress &address) | - |
1080 | { | - |
1081 | qint8 prot; executed (the execution status of this line is deduced): qint8 prot; | - |
1082 | in >> prot; executed (the execution status of this line is deduced): in >> prot; | - |
1083 | switch (QAbstractSocket::NetworkLayerProtocol(prot)) { | - |
1084 | case QAbstractSocket::UnknownNetworkLayerProtocol: | - |
1085 | address.clear(); executed (the execution status of this line is deduced): address.clear(); | - |
1086 | break; executed: break; Execution Count:3 | 3 |
1087 | case QAbstractSocket::IPv4Protocol: | - |
1088 | { | - |
1089 | quint32 ipv4; executed (the execution status of this line is deduced): quint32 ipv4; | - |
1090 | in >> ipv4; executed (the execution status of this line is deduced): in >> ipv4; | - |
1091 | address.setAddress(ipv4); executed (the execution status of this line is deduced): address.setAddress(ipv4); | - |
1092 | } | - |
1093 | break; executed: break; Execution Count:5 | 5 |
1094 | case QAbstractSocket::IPv6Protocol: | - |
1095 | { | - |
1096 | Q_IPV6ADDR ipv6; executed (the execution status of this line is deduced): Q_IPV6ADDR ipv6; | - |
1097 | for (int i = 0; i < 16; ++i) evaluated: i < 16 yes Evaluation Count:64 | yes Evaluation Count:4 |
| 4-64 |
1098 | in >> ipv6[i]; executed: in >> ipv6[i]; Execution Count:64 | 64 |
1099 | address.setAddress(ipv6); executed (the execution status of this line is deduced): address.setAddress(ipv6); | - |
1100 | | - |
1101 | QString scope; executed (the execution status of this line is deduced): QString scope; | - |
1102 | in >> scope; executed (the execution status of this line is deduced): in >> scope; | - |
1103 | address.setScopeId(scope); executed (the execution status of this line is deduced): address.setScopeId(scope); | - |
1104 | } | - |
1105 | break; executed: break; Execution Count:4 | 4 |
1106 | case QAbstractSocket::AnyIPProtocol: | - |
1107 | address = QHostAddress::Any; executed (the execution status of this line is deduced): address = QHostAddress::Any; | - |
1108 | break; executed: break; Execution Count:1 | 1 |
1109 | default: | - |
1110 | address.clear(); never executed (the execution status of this line is deduced): address.clear(); | - |
1111 | in.setStatus(QDataStream::ReadCorruptData); never executed (the execution status of this line is deduced): in.setStatus(QDataStream::ReadCorruptData); | - |
1112 | } | 0 |
1113 | return in; executed: return in; Execution Count:13 | 13 |
1114 | } | - |
1115 | | - |
1116 | #endif //QT_NO_DATASTREAM | - |
1117 | | - |
1118 | QT_END_NAMESPACE | - |
1119 | | - |
| | |