kernel/qhostinfo_unix.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//#define QHOSTINFO_DEBUG -
43 -
44#include "qplatformdefs.h" -
45 -
46#include "qhostinfo_p.h" -
47#include "private/qnativesocketengine_p.h" -
48#include "qiodevice.h" -
49#include <qbytearray.h> -
50#include <qlibrary.h> -
51#include <qbasicatomic.h> -
52#include <qurl.h> -
53#include <qfile.h> -
54#include <private/qmutexpool_p.h> -
55#include <private/qnet_unix_p.h> -
56 -
57#include <sys/types.h> -
58#include <netdb.h> -
59#include <arpa/inet.h> -
60#if defined(Q_OS_VXWORKS) -
61# include <hostLib.h> -
62#else -
63# include <resolv.h> -
64#endif -
65 -
66#if defined (QT_NO_GETADDRINFO) -
67static QBasicMutex getHostByNameMutex; -
68#endif -
69 -
70QT_BEGIN_NAMESPACE -
71 -
72// Almost always the same. If not, specify in qplatformdefs.h. -
73#if !defined(QT_SOCKOPTLEN_T) -
74# define QT_SOCKOPTLEN_T QT_SOCKLEN_T -
75#endif -
76 -
77// HP-UXi has a bug in getaddrinfo(3) that makes it thread-unsafe -
78// with this flag. So disable it in that platform. -
79#if defined(AI_ADDRCONFIG) && !defined(Q_OS_HPUX) -
80# define Q_ADDRCONFIG AI_ADDRCONFIG -
81#endif -
82 -
83typedef struct __res_state *res_state_ptr; -
84 -
85typedef int (*res_init_proto)(void); -
86static res_init_proto local_res_init = 0; -
87typedef int (*res_ninit_proto)(res_state_ptr); -
88static res_ninit_proto local_res_ninit = 0; -
89typedef void (*res_nclose_proto)(res_state_ptr); -
90static res_nclose_proto local_res_nclose = 0; -
91static res_state_ptr local_res = 0; -
92 -
93static void resolveLibrary() -
94{ -
95#ifndef QT_NO_LIBRARY -
96 QLibrary lib(QLatin1String("resolv"));
executed (the execution status of this line is deduced): QLibrary lib(QLatin1String("resolv"));
-
97 if (!lib.load())
partially evaluated: !lib.load()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
98 return;
never executed: return;
0
99 -
100 local_res_init = res_init_proto(lib.resolve("__res_init"));
executed (the execution status of this line is deduced): local_res_init = res_init_proto(lib.resolve("__res_init"));
-
101 if (!local_res_init)
partially evaluated: !local_res_init
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
102 local_res_init = res_init_proto(lib.resolve("res_init"));
never executed: local_res_init = res_init_proto(lib.resolve("res_init"));
0
103 -
104 local_res_ninit = res_ninit_proto(lib.resolve("__res_ninit"));
executed (the execution status of this line is deduced): local_res_ninit = res_ninit_proto(lib.resolve("__res_ninit"));
-
105 if (!local_res_ninit)
partially evaluated: !local_res_ninit
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
106 local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
never executed: local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
0
107 -
108 if (!local_res_ninit) {
partially evaluated: !local_res_ninit
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
109 // if we can't get a thread-safe context, we have to use the global _res state -
110 local_res = res_state_ptr(lib.resolve("_res"));
never executed (the execution status of this line is deduced): local_res = res_state_ptr(lib.resolve("_res"));
-
111 } else {
never executed: }
0
112 local_res_nclose = res_nclose_proto(lib.resolve("res_nclose"));
executed (the execution status of this line is deduced): local_res_nclose = res_nclose_proto(lib.resolve("res_nclose"));
-
113 if (!local_res_nclose)
partially evaluated: !local_res_nclose
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
114 local_res_nclose = res_nclose_proto(lib.resolve("__res_nclose"));
executed: local_res_nclose = res_nclose_proto(lib.resolve("__res_nclose"));
Execution Count:13
13
115 if (!local_res_nclose)
partially evaluated: !local_res_nclose
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
116 local_res_ninit = 0;
never executed: local_res_ninit = 0;
0
117 }
executed: }
Execution Count:13
13
118#endif -
119} -
120 -
121QHostInfo QHostInfoAgent::fromName(const QString &hostName) -
122{ -
123 QHostInfo results;
executed (the execution status of this line is deduced): QHostInfo results;
-
124 -
125#if defined(QHOSTINFO_DEBUG) -
126 qDebug("QHostInfoAgent::fromName(%s) looking up...", -
127 hostName.toLatin1().constData()); -
128#endif -
129 -
130 // Load res_init on demand. -
131 static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); -
132 if (!triedResolve.loadAcquire()) {
evaluated: !triedResolve.loadAcquire()
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:23
13-23
133 QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init));
executed (the execution status of this line is deduced): QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init));
-
134 if (!triedResolve.load()) {
partially evaluated: !triedResolve.load()
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
135 resolveLibrary();
executed (the execution status of this line is deduced): resolveLibrary();
-
136 triedResolve.storeRelease(true);
executed (the execution status of this line is deduced): triedResolve.storeRelease(true);
-
137 }
executed: }
Execution Count:13
13
138 }
executed: }
Execution Count:13
13
139 -
140 // If res_init is available, poll it. -
141 if (local_res_init)
partially evaluated: local_res_init
TRUEFALSE
yes
Evaluation Count:36
no
Evaluation Count:0
0-36
142 local_res_init();
executed: local_res_init();
Execution Count:36
36
143 -
144 QHostAddress address;
executed (the execution status of this line is deduced): QHostAddress address;
-
145 if (address.setAddress(hostName)) {
partially evaluated: address.setAddress(hostName)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
146 // Reverse lookup -
147// Reverse lookups using getnameinfo are broken on darwin, use gethostbyaddr instead. -
148#if !defined (QT_NO_GETADDRINFO) && !defined (Q_OS_DARWIN) -
149 sockaddr_in sa4;
never executed (the execution status of this line is deduced): sockaddr_in sa4;
-
150 sockaddr_in6 sa6;
never executed (the execution status of this line is deduced): sockaddr_in6 sa6;
-
151 sockaddr *sa = 0;
never executed (the execution status of this line is deduced): sockaddr *sa = 0;
-
152 QT_SOCKLEN_T saSize = 0;
never executed (the execution status of this line is deduced): socklen_t saSize = 0;
-
153 if (address.protocol() == QAbstractSocket::IPv4Protocol) {
never evaluated: address.protocol() == QAbstractSocket::IPv4Protocol
0
154 sa = (sockaddr *)&sa4;
never executed (the execution status of this line is deduced): sa = (sockaddr *)&sa4;
-
155 saSize = sizeof(sa4);
never executed (the execution status of this line is deduced): saSize = sizeof(sa4);
-
156 memset(&sa4, 0, sizeof(sa4));
never executed (the execution status of this line is deduced): memset(&sa4, 0, sizeof(sa4));
-
157 sa4.sin_family = AF_INET;
never executed (the execution status of this line is deduced): sa4.sin_family = 2;
-
158 sa4.sin_addr.s_addr = htonl(address.toIPv4Address());
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
159 }
never executed: }
0
160 else { -
161 sa = (sockaddr *)&sa6;
never executed (the execution status of this line is deduced): sa = (sockaddr *)&sa6;
-
162 saSize = sizeof(sa6);
never executed (the execution status of this line is deduced): saSize = sizeof(sa6);
-
163 memset(&sa6, 0, sizeof(sa6));
never executed (the execution status of this line is deduced): memset(&sa6, 0, sizeof(sa6));
-
164 sa6.sin6_family = AF_INET6;
never executed (the execution status of this line is deduced): sa6.sin6_family = 10;
-
165 memcpy(sa6.sin6_addr.s6_addr, address.toIPv6Address().c, sizeof(sa6.sin6_addr.s6_addr));
never executed (the execution status of this line is deduced): memcpy(sa6.sin6_addr.__in6_u.__u6_addr8, address.toIPv6Address().c, sizeof(sa6.sin6_addr.__in6_u.__u6_addr8));
-
166 }
never executed: }
0
167 -
168 char hbuf[NI_MAXHOST];
never executed (the execution status of this line is deduced): char hbuf[1025];
-
169 if (sa && getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0)
never evaluated: sa
never evaluated: getnameinfo(sa, saSize, hbuf, sizeof(hbuf), 0, 0, 0) == 0
0
170 results.setHostName(QString::fromLatin1(hbuf));
never executed: results.setHostName(QString::fromLatin1(hbuf));
0
171#else -
172 in_addr_t inetaddr = qt_safe_inet_addr(hostName.toLatin1().constData()); -
173 struct hostent *ent = gethostbyaddr((const char *)&inetaddr, sizeof(inetaddr), AF_INET); -
174 if (ent) -
175 results.setHostName(QString::fromLatin1(ent->h_name)); -
176#endif -
177 -
178 if (results.hostName().isEmpty())
never evaluated: results.hostName().isEmpty()
0
179 results.setHostName(address.toString());
never executed: results.setHostName(address.toString());
0
180 results.setAddresses(QList<QHostAddress>() << address);
never executed (the execution status of this line is deduced): results.setAddresses(QList<QHostAddress>() << address);
-
181 return results;
never executed: return results;
0
182 } -
183 -
184 // IDN support -
185 QByteArray aceHostname = QUrl::toAce(hostName);
executed (the execution status of this line is deduced): QByteArray aceHostname = QUrl::toAce(hostName);
-
186 results.setHostName(hostName);
executed (the execution status of this line is deduced): results.setHostName(hostName);
-
187 if (aceHostname.isEmpty()) {
partially evaluated: aceHostname.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
188 results.setError(QHostInfo::HostNotFound);
never executed (the execution status of this line is deduced): results.setError(QHostInfo::HostNotFound);
-
189 results.setErrorString(hostName.isEmpty() ?
never executed (the execution status of this line is deduced): results.setErrorString(hostName.isEmpty() ?
-
190 QCoreApplication::translate("QHostInfoAgent", "No host name given") :
never executed (the execution status of this line is deduced): QCoreApplication::translate("QHostInfoAgent", "No host name given") :
-
191 QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
never executed (the execution status of this line is deduced): QCoreApplication::translate("QHostInfoAgent", "Invalid hostname"));
-
192 return results;
never executed: return results;
0
193 } -
194 -
195#if !defined (QT_NO_GETADDRINFO) -
196 // Call getaddrinfo, and place all IPv4 addresses at the start and -
197 // the IPv6 addresses at the end of the address list in results. -
198 addrinfo *res = 0;
executed (the execution status of this line is deduced): addrinfo *res = 0;
-
199 struct addrinfo hints;
executed (the execution status of this line is deduced): struct addrinfo hints;
-
200 memset(&hints, 0, sizeof(hints));
executed (the execution status of this line is deduced): memset(&hints, 0, sizeof(hints));
-
201 hints.ai_family = PF_UNSPEC;
executed (the execution status of this line is deduced): hints.ai_family = 0;
-
202#ifdef Q_ADDRCONFIG -
203 hints.ai_flags = Q_ADDRCONFIG;
executed (the execution status of this line is deduced): hints.ai_flags = 0x0020;
-
204#endif -
205 -
206 int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
executed (the execution status of this line is deduced): int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
-
207# ifdef Q_ADDRCONFIG -
208 if (result == EAI_BADFLAGS) {
partially evaluated: result == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
209 // if the lookup failed with AI_ADDRCONFIG set, try again without it -
210 hints.ai_flags = 0;
never executed (the execution status of this line is deduced): hints.ai_flags = 0;
-
211 result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
never executed (the execution status of this line is deduced): result = getaddrinfo(aceHostname.constData(), 0, &hints, &res);
-
212 }
never executed: }
0
213# endif -
214 -
215 if (result == 0) {
evaluated: result == 0
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:5
5-31
216 addrinfo *node = res;
executed (the execution status of this line is deduced): addrinfo *node = res;
-
217 QList<QHostAddress> addresses;
executed (the execution status of this line is deduced): QList<QHostAddress> addresses;
-
218 while (node) {
evaluated: node
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:31
31-96
219#ifdef QHOSTINFO_DEBUG -
220 qDebug() << "getaddrinfo node: flags:" << node->ai_flags << "family:" << node->ai_family << "ai_socktype:" << node->ai_socktype << "ai_protocol:" << node->ai_protocol << "ai_addrlen:" << node->ai_addrlen; -
221#endif -
222 if (node->ai_family == AF_INET) {
evaluated: node->ai_family == 2
TRUEFALSE
yes
Evaluation Count:93
yes
Evaluation Count:3
3-93
223 QHostAddress addr;
executed (the execution status of this line is deduced): QHostAddress addr;
-
224 addr.setAddress(ntohl(((sockaddr_in *) node->ai_addr)->sin_addr.s_addr));
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:93
partially evaluated: __builtin_constant_p (__x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:93
0-93
225 if (!addresses.contains(addr))
evaluated: !addresses.contains(addr)
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:62
31-62
226 addresses.append(addr);
executed: addresses.append(addr);
Execution Count:31
31
227 }
executed: }
Execution Count:93
93
228 else if (node->ai_family == AF_INET6) {
partially evaluated: node->ai_family == 10
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
229 QHostAddress addr;
executed (the execution status of this line is deduced): QHostAddress addr;
-
230 sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
executed (the execution status of this line is deduced): sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr;
-
231 addr.setAddress(sa6->sin6_addr.s6_addr);
executed (the execution status of this line is deduced): addr.setAddress(sa6->sin6_addr.__in6_u.__u6_addr8);
-
232 if (sa6->sin6_scope_id)
partially evaluated: sa6->sin6_scope_id
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
233 addr.setScopeId(QString::number(sa6->sin6_scope_id));
never executed: addr.setScopeId(QString::number(sa6->sin6_scope_id));
0
234 if (!addresses.contains(addr))
evaluated: !addresses.contains(addr)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
235 addresses.append(addr);
executed: addresses.append(addr);
Execution Count:1
1
236 }
executed: }
Execution Count:3
3
237 node = node->ai_next;
executed (the execution status of this line is deduced): node = node->ai_next;
-
238 }
executed: }
Execution Count:96
96
239 if (addresses.isEmpty() && node == 0) {
partially evaluated: addresses.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
never evaluated: node == 0
0-31
240 // Reached the end of the list, but no addresses were found; this -
241 // means the list contains one or more unknown address types. -
242 results.setError(QHostInfo::UnknownError);
never executed (the execution status of this line is deduced): results.setError(QHostInfo::UnknownError);
-
243 results.setErrorString(tr("Unknown address type"));
never executed (the execution status of this line is deduced): results.setErrorString(tr("Unknown address type"));
-
244 }
never executed: }
0
245 -
246 results.setAddresses(addresses);
executed (the execution status of this line is deduced): results.setAddresses(addresses);
-
247 freeaddrinfo(res);
executed (the execution status of this line is deduced): freeaddrinfo(res);
-
248 } else if (result == EAI_NONAME
executed: }
Execution Count:31
partially evaluated: result == -2
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-31
249 || result == EAI_FAIL
never evaluated: result == -4
0
250#ifdef EAI_NODATA
executed (the execution status of this line is deduced):
-
251 // EAI_NODATA is deprecated in RFC 3493
executed (the execution status of this line is deduced):
-
252 || result == EAI_NODATA
never evaluated: result == -5
0
253#endif -
254 ) { -
255 results.setError(QHostInfo::HostNotFound);
executed (the execution status of this line is deduced): results.setError(QHostInfo::HostNotFound);
-
256 results.setErrorString(tr("Host not found"));
executed (the execution status of this line is deduced): results.setErrorString(tr("Host not found"));
-
257 } else {
executed: }
Execution Count:5
5
258 results.setError(QHostInfo::UnknownError);
never executed (the execution status of this line is deduced): results.setError(QHostInfo::UnknownError);
-
259 results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
never executed (the execution status of this line is deduced): results.setErrorString(QString::fromLocal8Bit(gai_strerror(result)));
-
260 }
never executed: }
0
261 -
262#else -
263 // Fall back to gethostbyname for platforms that don't define -
264 // getaddrinfo. gethostbyname does not support IPv6, and it's not -
265 // reentrant on all platforms. For now this is okay since we only -
266 // use one QHostInfoAgent, but if more agents are introduced, locking -
267 // must be provided. -
268 QMutexLocker locker(&getHostByNameMutex); -
269 hostent *result = gethostbyname(aceHostname.constData()); -
270 if (result) { -
271 if (result->h_addrtype == AF_INET) { -
272 QList<QHostAddress> addresses; -
273 for (char **p = result->h_addr_list; *p != 0; p++) { -
274 QHostAddress addr; -
275 addr.setAddress(ntohl(*((quint32 *)*p))); -
276 if (!addresses.contains(addr)) -
277 addresses.prepend(addr); -
278 } -
279 results.setAddresses(addresses); -
280 } else { -
281 results.setError(QHostInfo::UnknownError); -
282 results.setErrorString(tr("Unknown address type")); -
283 } -
284#if !defined(Q_OS_VXWORKS) -
285 } else if (h_errno == HOST_NOT_FOUND || h_errno == NO_DATA -
286 || h_errno == NO_ADDRESS) { -
287 results.setError(QHostInfo::HostNotFound); -
288 results.setErrorString(tr("Host not found")); -
289#endif -
290 } else { -
291 results.setError(QHostInfo::UnknownError); -
292 results.setErrorString(tr("Unknown error")); -
293 } -
294#endif // !defined (QT_NO_GETADDRINFO) -
295 -
296#if defined(QHOSTINFO_DEBUG) -
297 if (results.error() != QHostInfo::NoError) { -
298 qDebug("QHostInfoAgent::fromName(): error #%d %s", -
299 h_errno, results.errorString().toLatin1().constData()); -
300 } else { -
301 QString tmp; -
302 QList<QHostAddress> addresses = results.addresses(); -
303 for (int i = 0; i < addresses.count(); ++i) { -
304 if (i != 0) tmp += ", "; -
305 tmp += addresses.at(i).toString(); -
306 } -
307 qDebug("QHostInfoAgent::fromName(): found %i entries for \"%s\": {%s}", -
308 addresses.count(), hostName.toLatin1().constData(), -
309 tmp.toLatin1().constData()); -
310 } -
311#endif -
312 return results;
executed: return results;
Execution Count:36
36
313} -
314 -
315QString QHostInfo::localHostName() -
316{ -
317 char hostName[512];
executed (the execution status of this line is deduced): char hostName[512];
-
318 if (gethostname(hostName, sizeof(hostName)) == -1)
partially evaluated: gethostname(hostName, sizeof(hostName)) == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
319 return QString();
never executed: return QString();
0
320 hostName[sizeof(hostName) - 1] = '\0';
executed (the execution status of this line is deduced): hostName[sizeof(hostName) - 1] = '\0';
-
321 return QString::fromLocal8Bit(hostName);
executed: return QString::fromLocal8Bit(hostName);
Execution Count:1
1
322} -
323 -
324QString QHostInfo::localDomainName() -
325{ -
326#if !defined(Q_OS_VXWORKS) && !defined(Q_OS_LINUX_ANDROID) -
327 resolveLibrary();
never executed (the execution status of this line is deduced): resolveLibrary();
-
328 if (local_res_ninit) {
never evaluated: local_res_ninit
0
329 // using thread-safe version -
330 res_state_ptr state = res_state_ptr(malloc(sizeof(*state)));
never executed (the execution status of this line is deduced): res_state_ptr state = res_state_ptr(malloc(sizeof(*state)));
-
331 Q_CHECK_PTR(state);
never executed (the execution status of this line is deduced): qt_noop();
-
332 memset(state, 0, sizeof(*state));
never executed (the execution status of this line is deduced): memset(state, 0, sizeof(*state));
-
333 local_res_ninit(state);
never executed (the execution status of this line is deduced): local_res_ninit(state);
-
334 QString domainName = QUrl::fromAce(state->defdname);
never executed (the execution status of this line is deduced): QString domainName = QUrl::fromAce(state->defdname);
-
335 if (domainName.isEmpty())
never evaluated: domainName.isEmpty()
0
336 domainName = QUrl::fromAce(state->dnsrch[0]);
never executed: domainName = QUrl::fromAce(state->dnsrch[0]);
0
337 local_res_nclose(state);
never executed (the execution status of this line is deduced): local_res_nclose(state);
-
338 free(state);
never executed (the execution status of this line is deduced): free(state);
-
339 -
340 return domainName;
never executed: return domainName;
0
341 } -
342 -
343 if (local_res_init && local_res) {
never evaluated: local_res_init
never evaluated: local_res
0
344 // using thread-unsafe version -
345 -
346#if defined(QT_NO_GETADDRINFO) -
347 // We have to call res_init to be sure that _res was initialized -
348 // So, for systems without getaddrinfo (which is thread-safe), we lock the mutex too -
349 QMutexLocker locker(&getHostByNameMutex); -
350#endif -
351 local_res_init();
never executed (the execution status of this line is deduced): local_res_init();
-
352 QString domainName = QUrl::fromAce(local_res->defdname);
never executed (the execution status of this line is deduced): QString domainName = QUrl::fromAce(local_res->defdname);
-
353 if (domainName.isEmpty())
never evaluated: domainName.isEmpty()
0
354 domainName = QUrl::fromAce(local_res->dnsrch[0]);
never executed: domainName = QUrl::fromAce(local_res->dnsrch[0]);
0
355 return domainName;
never executed: return domainName;
0
356 } -
357#endif -
358 // nothing worked, try doing it by ourselves: -
359 QFile resolvconf;
never executed (the execution status of this line is deduced): QFile resolvconf;
-
360#if defined(_PATH_RESCONF) -
361 resolvconf.setFileName(QFile::decodeName(_PATH_RESCONF));
never executed (the execution status of this line is deduced): resolvconf.setFileName(QFile::decodeName("/etc/resolv.conf"));
-
362#else -
363 resolvconf.setFileName(QLatin1String("/etc/resolv.conf")); -
364#endif -
365 if (!resolvconf.open(QIODevice::ReadOnly))
never evaluated: !resolvconf.open(QIODevice::ReadOnly)
0
366 return QString(); // failure
never executed: return QString();
0
367 -
368 QString domainName;
never executed (the execution status of this line is deduced): QString domainName;
-
369 while (!resolvconf.atEnd()) {
never evaluated: !resolvconf.atEnd()
0
370 QByteArray line = resolvconf.readLine().trimmed();
never executed (the execution status of this line is deduced): QByteArray line = resolvconf.readLine().trimmed();
-
371 if (line.startsWith("domain "))
never evaluated: line.startsWith("domain ")
0
372 return QUrl::fromAce(line.mid(sizeof "domain " - 1).trimmed());
never executed: return QUrl::fromAce(line.mid(sizeof "domain " - 1).trimmed());
0
373 -
374 // in case there's no "domain" line, fall back to the first "search" entry -
375 if (domainName.isEmpty() && line.startsWith("search ")) {
never evaluated: domainName.isEmpty()
never evaluated: line.startsWith("search ")
0
376 QByteArray searchDomain = line.mid(sizeof "search " - 1).trimmed();
never executed (the execution status of this line is deduced): QByteArray searchDomain = line.mid(sizeof "search " - 1).trimmed();
-
377 int pos = searchDomain.indexOf(' ');
never executed (the execution status of this line is deduced): int pos = searchDomain.indexOf(' ');
-
378 if (pos != -1)
never evaluated: pos != -1
0
379 searchDomain.truncate(pos);
never executed: searchDomain.truncate(pos);
0
380 domainName = QUrl::fromAce(searchDomain);
never executed (the execution status of this line is deduced): domainName = QUrl::fromAce(searchDomain);
-
381 }
never executed: }
0
382 }
never executed: }
0
383 -
384 // return the fallen-back-to searched domain -
385 return domainName;
never executed: return domainName;
0
386} -
387 -
388QT_END_NAMESPACE -
389 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial