kernel/qhostinfo_unix.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3typedef struct __res_state *res_state_ptr; -
4 -
5typedef int (*res_init_proto)(void); -
6static res_init_proto local_res_init = 0; -
7typedef int (*res_ninit_proto)(res_state_ptr); -
8static res_ninit_proto local_res_ninit = 0; -
9typedef void (*res_nclose_proto)(res_state_ptr); -
10static res_nclose_proto local_res_nclose = 0; -
11static res_state_ptr local_res = 0; -
12 -
13static void resolveLibrary() -
14{ -
15 -
16 QLibrary lib(QLatin1String("resolv")); -
17 if (!lib.load())
partially evaluated: !lib.load()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
18 return;
never executed: return;
0
19 -
20 local_res_init = res_init_proto(lib.resolve("__res_init")); -
21 if (!local_res_init)
partially evaluated: !local_res_init
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
22 local_res_init = res_init_proto(lib.resolve("res_init"));
never executed: local_res_init = res_init_proto(lib.resolve("res_init"));
0
23 -
24 local_res_ninit = res_ninit_proto(lib.resolve("__res_ninit")); -
25 if (!local_res_ninit)
partially evaluated: !local_res_ninit
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
26 local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
never executed: local_res_ninit = res_ninit_proto(lib.resolve("res_ninit"));
0
27 -
28 if (!local_res_ninit) {
partially evaluated: !local_res_ninit
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
29 -
30 local_res = res_state_ptr(lib.resolve("_res")); -
31 } else {
never executed: }
0
32 local_res_nclose = res_nclose_proto(lib.resolve("res_nclose")); -
33 if (!local_res_nclose)
partially evaluated: !local_res_nclose
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
34 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
35 if (!local_res_nclose)
partially evaluated: !local_res_nclose
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
36 local_res_ninit = 0;
never executed: local_res_ninit = 0;
0
37 }
executed: }
Execution Count:13
13
38 -
39} -
40 -
41QHostInfo QHostInfoAgent::fromName(const QString &hostName) -
42{ -
43 QHostInfo results; -
44 -
45 -
46 -
47 -
48 -
49 -
50 -
51 static QBasicAtomicInt triedResolve = { (false) }; -
52 if (!triedResolve.loadAcquire()) {
evaluated: !triedResolve.loadAcquire()
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:23
13-23
53 QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init)); -
54 if (!triedResolve.load()) {
partially evaluated: !triedResolve.load()
TRUEFALSE
yes
Evaluation Count:13
no
Evaluation Count:0
0-13
55 resolveLibrary(); -
56 triedResolve.storeRelease(true); -
57 }
executed: }
Execution Count:13
13
58 }
executed: }
Execution Count:13
13
59 -
60 -
61 if (local_res_init)
partially evaluated: local_res_init
TRUEFALSE
yes
Evaluation Count:36
no
Evaluation Count:0
0-36
62 local_res_init();
executed: local_res_init();
Execution Count:36
36
63 -
64 QHostAddress address; -
65 if (address.setAddress(hostName)) {
partially evaluated: address.setAddress(hostName)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
66 -
67 -
68 -
69 sockaddr_in sa4; -
70 sockaddr_in6 sa6; -
71 sockaddr *sa = 0; -
72 socklen_t saSize = 0; -
73 if (address.protocol() == QAbstractSocket::IPv4Protocol) {
never evaluated: address.protocol() == QAbstractSocket::IPv4Protocol
0
74 sa = (sockaddr *)&sa4; -
75 saSize = sizeof(sa4); -
76 memset(&sa4, 0, sizeof(sa4)); -
77 sa4.sin_family = 2; -
78 sa4.sin_addr.s_addr = (__extension__ ({ register unsigned int __v, __x = (address.toIPv4Address()); 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
79 }
never executed: }
0
80 else { -
81 sa = (sockaddr *)&sa6; -
82 saSize = sizeof(sa6); -
83 memset(&sa6, 0, sizeof(sa6)); -
84 sa6.sin6_family = 10; -
85 memcpy(sa6.sin6_addr.__in6_u.__u6_addr8, address.toIPv6Address().c, sizeof(sa6.sin6_addr.__in6_u.__u6_addr8)); -
86 }
never executed: }
0
87 -
88 char hbuf[1025]; -
89 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
90 results.setHostName(QString::fromLatin1(hbuf));
never executed: results.setHostName(QString::fromLatin1(hbuf));
0
91 -
92 -
93 -
94 -
95 -
96 -
97 -
98 if (results.hostName().isEmpty())
never evaluated: results.hostName().isEmpty()
0
99 results.setHostName(address.toString());
never executed: results.setHostName(address.toString());
0
100 results.setAddresses(QList<QHostAddress>() << address); -
101 return results;
never executed: return results;
0
102 } -
103 -
104 -
105 QByteArray aceHostname = QUrl::toAce(hostName); -
106 results.setHostName(hostName); -
107 if (aceHostname.isEmpty()) {
partially evaluated: aceHostname.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
108 results.setError(QHostInfo::HostNotFound); -
109 results.setErrorString(hostName.isEmpty() ? -
110 QCoreApplication::translate("QHostInfoAgent", "No host name given") : -
111 QCoreApplication::translate("QHostInfoAgent", "Invalid hostname")); -
112 return results;
never executed: return results;
0
113 } -
114 -
115 -
116 -
117 -
118 addrinfo *res = 0; -
119 struct addrinfo hints; -
120 memset(&hints, 0, sizeof(hints)); -
121 hints.ai_family = 0; -
122 -
123 hints.ai_flags = 0x0020; -
124 -
125 -
126 int result = getaddrinfo(aceHostname.constData(), 0, &hints, &res); -
127 -
128 if (result == -1) {
partially evaluated: result == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36
0-36
129 -
130 hints.ai_flags = 0; -
131 result = getaddrinfo(aceHostname.constData(), 0, &hints, &res); -
132 }
never executed: }
0
133 -
134 -
135 if (result == 0) {
evaluated: result == 0
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:5
5-31
136 addrinfo *node = res; -
137 QList<QHostAddress> addresses; -
138 while (node) {
evaluated: node
TRUEFALSE
yes
Evaluation Count:96
yes
Evaluation Count:31
31-96
139 -
140 -
141 -
142 if (node->ai_family == 2) {
evaluated: node->ai_family == 2
TRUEFALSE
yes
Evaluation Count:93
yes
Evaluation Count:3
3-93
143 QHostAddress addr; -
144 addr.setAddress((__extension__ ({ register unsigned int __v, __x = (((sockaddr_in *) node->ai_addr)->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));
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
145 if (!addresses.contains(addr))
evaluated: !addresses.contains(addr)
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:62
31-62
146 addresses.append(addr);
executed: addresses.append(addr);
Execution Count:31
31
147 }
executed: }
Execution Count:93
93
148 else if (node->ai_family == 10) {
partially evaluated: node->ai_family == 10
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
149 QHostAddress addr; -
150 sockaddr_in6 *sa6 = (sockaddr_in6 *) node->ai_addr; -
151 addr.setAddress(sa6->sin6_addr.__in6_u.__u6_addr8); -
152 if (sa6->sin6_scope_id)
partially evaluated: sa6->sin6_scope_id
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
153 addr.setScopeId(QString::number(sa6->sin6_scope_id));
never executed: addr.setScopeId(QString::number(sa6->sin6_scope_id));
0
154 if (!addresses.contains(addr))
evaluated: !addresses.contains(addr)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
155 addresses.append(addr);
executed: addresses.append(addr);
Execution Count:1
1
156 }
executed: }
Execution Count:3
3
157 node = node->ai_next; -
158 }
executed: }
Execution Count:96
96
159 if (addresses.isEmpty() && node == 0) {
partially evaluated: addresses.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:31
never evaluated: node == 0
0-31
160 -
161 -
162 results.setError(QHostInfo::UnknownError); -
163 results.setErrorString(tr("Unknown address type")); -
164 }
never executed: }
0
165 -
166 results.setAddresses(addresses); -
167 freeaddrinfo(res); -
168 } else if (result == -2
executed: }
Execution Count:31
partially evaluated: result == -2
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-31
169 || result == -4
never evaluated: result == -4
0
170 -
171 -
172 || result == -5
never evaluated: result == -5
0
173 -
174 ) { -
175 results.setError(QHostInfo::HostNotFound); -
176 results.setErrorString(tr("Host not found")); -
177 } else {
executed: }
Execution Count:5
5
178 results.setError(QHostInfo::UnknownError); -
179 results.setErrorString(QString::fromLocal8Bit(gai_strerror(result))); -
180 }
never executed: }
0
181 return results;
executed: return results;
Execution Count:36
36
182} -
183 -
184QString QHostInfo::localHostName() -
185{ -
186 char hostName[512]; -
187 if (gethostname(hostName, sizeof(hostName)) == -1)
partially evaluated: gethostname(hostName, sizeof(hostName)) == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
188 return QString();
never executed: return QString();
0
189 hostName[sizeof(hostName) - 1] = '\0'; -
190 return QString::fromLocal8Bit(hostName);
executed: return QString::fromLocal8Bit(hostName);
Execution Count:1
1
191} -
192 -
193QString QHostInfo::localDomainName() -
194{ -
195 -
196 resolveLibrary(); -
197 if (local_res_ninit) {
never evaluated: local_res_ninit
0
198 -
199 res_state_ptr state = res_state_ptr(malloc(sizeof(*state))); -
200 qt_noop(); -
201 memset(state, 0, sizeof(*state)); -
202 local_res_ninit(state); -
203 QString domainName = QUrl::fromAce(state->defdname); -
204 if (domainName.isEmpty())
never evaluated: domainName.isEmpty()
0
205 domainName = QUrl::fromAce(state->dnsrch[0]);
never executed: domainName = QUrl::fromAce(state->dnsrch[0]);
0
206 local_res_nclose(state); -
207 free(state); -
208 -
209 return domainName;
never executed: return domainName;
0
210 } -
211 -
212 if (local_res_init && local_res) {
never evaluated: local_res_init
never evaluated: local_res
0
213 -
214 -
215 -
216 -
217 -
218 -
219 -
220 local_res_init(); -
221 QString domainName = QUrl::fromAce(local_res->defdname); -
222 if (domainName.isEmpty())
never evaluated: domainName.isEmpty()
0
223 domainName = QUrl::fromAce(local_res->dnsrch[0]);
never executed: domainName = QUrl::fromAce(local_res->dnsrch[0]);
0
224 return domainName;
never executed: return domainName;
0
225 } -
226 -
227 -
228 QFile resolvconf; -
229 -
230 resolvconf.setFileName(QFile::decodeName("/etc/resolv.conf")); -
231 -
232 -
233 -
234 if (!resolvconf.open(QIODevice::ReadOnly))
never evaluated: !resolvconf.open(QIODevice::ReadOnly)
0
235 return QString();
never executed: return QString();
0
236 -
237 QString domainName; -
238 while (!resolvconf.atEnd()) {
never evaluated: !resolvconf.atEnd()
0
239 QByteArray line = resolvconf.readLine().trimmed(); -
240 if (line.startsWith("domain "))
never evaluated: line.startsWith("domain ")
0
241 return QUrl::fromAce(line.mid(sizeof "domain " - 1).trimmed());
never executed: return QUrl::fromAce(line.mid(sizeof "domain " - 1).trimmed());
0
242 -
243 -
244 if (domainName.isEmpty() && line.startsWith("search ")) {
never evaluated: domainName.isEmpty()
never evaluated: line.startsWith("search ")
0
245 QByteArray searchDomain = line.mid(sizeof "search " - 1).trimmed(); -
246 int pos = searchDomain.indexOf(' '); -
247 if (pos != -1)
never evaluated: pos != -1
0
248 searchDomain.truncate(pos);
never executed: searchDomain.truncate(pos);
0
249 domainName = QUrl::fromAce(searchDomain); -
250 }
never executed: }
0
251 }
never executed: }
0
252 -
253 -
254 return domainName;
never executed: return domainName;
0
255} -
256 -
257 -
258 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial