1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// tests/dns1.c
|
4 |
|
|
//
|
5 |
|
|
// Simple test of DNS client support
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): andrew.lunn
|
43 |
|
|
// Contributors: andrew.lunn, jskov
|
44 |
|
|
// Date: 2001-09-18
|
45 |
|
|
// Purpose:
|
46 |
|
|
// Description: Test DNS functions. Note that the structure below that
|
47 |
|
|
// control what addresses the test uses. These must be
|
48 |
|
|
// changed to match the particular testing network in which
|
49 |
|
|
// the test is to be run.
|
50 |
|
|
//
|
51 |
|
|
//####DESCRIPTIONEND####
|
52 |
|
|
//
|
53 |
|
|
//==========================================================================
|
54 |
|
|
#include <pkgconf/ns_dns.h>
|
55 |
|
|
|
56 |
|
|
#include <network.h>
|
57 |
|
|
#include <netdb.h>
|
58 |
|
|
|
59 |
|
|
#include <arpa/inet.h>
|
60 |
|
|
|
61 |
|
|
#include <cyg/infra/testcase.h>
|
62 |
|
|
|
63 |
|
|
#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + 0x1000)
|
64 |
|
|
static char stack[STACK_SIZE];
|
65 |
|
|
static cyg_thread thread_data;
|
66 |
|
|
static cyg_handle_t thread_handle;
|
67 |
|
|
|
68 |
|
|
struct test_info_s {
|
69 |
|
|
char * dns_server_v4;
|
70 |
|
|
char * dns_server_v6;
|
71 |
|
|
char * domain_name;
|
72 |
|
|
char * hostname_v4;
|
73 |
|
|
char * cname_v4;
|
74 |
|
|
char * ip_addr_v4;
|
75 |
|
|
char * hostname_v6;
|
76 |
|
|
char * cname_v6;
|
77 |
|
|
char * ip_addr_v6;
|
78 |
|
|
char * hostname_v46;
|
79 |
|
|
char * cname_v46;
|
80 |
|
|
char * ip_addr_v46_v4;
|
81 |
|
|
char * ip_addr_v46_v6;
|
82 |
|
|
};
|
83 |
|
|
|
84 |
|
|
struct test_info_s test_info[] = {
|
85 |
|
|
#if CYGPKG_NS_DNS_TESTS_ELSIS
|
86 |
|
|
{
|
87 |
|
|
"194.249.198.85",
|
88 |
|
|
NULL,
|
89 |
|
|
"test.ecos.",
|
90 |
|
|
"hostnamev4",
|
91 |
|
|
"cnamev4",
|
92 |
|
|
"192.168.88.1",
|
93 |
|
|
"hostnamev6",
|
94 |
|
|
"cnamev6",
|
95 |
|
|
"fec0::88:4:3:2:1",
|
96 |
|
|
"hostnamev46",
|
97 |
|
|
"cnamev46",
|
98 |
|
|
"192.168.88.2",
|
99 |
|
|
"fec0::88:4:3:2:2"
|
100 |
|
|
},
|
101 |
|
|
#endif
|
102 |
|
|
#ifdef CYGPKG_NS_DNS_TESTS_LUNN
|
103 |
|
|
{
|
104 |
|
|
"192.168.10.1",
|
105 |
|
|
"3ffe:bc0:8000::839",
|
106 |
|
|
"test.ecos.",
|
107 |
|
|
"hostnamev4",
|
108 |
|
|
"cnamev4",
|
109 |
|
|
"192.168.88.1",
|
110 |
|
|
"hostnamev6",
|
111 |
|
|
"cnamev6",
|
112 |
|
|
"fec0::88:4:3:2:1",
|
113 |
|
|
"hostnamev46",
|
114 |
|
|
"cnamev46",
|
115 |
|
|
"192.168.88.2",
|
116 |
|
|
"fec0::88:4:3:2:2"
|
117 |
|
|
}
|
118 |
|
|
#endif
|
119 |
|
|
};
|
120 |
|
|
|
121 |
|
|
char * familytoa(int family) {
|
122 |
|
|
|
123 |
|
|
switch (family) {
|
124 |
|
|
case AF_INET:
|
125 |
|
|
return "AF_INET";
|
126 |
|
|
#ifdef CYGPKG_NET_INET6
|
127 |
|
|
case AF_INET6:
|
128 |
|
|
return "AF_INET6";
|
129 |
|
|
#endif
|
130 |
|
|
default:
|
131 |
|
|
return "Unknown";
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
void dns_test(struct test_info_s *info) {
|
136 |
|
|
struct in_addr addr;
|
137 |
|
|
struct hostent *hent;
|
138 |
|
|
char dn[256];
|
139 |
|
|
char name[256];
|
140 |
|
|
char cname[256];
|
141 |
|
|
char buffer[256];
|
142 |
|
|
char buff[64];
|
143 |
|
|
size_t hostlen = 128;
|
144 |
|
|
char host[hostlen];
|
145 |
|
|
struct addrinfo * res;
|
146 |
|
|
struct addrinfo hints;
|
147 |
|
|
struct sockaddr_in sa4;
|
148 |
|
|
#ifdef CYGPKG_NET_INET6
|
149 |
|
|
struct sockaddr_in6 sa6;
|
150 |
|
|
struct addrinfo *ai4, *ai6;
|
151 |
|
|
#endif
|
152 |
|
|
int error;
|
153 |
|
|
|
154 |
|
|
if (inet_pton(AF_INET, info->dns_server_v4, (void *)&addr) < 0) {
|
155 |
|
|
CYG_TEST_FAIL_FINISH("Error with DNS server address");
|
156 |
|
|
}
|
157 |
|
|
cyg_dns_res_init(&addr);
|
158 |
|
|
|
159 |
|
|
setdomainname(NULL,0);
|
160 |
|
|
|
161 |
|
|
inet_aton(info->ip_addr_v4, &addr);
|
162 |
|
|
strcpy(name,info->hostname_v4);
|
163 |
|
|
strcat(name,".");
|
164 |
|
|
strcat(name,info->domain_name);
|
165 |
|
|
strcpy(cname,info->cname_v4);
|
166 |
|
|
strcat(cname,".");
|
167 |
|
|
strcat(cname,info->domain_name);
|
168 |
|
|
|
169 |
|
|
// Lookup the IPv4 FQDN hostname
|
170 |
|
|
hent = gethostbyname(name);
|
171 |
|
|
if (hent != NULL) {
|
172 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s>",
|
173 |
|
|
name,
|
174 |
|
|
hent->h_name,
|
175 |
|
|
inet_ntoa(*(struct in_addr *)hent->h_addr));
|
176 |
|
|
CYG_TEST_INFO(buffer);
|
177 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void*)&addr,
|
178 |
|
|
(void*)(hent->h_addr),
|
179 |
|
|
sizeof(struct in_addr))),
|
180 |
|
|
"IPv4 FQDN hostname address");
|
181 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, hent->h_name)),
|
182 |
|
|
"IPv4 FQDN hostname name");
|
183 |
|
|
} else {
|
184 |
|
|
diag_sprintf(buffer,"IPv4 FQDN hostname: error %s",
|
185 |
|
|
hstrerror(h_errno));
|
186 |
|
|
CYG_TEST_FAIL(buffer);
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
// Lookup the IPv4 FQDN cname
|
190 |
|
|
hent = gethostbyname(cname);
|
191 |
|
|
if (hent != NULL) {
|
192 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s>",
|
193 |
|
|
cname,
|
194 |
|
|
hent->h_name,
|
195 |
|
|
inet_ntoa(*(struct in_addr *)hent->h_addr));
|
196 |
|
|
CYG_TEST_INFO(buffer);
|
197 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void*)&addr,
|
198 |
|
|
(void*)(hent->h_addr),
|
199 |
|
|
sizeof(struct in_addr))),
|
200 |
|
|
"IPv4 FQDN cname address");
|
201 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, hent->h_name)),
|
202 |
|
|
"IPv4 FQDN hostname name");
|
203 |
|
|
} else {
|
204 |
|
|
diag_sprintf(buffer,"IPv4 FQDN cname: error %s", hstrerror(h_errno));
|
205 |
|
|
CYG_TEST_FAIL(buffer);
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
// Lookup the IP address as a string. This does not require a DNS
|
209 |
|
|
// lookup. Just turn the value into binary
|
210 |
|
|
hent = gethostbyname(info->ip_addr_v4);
|
211 |
|
|
if (hent != NULL) {
|
212 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s>",
|
213 |
|
|
info->ip_addr_v4,
|
214 |
|
|
hent->h_name,
|
215 |
|
|
inet_ntoa(*(struct in_addr *)hent->h_addr));
|
216 |
|
|
CYG_TEST_INFO(buffer);
|
217 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void*)&addr,
|
218 |
|
|
(void*)(hent->h_addr),
|
219 |
|
|
sizeof(struct in_addr))),
|
220 |
|
|
"IPv4 IP address");
|
221 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(info->ip_addr_v4, hent->h_name)),
|
222 |
|
|
"IPv4 IP address name");
|
223 |
|
|
|
224 |
|
|
} else {
|
225 |
|
|
diag_sprintf(buffer,"IPv4 IP address: error %s", hstrerror(h_errno));
|
226 |
|
|
CYG_TEST_FAIL(buffer);
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
// Reverse lookup the IPv4 address, expect the FQDN hostname
|
230 |
|
|
hent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
|
231 |
|
|
if (hent != NULL) {
|
232 |
|
|
inet_ntop(AF_INET,(void *)&addr, buff, sizeof(buff));
|
233 |
|
|
diag_sprintf(buffer,"Reverse lookup %s: Result <%s is %s>",
|
234 |
|
|
buff,
|
235 |
|
|
hent->h_name,
|
236 |
|
|
inet_ntoa(*(struct in_addr *)hent->h_addr));
|
237 |
|
|
CYG_TEST_INFO(buffer);
|
238 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void*)&addr,
|
239 |
|
|
(void*)(hent->h_addr),
|
240 |
|
|
sizeof(struct in_addr))),
|
241 |
|
|
"Reverse lookup IPv4 IP address");
|
242 |
|
|
|
243 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, hent->h_name)),
|
244 |
|
|
"Reverse lookup IPv4 IP address name");
|
245 |
|
|
} else {
|
246 |
|
|
diag_sprintf(buffer,"Reverse lookup IPv4 IP address: error %s",
|
247 |
|
|
hstrerror(h_errno));
|
248 |
|
|
CYG_TEST_FAIL(buffer);
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
// Setup a domainname. We now don't have to use fully qualified
|
252 |
|
|
// domain names
|
253 |
|
|
setdomainname(info->domain_name, strlen(info->domain_name));
|
254 |
|
|
getdomainname(dn, sizeof(dn));
|
255 |
|
|
CYG_TEST_PASS_FAIL(0 == strcmp(info->domain_name, dn),
|
256 |
|
|
"{get|set}domainname");
|
257 |
|
|
|
258 |
|
|
// Make sure FQDN still work
|
259 |
|
|
strcpy(name,info->hostname_v4);
|
260 |
|
|
strcat(name,".");
|
261 |
|
|
strcat(name,info->domain_name);
|
262 |
|
|
|
263 |
|
|
hent = gethostbyname(name);
|
264 |
|
|
if (hent != NULL) {
|
265 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s>",
|
266 |
|
|
name,
|
267 |
|
|
hent->h_name,
|
268 |
|
|
inet_ntoa(*(struct in_addr *)hent->h_addr));
|
269 |
|
|
CYG_TEST_INFO(buffer);
|
270 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void*)&addr,
|
271 |
|
|
(void*)(hent->h_addr),
|
272 |
|
|
sizeof(struct in_addr))),
|
273 |
|
|
"IPv4 FQDN hostname address");
|
274 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, hent->h_name)),
|
275 |
|
|
"IPv4 FQDN hostname name");
|
276 |
|
|
} else {
|
277 |
|
|
diag_sprintf(buffer,"IPv4 FQDN hostname: error %s",
|
278 |
|
|
hstrerror(h_errno));
|
279 |
|
|
CYG_TEST_FAIL(buffer);
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
// Now just the hostname
|
283 |
|
|
hent = gethostbyname(info->hostname_v4);
|
284 |
|
|
if (hent != NULL) {
|
285 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s>",
|
286 |
|
|
info->hostname_v4,
|
287 |
|
|
hent->h_name,
|
288 |
|
|
inet_ntoa(*(struct in_addr *)hent->h_addr));
|
289 |
|
|
CYG_TEST_INFO(buffer);
|
290 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void*)&addr,
|
291 |
|
|
(void*)(hent->h_addr),
|
292 |
|
|
sizeof(struct in_addr))),
|
293 |
|
|
"IPv4 hostname address");
|
294 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, hent->h_name)),
|
295 |
|
|
"IPv4 hostname name");
|
296 |
|
|
} else {
|
297 |
|
|
diag_sprintf(buffer,"IPv4 hostname: error %s", hstrerror(h_errno));
|
298 |
|
|
CYG_TEST_FAIL(buffer);
|
299 |
|
|
}
|
300 |
|
|
|
301 |
|
|
// Run the same tests as above, but this time use getaddrinfo and
|
302 |
|
|
// getnameinfo.
|
303 |
|
|
setdomainname(NULL,0);
|
304 |
|
|
|
305 |
|
|
memset(&hints,0,sizeof(hints));
|
306 |
|
|
hints.ai_flags = AI_CANONNAME;
|
307 |
|
|
memset(&sa4,0,sizeof(sa4));
|
308 |
|
|
memcpy(&sa4.sin_addr, &addr, sizeof(addr));
|
309 |
|
|
sa4.sin_family=AF_INET;
|
310 |
|
|
sa4.sin_len = sizeof(sa4);
|
311 |
|
|
|
312 |
|
|
// Lookup the IPv4 FQDN hostname
|
313 |
|
|
error = getaddrinfo(name, NULL, &hints, &res);
|
314 |
|
|
|
315 |
|
|
if (error == EAI_NONE) {
|
316 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
317 |
|
|
buff, sizeof(buff),
|
318 |
|
|
NULL,0,NI_NUMERICHOST);
|
319 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
320 |
|
|
name,
|
321 |
|
|
res->ai_canonname,
|
322 |
|
|
familytoa(res->ai_family),
|
323 |
|
|
buff);
|
324 |
|
|
CYG_TEST_INFO(buffer);
|
325 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
326 |
|
|
(void*)res->ai_addr,
|
327 |
|
|
sizeof(sa4))) &&
|
328 |
|
|
(res->ai_family == AF_INET),
|
329 |
|
|
"IPv4 FQDN hostname address");
|
330 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
331 |
|
|
"IPv4 FQDN hostname name");
|
332 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
333 |
|
|
"IPv4 FQDN hostname one result");
|
334 |
|
|
freeaddrinfo(res);
|
335 |
|
|
} else {
|
336 |
|
|
diag_sprintf(buffer,"IPv4 FQDN hostname: error %s",
|
337 |
|
|
gai_strerror(error));
|
338 |
|
|
CYG_TEST_FAIL(buffer);
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
// Lookup the IPv4 FQDN cname
|
342 |
|
|
error = getaddrinfo(cname, NULL, &hints, &res);
|
343 |
|
|
|
344 |
|
|
if (error == EAI_NONE) {
|
345 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
346 |
|
|
buff, sizeof(buff),
|
347 |
|
|
NULL,0,NI_NUMERICHOST);
|
348 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
349 |
|
|
cname,
|
350 |
|
|
res->ai_canonname,
|
351 |
|
|
familytoa(res->ai_family),
|
352 |
|
|
buff);
|
353 |
|
|
CYG_TEST_INFO(buffer);
|
354 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
355 |
|
|
(void*)res->ai_addr,
|
356 |
|
|
sizeof(sa4))) &&
|
357 |
|
|
(res->ai_family == AF_INET),
|
358 |
|
|
"IPv4 FQDN cname address");
|
359 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
360 |
|
|
"IPv4 FQDN cname name");
|
361 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
362 |
|
|
"IPv4 FQDN cname one result");
|
363 |
|
|
freeaddrinfo(res);
|
364 |
|
|
} else {
|
365 |
|
|
diag_sprintf(buffer,"IPv4 FQDN cname: error %s", gai_strerror(error));
|
366 |
|
|
CYG_TEST_FAIL(buffer);
|
367 |
|
|
}
|
368 |
|
|
|
369 |
|
|
// Lookup the IP address as a string. This does not require a DNS
|
370 |
|
|
// lookup. Just turn the value into binary
|
371 |
|
|
hints.ai_flags = AI_NUMERICHOST;
|
372 |
|
|
error = getaddrinfo(info->ip_addr_v4, NULL, &hints, &res);
|
373 |
|
|
|
374 |
|
|
if (error == EAI_NONE) {
|
375 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
376 |
|
|
buff, sizeof(buff),
|
377 |
|
|
NULL,0,NI_NUMERICHOST);
|
378 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s %s>",
|
379 |
|
|
info->ip_addr_v4,
|
380 |
|
|
familytoa(res->ai_family),
|
381 |
|
|
buff);
|
382 |
|
|
CYG_TEST_INFO(buffer);
|
383 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
384 |
|
|
(void*)res->ai_addr,
|
385 |
|
|
sizeof(sa4))) &&
|
386 |
|
|
(res->ai_family == AF_INET),
|
387 |
|
|
"IPv4 IP address");
|
388 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_canonname),
|
389 |
|
|
"IPv4 IP address name");
|
390 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
391 |
|
|
"IPv4 IP address one result");
|
392 |
|
|
// Don't free results - use for next test.
|
393 |
|
|
} else {
|
394 |
|
|
diag_sprintf(buffer,"IPv4 IP address: error %s", gai_strerror(error));
|
395 |
|
|
CYG_TEST_FAIL(buffer);
|
396 |
|
|
}
|
397 |
|
|
|
398 |
|
|
// Reverse lookup the IPv4 address, expect the FQDN hostname
|
399 |
|
|
error = getnameinfo(res->ai_addr,res->ai_addrlen,
|
400 |
|
|
host, hostlen, NULL, 0, 0);
|
401 |
|
|
if (error == EAI_NONE) {
|
402 |
|
|
diag_sprintf(buffer, "IPv4 Reverse lookup FDQN %s: Result %s",
|
403 |
|
|
info->ip_addr_v4,
|
404 |
|
|
host);
|
405 |
|
|
CYG_TEST_INFO(buffer);
|
406 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, host)),
|
407 |
|
|
"IPv4 Reverse lookup FQDN");
|
408 |
|
|
} else {
|
409 |
|
|
diag_sprintf(buffer,"IPv4 Reverse lookup FQDN: error %s",
|
410 |
|
|
gai_strerror(error));
|
411 |
|
|
CYG_TEST_FAIL(buffer);
|
412 |
|
|
}
|
413 |
|
|
// Reverse lookup the IPv4 address, expect just the hostname part
|
414 |
|
|
error = getnameinfo(res->ai_addr,res->ai_addrlen,
|
415 |
|
|
host, hostlen, NULL, 0, NI_NOFQDN);
|
416 |
|
|
if (error == EAI_NONE) {
|
417 |
|
|
diag_sprintf(buffer, "IPv4 Reverse lookup hostname part %s: Result %s",
|
418 |
|
|
info->ip_addr_v4,
|
419 |
|
|
host);
|
420 |
|
|
CYG_TEST_INFO(buffer);
|
421 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(info->hostname_v4, host)),
|
422 |
|
|
"IPv4 Reverse lookup hostname part");
|
423 |
|
|
} else {
|
424 |
|
|
diag_sprintf(buffer,"IPv4 Reverse lookup hostname part: error %s",
|
425 |
|
|
gai_strerror(error));
|
426 |
|
|
CYG_TEST_FAIL(buffer);
|
427 |
|
|
}
|
428 |
|
|
freeaddrinfo(res);
|
429 |
|
|
|
430 |
|
|
// Setup a domainname. We now don't have to use fully qualified
|
431 |
|
|
// domain names
|
432 |
|
|
setdomainname(info->domain_name, strlen(info->domain_name));
|
433 |
|
|
getdomainname(dn, sizeof(dn));
|
434 |
|
|
CYG_TEST_PASS_FAIL(0 == strcmp(info->domain_name, dn),
|
435 |
|
|
"{get|set}domainname");
|
436 |
|
|
|
437 |
|
|
// Lookup the IPv4 FQDN hostname to make sure it still works
|
438 |
|
|
hints.ai_flags = AI_CANONNAME;
|
439 |
|
|
error = getaddrinfo(name, NULL, &hints, &res);
|
440 |
|
|
|
441 |
|
|
if (error == EAI_NONE) {
|
442 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
443 |
|
|
buff, sizeof(buff),
|
444 |
|
|
NULL,0,NI_NUMERICHOST);
|
445 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
446 |
|
|
name,
|
447 |
|
|
res->ai_canonname,
|
448 |
|
|
familytoa(res->ai_family),
|
449 |
|
|
buff);
|
450 |
|
|
CYG_TEST_INFO(buffer);
|
451 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
452 |
|
|
(void*)res->ai_addr,
|
453 |
|
|
sizeof(sa4))) &&
|
454 |
|
|
(res->ai_family == AF_INET),
|
455 |
|
|
"IPv4 FQDN hostname address");
|
456 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
457 |
|
|
"IPv4 FQDN hostname name");
|
458 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
459 |
|
|
"IPv4 FQDN hostname one result");
|
460 |
|
|
freeaddrinfo(res);
|
461 |
|
|
} else {
|
462 |
|
|
diag_sprintf(buffer,"IPv4 FQDN hostname: error %s",
|
463 |
|
|
gai_strerror(error));
|
464 |
|
|
CYG_TEST_FAIL(buffer);
|
465 |
|
|
}
|
466 |
|
|
|
467 |
|
|
// Now the host name without the domain name
|
468 |
|
|
error = getaddrinfo(info->hostname_v4, NULL, &hints, &res);
|
469 |
|
|
|
470 |
|
|
if (error == EAI_NONE) {
|
471 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
472 |
|
|
buff, sizeof(buff),
|
473 |
|
|
NULL,0,NI_NUMERICHOST);
|
474 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
475 |
|
|
info->hostname_v4,
|
476 |
|
|
res->ai_canonname,
|
477 |
|
|
familytoa(res->ai_family),
|
478 |
|
|
buff);
|
479 |
|
|
CYG_TEST_INFO(buffer);
|
480 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
481 |
|
|
(void*)res->ai_addr,
|
482 |
|
|
sizeof(sa4))) &&
|
483 |
|
|
(res->ai_family == AF_INET),
|
484 |
|
|
"IPv4 hostname address");
|
485 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
486 |
|
|
"IPv4 hostname name");
|
487 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
488 |
|
|
"IPv4 hostname one result");
|
489 |
|
|
freeaddrinfo(res);
|
490 |
|
|
} else {
|
491 |
|
|
diag_sprintf(buffer,"IPv4 hostname: error %s",
|
492 |
|
|
gai_strerror(error));
|
493 |
|
|
CYG_TEST_FAIL(buffer);
|
494 |
|
|
}
|
495 |
|
|
#ifdef CYGPKG_NET_INET6
|
496 |
|
|
// Check we have the needed information for the IPv6 tests
|
497 |
|
|
if (!info->hostname_v6 || !info->cname_v6 || !info->ip_addr_v6) {
|
498 |
|
|
return;
|
499 |
|
|
}
|
500 |
|
|
|
501 |
|
|
setdomainname(NULL,0);
|
502 |
|
|
|
503 |
|
|
strcpy(name,info->hostname_v6);
|
504 |
|
|
strcat(name,".");
|
505 |
|
|
strcat(name,info->domain_name);
|
506 |
|
|
strcpy(cname,info->cname_v6);
|
507 |
|
|
strcat(cname,".");
|
508 |
|
|
strcat(cname,info->domain_name);
|
509 |
|
|
|
510 |
|
|
memset(&sa6,0,sizeof(sa6));
|
511 |
|
|
sa6.sin6_family = AF_INET6;
|
512 |
|
|
sa6.sin6_len = sizeof(sa6);
|
513 |
|
|
inet_pton(AF_INET6, info->ip_addr_v6, (void *)&sa6.sin6_addr);
|
514 |
|
|
|
515 |
|
|
// Lookup the IPv6 FQDN hostname
|
516 |
|
|
error = getaddrinfo(name, NULL, &hints, &res);
|
517 |
|
|
|
518 |
|
|
if (error == EAI_NONE) {
|
519 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
520 |
|
|
buff, sizeof(buff),
|
521 |
|
|
NULL,0,NI_NUMERICHOST);
|
522 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
523 |
|
|
name,
|
524 |
|
|
res->ai_canonname,
|
525 |
|
|
familytoa(res->ai_family),
|
526 |
|
|
buff);
|
527 |
|
|
CYG_TEST_INFO(buffer);
|
528 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
529 |
|
|
(void*)res->ai_addr,
|
530 |
|
|
sizeof(sa6))) &&
|
531 |
|
|
(res->ai_family == AF_INET6),
|
532 |
|
|
"IPv6 FQDN hostname address");
|
533 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
534 |
|
|
"IPv6 FQDN hostname name");
|
535 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
536 |
|
|
"IPv6 FQDN hostname one result");
|
537 |
|
|
freeaddrinfo(res);
|
538 |
|
|
} else {
|
539 |
|
|
diag_sprintf(buffer,"IPv6 FQDN hostname: error %s",
|
540 |
|
|
gai_strerror(error));
|
541 |
|
|
CYG_TEST_FAIL(buffer);
|
542 |
|
|
}
|
543 |
|
|
|
544 |
|
|
// Lookup the IPv6 FQDN cname
|
545 |
|
|
error = getaddrinfo(cname, NULL, &hints, &res);
|
546 |
|
|
|
547 |
|
|
if (error == EAI_NONE) {
|
548 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
549 |
|
|
buff, sizeof(buff),
|
550 |
|
|
NULL,0,NI_NUMERICHOST);
|
551 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
552 |
|
|
cname,
|
553 |
|
|
res->ai_canonname,
|
554 |
|
|
familytoa(res->ai_family),
|
555 |
|
|
buff);
|
556 |
|
|
CYG_TEST_INFO(buffer);
|
557 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
558 |
|
|
(void*)res->ai_addr,
|
559 |
|
|
sizeof(sa6))) &&
|
560 |
|
|
(res->ai_family == AF_INET6),
|
561 |
|
|
"IPv6 FQDN cname address");
|
562 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
563 |
|
|
"IPv6 FQDN cname name");
|
564 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
565 |
|
|
"IPv6 FQDN cname one result");
|
566 |
|
|
freeaddrinfo(res);
|
567 |
|
|
} else {
|
568 |
|
|
diag_sprintf(buffer,"IPv6 FQDN cname: error %s",
|
569 |
|
|
gai_strerror(error));
|
570 |
|
|
CYG_TEST_FAIL(buffer);
|
571 |
|
|
}
|
572 |
|
|
|
573 |
|
|
// Lookup the IP address as a string. This does not require a DNS
|
574 |
|
|
// lookup. Just turn the value into binary
|
575 |
|
|
hints.ai_flags = AI_NUMERICHOST;
|
576 |
|
|
error = getaddrinfo(info->ip_addr_v6, NULL, &hints, &res);
|
577 |
|
|
|
578 |
|
|
if (error == EAI_NONE) {
|
579 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
580 |
|
|
buff, sizeof(buff),
|
581 |
|
|
NULL,0,NI_NUMERICHOST);
|
582 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s %s>",
|
583 |
|
|
info->ip_addr_v6,
|
584 |
|
|
familytoa(res->ai_family),
|
585 |
|
|
buff);
|
586 |
|
|
CYG_TEST_INFO(buffer);
|
587 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
588 |
|
|
(void*)res->ai_addr,
|
589 |
|
|
sizeof(sa6))) &&
|
590 |
|
|
(res->ai_family == AF_INET6),
|
591 |
|
|
"IPv6 IP address");
|
592 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_canonname),
|
593 |
|
|
"IPv6 IP address name");
|
594 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
595 |
|
|
"IPv6 IP address one result");
|
596 |
|
|
// Don't free the result, use it in the next tests
|
597 |
|
|
} else {
|
598 |
|
|
diag_sprintf(buffer,"IPv6 IP address: error %s", gai_strerror(error));
|
599 |
|
|
CYG_TEST_FAIL(buffer);
|
600 |
|
|
}
|
601 |
|
|
|
602 |
|
|
// Reverse lookup the IPv6 address, expect the FQDN hostname
|
603 |
|
|
error = getnameinfo(res->ai_addr,res->ai_addrlen,
|
604 |
|
|
host, hostlen, NULL, 0, 0);
|
605 |
|
|
if (error == EAI_NONE) {
|
606 |
|
|
diag_sprintf(buffer, "IPv6 Reverse lookup FDQN %s: Result %s",
|
607 |
|
|
info->ip_addr_v6,
|
608 |
|
|
host);
|
609 |
|
|
CYG_TEST_INFO(buffer);
|
610 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, host)),
|
611 |
|
|
"IPv6 Reverse lookup FQDN");
|
612 |
|
|
} else {
|
613 |
|
|
diag_sprintf(buffer,"IPv6 Reverse lookup FQDN: error %s",
|
614 |
|
|
gai_strerror(error));
|
615 |
|
|
CYG_TEST_FAIL(buffer);
|
616 |
|
|
}
|
617 |
|
|
// Reverse lookup the IPv6 address, expect just the hostname part
|
618 |
|
|
error = getnameinfo(res->ai_addr,res->ai_addrlen,
|
619 |
|
|
host, hostlen, NULL, 0, NI_NOFQDN);
|
620 |
|
|
if (error == EAI_NONE) {
|
621 |
|
|
diag_sprintf(buffer, "IPv6 Reverse lookup hostname part %s: Result %s",
|
622 |
|
|
info->ip_addr_v6,
|
623 |
|
|
host);
|
624 |
|
|
CYG_TEST_INFO(buffer);
|
625 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(info->hostname_v6, host)),
|
626 |
|
|
"IPv6 Reverse lookup hostname part");
|
627 |
|
|
} else {
|
628 |
|
|
diag_sprintf(buffer,"IPv6 Reverse lookup hostname part: error %s",
|
629 |
|
|
gai_strerror(error));
|
630 |
|
|
CYG_TEST_FAIL(buffer);
|
631 |
|
|
}
|
632 |
|
|
freeaddrinfo(res);
|
633 |
|
|
|
634 |
|
|
// Setup a domainname. We now don't have to use fully qualified
|
635 |
|
|
// domain names
|
636 |
|
|
setdomainname(info->domain_name, strlen(info->domain_name));
|
637 |
|
|
getdomainname(dn, sizeof(dn));
|
638 |
|
|
CYG_TEST_PASS_FAIL(0 == strcmp(info->domain_name, dn),
|
639 |
|
|
"{get|set}domainname");
|
640 |
|
|
|
641 |
|
|
// Lookup the IPv6 FQDN hostname to make sure it still works
|
642 |
|
|
hints.ai_flags = AI_CANONNAME;
|
643 |
|
|
error = getaddrinfo(name, NULL, &hints, &res);
|
644 |
|
|
|
645 |
|
|
if (error == EAI_NONE) {
|
646 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
647 |
|
|
buff, sizeof(buff),
|
648 |
|
|
NULL,0,NI_NUMERICHOST);
|
649 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
650 |
|
|
name,
|
651 |
|
|
res->ai_canonname,
|
652 |
|
|
familytoa(res->ai_family),
|
653 |
|
|
buff);
|
654 |
|
|
CYG_TEST_INFO(buffer);
|
655 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
656 |
|
|
(void*)res->ai_addr,
|
657 |
|
|
sizeof(sa6))) &&
|
658 |
|
|
(res->ai_family == AF_INET6),
|
659 |
|
|
"IPv6 FQDN hostname address");
|
660 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
661 |
|
|
"IPv6 FQDN hostname name");
|
662 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
663 |
|
|
"IPv6 FQDN hostname one result");
|
664 |
|
|
freeaddrinfo(res);
|
665 |
|
|
} else {
|
666 |
|
|
diag_sprintf(buffer,"IPv6 FQDN hostname: error %s",
|
667 |
|
|
gai_strerror(error));
|
668 |
|
|
CYG_TEST_FAIL(buffer);
|
669 |
|
|
}
|
670 |
|
|
|
671 |
|
|
// Now the host name without the domain name
|
672 |
|
|
error = getaddrinfo(info->hostname_v6, NULL, &hints, &res);
|
673 |
|
|
|
674 |
|
|
if (error == EAI_NONE) {
|
675 |
|
|
getnameinfo(res->ai_addr, res->ai_addrlen,
|
676 |
|
|
buff, sizeof(buff),
|
677 |
|
|
NULL,0,NI_NUMERICHOST);
|
678 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
679 |
|
|
info->hostname_v6,
|
680 |
|
|
res->ai_canonname,
|
681 |
|
|
familytoa(res->ai_family),
|
682 |
|
|
buff);
|
683 |
|
|
CYG_TEST_INFO(buffer);
|
684 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
685 |
|
|
(void*)res->ai_addr,
|
686 |
|
|
sizeof(sa6))) &&
|
687 |
|
|
(res->ai_family == AF_INET6),
|
688 |
|
|
"IPv6 hostname address");
|
689 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, res->ai_canonname)),
|
690 |
|
|
"IPv6 hostname name");
|
691 |
|
|
CYG_TEST_PASS_FAIL((NULL == res->ai_next),
|
692 |
|
|
"IPv6 hostname one result");
|
693 |
|
|
freeaddrinfo(res);
|
694 |
|
|
} else {
|
695 |
|
|
diag_sprintf(buffer,"IPv6 hostname: error %s",
|
696 |
|
|
gai_strerror(error));
|
697 |
|
|
CYG_TEST_FAIL(buffer);
|
698 |
|
|
}
|
699 |
|
|
|
700 |
|
|
// Check if we have the information to do tests which result in two
|
701 |
|
|
// answers, an AF_INET and an AF_INET6
|
702 |
|
|
if (!info->hostname_v46 || !info->cname_v46 ||
|
703 |
|
|
!info->ip_addr_v46_v4 || !info->ip_addr_v46_v6 ) {
|
704 |
|
|
return;
|
705 |
|
|
}
|
706 |
|
|
setdomainname(NULL,0);
|
707 |
|
|
|
708 |
|
|
strcpy(name,info->hostname_v46);
|
709 |
|
|
strcat(name,".");
|
710 |
|
|
strcat(name,info->domain_name);
|
711 |
|
|
strcpy(cname,info->cname_v46);
|
712 |
|
|
strcat(cname,".");
|
713 |
|
|
strcat(cname,info->domain_name);
|
714 |
|
|
|
715 |
|
|
inet_aton(info->ip_addr_v46_v4, &addr);
|
716 |
|
|
memset(&sa4,0,sizeof(sa4));
|
717 |
|
|
memcpy(&sa4.sin_addr, &addr, sizeof(addr));
|
718 |
|
|
sa4.sin_family=AF_INET;
|
719 |
|
|
sa4.sin_len = sizeof(sa4);
|
720 |
|
|
|
721 |
|
|
memset(&sa6,0,sizeof(sa6));
|
722 |
|
|
sa6.sin6_family = AF_INET6;
|
723 |
|
|
sa6.sin6_len = sizeof(sa6);
|
724 |
|
|
inet_pton(AF_INET6, info->ip_addr_v46_v6, (void *)&sa6.sin6_addr);
|
725 |
|
|
|
726 |
|
|
// Lookup the IPv4 and IPv6 FQDN hostname
|
727 |
|
|
error = getaddrinfo(name, NULL, &hints, &res);
|
728 |
|
|
|
729 |
|
|
if (error == EAI_NONE) {
|
730 |
|
|
#ifdef CYGOPT_NS_DNS_FIRST_FAMILY_AF_INET6
|
731 |
|
|
ai6 = res;
|
732 |
|
|
ai4 = res->ai_next;
|
733 |
|
|
CYG_TEST_PASS_FAIL((NULL != ai6->ai_next),
|
734 |
|
|
"IPv6 FQDN hostname not one result");
|
735 |
|
|
CYG_TEST_PASS_FAIL((NULL == ai4->ai_next),
|
736 |
|
|
"IPv4 & IPv6 FQDN hostname two results");
|
737 |
|
|
#else
|
738 |
|
|
ai4 = res;
|
739 |
|
|
ai6 = res->ai_next;
|
740 |
|
|
CYG_TEST_PASS_FAIL((NULL != ai4->ai_next),
|
741 |
|
|
"IPv6 FQDN hostname not one result");
|
742 |
|
|
CYG_TEST_PASS_FAIL((NULL == ai6->ai_next),
|
743 |
|
|
"IPv4 & IPv6 FQDN hostname two results");
|
744 |
|
|
#endif
|
745 |
|
|
getnameinfo(ai4->ai_addr, ai4->ai_addrlen,
|
746 |
|
|
buff, sizeof(buff),
|
747 |
|
|
NULL,0,NI_NUMERICHOST);
|
748 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
749 |
|
|
name,
|
750 |
|
|
ai4->ai_canonname,
|
751 |
|
|
familytoa(ai4->ai_family),
|
752 |
|
|
buff);
|
753 |
|
|
CYG_TEST_INFO(buffer);
|
754 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
755 |
|
|
(void*)ai4->ai_addr,
|
756 |
|
|
sizeof(sa4))) &&
|
757 |
|
|
(ai4->ai_family == AF_INET),
|
758 |
|
|
"IPv4 & IPv6 FQDN hostname address IPv4");
|
759 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, ai4->ai_canonname)),
|
760 |
|
|
"IPv4 & IPv6 FQDN hostname name");
|
761 |
|
|
getnameinfo(ai6->ai_addr, ai6->ai_addrlen,
|
762 |
|
|
buff, sizeof(buff),
|
763 |
|
|
NULL,0,NI_NUMERICHOST);
|
764 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s %s>",
|
765 |
|
|
name,
|
766 |
|
|
familytoa(ai6->ai_family),
|
767 |
|
|
buff);
|
768 |
|
|
CYG_TEST_INFO(buffer);
|
769 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
770 |
|
|
(void*)ai6->ai_addr,
|
771 |
|
|
sizeof(sa6))) &&
|
772 |
|
|
(ai6->ai_family == AF_INET6),
|
773 |
|
|
"IPv4 & IPv6 FQDN hostname address IPv6");
|
774 |
|
|
freeaddrinfo(res);
|
775 |
|
|
} else {
|
776 |
|
|
diag_sprintf(buffer,"IPv4 & IPv6 FQDN hostname: error %s",
|
777 |
|
|
gai_strerror(error));
|
778 |
|
|
CYG_TEST_FAIL(buffer);
|
779 |
|
|
}
|
780 |
|
|
|
781 |
|
|
// Lookup the IPv4 and IPv6 FQDN cname
|
782 |
|
|
error = getaddrinfo(cname, NULL, &hints, &res);
|
783 |
|
|
|
784 |
|
|
if (error == EAI_NONE) {
|
785 |
|
|
#ifdef CYGOPT_NS_DNS_FIRST_FAMILY_AF_INET6
|
786 |
|
|
ai6 = res;
|
787 |
|
|
ai4 = res->ai_next;
|
788 |
|
|
CYG_TEST_PASS_FAIL((NULL != ai6->ai_next),
|
789 |
|
|
"IPv6 FQDN hostname not one result");
|
790 |
|
|
CYG_TEST_PASS_FAIL((NULL == ai4->ai_next),
|
791 |
|
|
"IPv4 & IPv6 FQDN hostname two results");
|
792 |
|
|
#else
|
793 |
|
|
ai4 = res;
|
794 |
|
|
ai6 = res->ai_next;
|
795 |
|
|
CYG_TEST_PASS_FAIL((NULL != ai4->ai_next),
|
796 |
|
|
"IPv6 FQDN hostname not one result");
|
797 |
|
|
CYG_TEST_PASS_FAIL((NULL == ai6->ai_next),
|
798 |
|
|
"IPv4 & IPv6 FQDN hostname two results");
|
799 |
|
|
#endif
|
800 |
|
|
getnameinfo(ai4->ai_addr, ai4->ai_addrlen,
|
801 |
|
|
buff, sizeof(buff),
|
802 |
|
|
NULL,0,NI_NUMERICHOST);
|
803 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s is %s %s>",
|
804 |
|
|
cname,
|
805 |
|
|
ai4->ai_canonname,
|
806 |
|
|
familytoa(ai4->ai_family),
|
807 |
|
|
buff);
|
808 |
|
|
CYG_TEST_INFO(buffer);
|
809 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
810 |
|
|
(void*)ai4->ai_addr,
|
811 |
|
|
sizeof(sa4))) &&
|
812 |
|
|
(ai4->ai_family == AF_INET),
|
813 |
|
|
"IPv4 & IPv6 FQDN cname address IPv4");
|
814 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, ai4->ai_canonname)),
|
815 |
|
|
"IPv4 & IPv6 FQDN cname name");
|
816 |
|
|
getnameinfo(ai6->ai_addr, ai6->ai_addrlen,
|
817 |
|
|
buff, sizeof(buff),
|
818 |
|
|
NULL,0,NI_NUMERICHOST);
|
819 |
|
|
diag_sprintf(buffer,"Lookup %s: Result <%s %s>",
|
820 |
|
|
cname,
|
821 |
|
|
familytoa(ai6->ai_family),
|
822 |
|
|
buff);
|
823 |
|
|
CYG_TEST_INFO(buffer);
|
824 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
825 |
|
|
(void*)ai6->ai_addr,
|
826 |
|
|
sizeof(sa6))) &&
|
827 |
|
|
(ai6->ai_family == AF_INET6),
|
828 |
|
|
"IPv4 & IPv6 FQDN cname address IPv6");
|
829 |
|
|
freeaddrinfo(res);
|
830 |
|
|
} else {
|
831 |
|
|
diag_sprintf(buffer,"IPv4 & IPv6 FQDN cname: error %s",
|
832 |
|
|
gai_strerror(error));
|
833 |
|
|
CYG_TEST_FAIL(buffer);
|
834 |
|
|
}
|
835 |
|
|
|
836 |
|
|
if (info->dns_server_v6) {
|
837 |
|
|
cyg_dns_res_start(info->dns_server_v6);
|
838 |
|
|
// Lookup the IPv4 and IPv6 FQDN cname
|
839 |
|
|
error = getaddrinfo(cname, NULL, &hints, &res);
|
840 |
|
|
|
841 |
|
|
if (error == EAI_NONE) {
|
842 |
|
|
#ifdef CYGOPT_NS_DNS_FIRST_FAMILY_AF_INET6
|
843 |
|
|
ai6 = res;
|
844 |
|
|
ai4 = res->ai_next;
|
845 |
|
|
CYG_TEST_PASS_FAIL((NULL != ai6->ai_next),
|
846 |
|
|
"[IPv6] IPv6 FQDN hostname not one result");
|
847 |
|
|
CYG_TEST_PASS_FAIL((NULL == ai4->ai_next),
|
848 |
|
|
"[IPv6] IPv4 & IPv6 FQDN hostname two results");
|
849 |
|
|
#else
|
850 |
|
|
ai4 = res;
|
851 |
|
|
ai6 = res->ai_next;
|
852 |
|
|
CYG_TEST_PASS_FAIL((NULL != ai4->ai_next),
|
853 |
|
|
"[IPv6] IPv6 FQDN hostname not one result");
|
854 |
|
|
CYG_TEST_PASS_FAIL((NULL == ai6->ai_next),
|
855 |
|
|
"[IPv6] IPv4 & IPv6 FQDN hostname two results");
|
856 |
|
|
#endif
|
857 |
|
|
getnameinfo(ai4->ai_addr, ai4->ai_addrlen,
|
858 |
|
|
buff, sizeof(buff),
|
859 |
|
|
NULL,0,NI_NUMERICHOST);
|
860 |
|
|
diag_sprintf(buffer,"[IPv6] Lookup %s: Result <%s is %s %s>",
|
861 |
|
|
cname,
|
862 |
|
|
ai4->ai_canonname,
|
863 |
|
|
familytoa(ai4->ai_family),
|
864 |
|
|
buff);
|
865 |
|
|
CYG_TEST_INFO(buffer);
|
866 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa4,
|
867 |
|
|
(void*)ai4->ai_addr,
|
868 |
|
|
sizeof(sa4))) &&
|
869 |
|
|
(ai4->ai_family == AF_INET),
|
870 |
|
|
"[IPv6] IPv4 & IPv6 FQDN cname address IPv4");
|
871 |
|
|
CYG_TEST_PASS_FAIL((0 == strcmp(name, ai4->ai_canonname)),
|
872 |
|
|
"[IPv6] IPv4 & IPv6 FQDN cname name");
|
873 |
|
|
getnameinfo(ai6->ai_addr, ai6->ai_addrlen,
|
874 |
|
|
buff, sizeof(buff),
|
875 |
|
|
NULL,0,NI_NUMERICHOST);
|
876 |
|
|
diag_sprintf(buffer,"[IPv6] Lookup %s: Result <%s %s>",
|
877 |
|
|
cname,
|
878 |
|
|
familytoa(ai6->ai_family),
|
879 |
|
|
buff);
|
880 |
|
|
CYG_TEST_INFO(buffer);
|
881 |
|
|
CYG_TEST_PASS_FAIL((0 == memcmp((void *)&sa6,
|
882 |
|
|
(void*)ai6->ai_addr,
|
883 |
|
|
sizeof(sa6))) &&
|
884 |
|
|
(ai6->ai_family == AF_INET6),
|
885 |
|
|
"[IPv6] IPv4 & IPv6 FQDN cname address IPv6");
|
886 |
|
|
freeaddrinfo(res);
|
887 |
|
|
} else {
|
888 |
|
|
diag_sprintf(buffer,"[IPv6] IPv4 & IPv6 FQDN cname: error %s",
|
889 |
|
|
gai_strerror(error));
|
890 |
|
|
CYG_TEST_FAIL(buffer);
|
891 |
|
|
}
|
892 |
|
|
}
|
893 |
|
|
#endif
|
894 |
|
|
}
|
895 |
|
|
|
896 |
|
|
void
|
897 |
|
|
dns_test_thread(cyg_addrword_t p)
|
898 |
|
|
{
|
899 |
|
|
int i;
|
900 |
|
|
|
901 |
|
|
CYG_TEST_INIT();
|
902 |
|
|
|
903 |
|
|
init_all_network_interfaces();
|
904 |
|
|
|
905 |
|
|
CYG_TEST_INFO("Starting dns1 test");
|
906 |
|
|
|
907 |
|
|
for (i = 0; i < CYG_NELEM(test_info); i++) {
|
908 |
|
|
dns_test(&test_info[i]);
|
909 |
|
|
}
|
910 |
|
|
|
911 |
|
|
CYG_TEST_FINISH("dns1 test completed");
|
912 |
|
|
}
|
913 |
|
|
|
914 |
|
|
void
|
915 |
|
|
cyg_start(void)
|
916 |
|
|
{
|
917 |
|
|
// Create a main thread, so we can run the scheduler and have time 'pass'
|
918 |
|
|
cyg_thread_create(10, // Priority - just a number
|
919 |
|
|
dns_test_thread, // entry
|
920 |
|
|
0, // entry parameter
|
921 |
|
|
"DNS test", // Name
|
922 |
|
|
&stack[0], // Stack
|
923 |
|
|
STACK_SIZE, // Size
|
924 |
|
|
&thread_handle, // Handle
|
925 |
|
|
&thread_data // Thread data structure
|
926 |
|
|
);
|
927 |
|
|
cyg_thread_resume(thread_handle); // Start it
|
928 |
|
|
cyg_scheduler_start();
|
929 |
|
|
}
|