No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / bind / dist / bin / tests / system / lwresd / lwtest.c
blob3e1fdd072ac5af61ab7ca489c9c71f5339a2ed78
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000-2002 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: lwtest.c,v 1.32 2008/04/02 02:37:42 marka Exp */
22 #include <config.h>
24 #include <assert.h>
25 #include <stdlib.h>
27 #include <isc/net.h>
28 #include <isc/string.h>
30 #include <lwres/lwres.h>
31 #include <lwres/netdb.h>
32 #include <lwres/net.h>
35 * XXX getnameinfo errors, which don't appear to be standard.
37 #define ENI_NOSERVNAME 1
38 #define ENI_NOHOSTNAME 2
39 #define ENI_MEMORY 3
40 #define ENI_SYSTEM 4
41 #define ENI_FAMILY 5
42 #define ENI_SALEN 6
43 #define ENI_NOSOCKET 7
45 static int fails = 0;
47 static void
48 CHECK(lwres_result_t val, const char *msg) {
49 if (val != 0) {
50 printf("I:%s returned %d\n", msg, val);
51 exit(1);
55 static unsigned char TESTSTRING[] =
56 "This is a test. This is only a test. !!!";
58 static lwres_context_t *ctx;
60 static void
61 test_noop(void) {
62 lwres_result_t ret;
63 lwres_lwpacket_t pkt, pkt2;
64 lwres_nooprequest_t nooprequest, *nooprequest2;
65 lwres_noopresponse_t noopresponse, *noopresponse2;
66 lwres_buffer_t b;
68 pkt.pktflags = 0;
69 pkt.serial = 0x11223344;
70 pkt.recvlength = 0x55667788;
71 pkt.result = 0;
73 nooprequest.datalength = strlen((char *)TESTSTRING);
74 nooprequest.data = TESTSTRING;
75 ret = lwres_nooprequest_render(ctx, &nooprequest, &pkt, &b);
76 CHECK(ret, "lwres_nooprequest_render");
79 * Now, parse it into a new structure.
81 lwres_buffer_first(&b);
82 ret = lwres_lwpacket_parseheader(&b, &pkt2);
83 CHECK(ret, "lwres_lwpacket_parseheader");
85 nooprequest2 = NULL;
86 ret = lwres_nooprequest_parse(ctx, &b, &pkt2, &nooprequest2);
87 CHECK(ret, "lwres_nooprequest_parse");
89 assert(nooprequest.datalength == nooprequest2->datalength);
90 assert(memcmp(nooprequest.data, nooprequest2->data,
91 nooprequest.datalength) == 0);
93 lwres_nooprequest_free(ctx, &nooprequest2);
95 lwres_context_freemem(ctx, b.base, b.length);
96 b.base = NULL;
97 b.length = 0;
99 pkt.pktflags = 0;
100 pkt.serial = 0x11223344;
101 pkt.recvlength = 0x55667788;
102 pkt.result = 0xdeadbeef;
104 noopresponse.datalength = strlen((char *)TESTSTRING);
105 noopresponse.data = TESTSTRING;
106 ret = lwres_noopresponse_render(ctx, &noopresponse, &pkt, &b);
107 CHECK(ret, "lwres_noopresponse_render");
110 * Now, parse it into a new structure.
112 lwres_buffer_first(&b);
113 ret = lwres_lwpacket_parseheader(&b, &pkt2);
114 CHECK(ret, "lwres_lwpacket_parseheader");
116 noopresponse2 = NULL;
117 ret = lwres_noopresponse_parse(ctx, &b, &pkt2, &noopresponse2);
118 CHECK(ret, "lwres_noopresponse_parse");
120 assert(noopresponse.datalength == noopresponse2->datalength);
121 assert(memcmp(noopresponse.data, noopresponse2->data,
122 noopresponse.datalength) == 0);
124 lwres_noopresponse_free(ctx, &noopresponse2);
126 lwres_context_freemem(ctx, b.base, b.length);
127 b.base = NULL;
128 b.length = 0;
131 static void
132 test_gabn(const char *target, lwres_result_t expected, const char *address,
133 lwres_uint32_t af)
135 lwres_gabnresponse_t *res;
136 unsigned char addrbuf[16];
137 lwres_addr_t *addr;
138 char outbuf[64];
139 unsigned int len;
140 lwres_result_t ret;
142 res = NULL;
143 ret = lwres_getaddrsbyname(ctx, target,
144 LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6,
145 &res);
146 if (ret != expected) {
147 printf("I:gabn(%s) failed: %d\n", target, ret);
148 if (res != NULL)
149 lwres_gabnresponse_free(ctx, &res);
150 fails++;
151 return;
153 if (ret == LWRES_R_SUCCESS) {
154 if (af == LWRES_ADDRTYPE_V4) {
155 len = 4;
156 ret = inet_pton(AF_INET, address, addrbuf);
157 assert(ret == 1);
158 } else {
159 len = 16;
160 ret = inet_pton(AF_INET6, address, addrbuf);
161 assert(ret == 1);
163 addr = LWRES_LIST_HEAD(res->addrs);
164 if (addr == NULL) {
165 printf("I:gabn(%s) returned empty list\n", target);
166 fails++;
167 return;
169 while (addr != NULL) {
170 if (addr->family != af || addr->length != len ||
171 memcmp(addr->address, addrbuf, len) == 0)
172 break;
173 addr = LWRES_LIST_NEXT(addr, link);
175 if (addr == NULL) {
176 addr = LWRES_LIST_HEAD(res->addrs);
177 if (addr->family == LWRES_ADDRTYPE_V4)
178 (void)inet_ntop(AF_INET, addr->address,
179 outbuf, sizeof(outbuf));
180 else
181 (void)inet_ntop(AF_INET6, addr->address,
182 outbuf, sizeof(outbuf));
183 printf("I:gabn(%s) returned %s, expected %s\n",
184 target, outbuf, address);
185 fails++;
186 return;
189 if (res != NULL)
190 lwres_gabnresponse_free(ctx, &res);
193 static void
194 test_gnba(const char *target, lwres_uint32_t af, lwres_result_t expected,
195 const char *name)
197 lwres_gnbaresponse_t *res;
198 lwres_result_t ret;
199 unsigned char addrbuf[16];
200 unsigned int len;
202 if (af == LWRES_ADDRTYPE_V4) {
203 len = 4;
204 ret = inet_pton(AF_INET, target, addrbuf);
205 assert(ret == 1);
206 } else {
207 len = 16;
208 ret = inet_pton(AF_INET6, target, addrbuf);
209 assert(ret == 1);
212 res = NULL;
213 ret = lwres_getnamebyaddr(ctx, af, len, addrbuf, &res);
214 if (ret != expected) {
215 printf("I:gnba(%s) failed: %d\n", target, ret);
216 if (res != NULL)
217 lwres_gnbaresponse_free(ctx, &res);
218 fails++;
219 return;
221 if (ret == LWRES_R_SUCCESS && strcasecmp(res->realname, name) != 0) {
222 printf("I:gnba(%s) returned %s, expected %s\n",
223 target, res->realname, name);
224 fails++;
225 return;
227 if (res != NULL)
228 lwres_gnbaresponse_free(ctx, &res);
231 static void
232 test_gethostbyname(const char *name, const char *address) {
233 struct hostent *hp;
234 unsigned char addrbuf[16];
235 int ret;
237 hp = gethostbyname(name);
238 if (hp == NULL) {
239 if (address == NULL && h_errno == HOST_NOT_FOUND)
240 return;
241 else if (h_errno != HOST_NOT_FOUND) {
242 printf("I:gethostbyname(%s) failed: %s\n",
243 name, hstrerror(h_errno));
244 fails++;
245 return;
246 } else {
247 printf("I:gethostbyname(%s) returned not found\n",
248 name);
249 fails++;
250 return;
252 } else {
253 ret = inet_pton(AF_INET, address, addrbuf);
254 assert(ret == 1);
255 if (memcmp(hp->h_addr_list[0], addrbuf, hp->h_length) != 0) {
256 char outbuf[16];
257 (void)inet_ntop(AF_INET, hp->h_addr_list[0],
258 outbuf, sizeof(outbuf));
259 printf("I:gethostbyname(%s) returned %s, "
260 "expected %s\n", name, outbuf, address);
261 fails++;
262 return;
267 static void
268 test_gethostbyname2(const char *name, const char *address, int af) {
269 struct hostent *hp;
270 unsigned char addrbuf[16];
271 int len, ret;
273 hp = gethostbyname2(name, af);
274 if (hp == NULL) {
275 if (address == NULL && h_errno == HOST_NOT_FOUND)
276 return;
277 else if (h_errno != HOST_NOT_FOUND) {
278 printf("I:gethostbyname(%s) failed: %s\n",
279 name, hstrerror(h_errno));
280 fails++;
281 return;
282 } else {
283 printf("I:gethostbyname(%s) returned not found\n",
284 name);
285 fails++;
286 return;
288 } else {
289 if (af == AF_INET)
290 len = 4;
291 else
292 len = 16;
293 ret = inet_pton(af, address, addrbuf);
294 assert(ret == 1);
295 if (hp->h_addrtype != af) {
296 printf("I:gethostbyname(%s) returned wrong family\n",
297 name);
298 fails++;
299 return;
301 if (len != (int)hp->h_length ||
302 memcmp(hp->h_addr_list[0], addrbuf, hp->h_length) != 0)
304 char outbuf[16];
305 (void)inet_ntop(af, hp->h_addr_list[0],
306 outbuf, sizeof(outbuf));
307 printf("I:gethostbyname(%s) returned %s, "
308 "expected %s\n", name, outbuf, address);
309 fails++;
310 return;
315 static void
316 test_getipnodebyname(const char *name, const char *address, int af,
317 int v4map, int all)
319 struct hostent *hp;
320 unsigned char addrbuf[16];
321 int len, ret;
322 int error_num;
323 int flags = 0;
325 if (v4map)
326 flags |= AI_V4MAPPED;
327 if (all)
328 flags |= AI_ALL;
330 hp = getipnodebyname(name, af, flags, &error_num);
331 if (hp == NULL) {
332 if (address == NULL && error_num == HOST_NOT_FOUND)
333 return;
334 else if (error_num != HOST_NOT_FOUND) {
335 printf("I:getipnodebyname(%s) failed: %d\n",
336 name, error_num);
337 fails++;
338 return;
339 } else {
340 printf("I:getipnodebyname(%s) returned not found\n",
341 name);
342 fails++;
343 return;
345 } else {
346 if (af == AF_INET)
347 len = 4;
348 else
349 len = 16;
350 ret = inet_pton(af, address, addrbuf);
351 assert(ret == 1);
352 if (hp->h_addrtype != af) {
353 printf("I:getipnodebyname(%s) returned wrong family\n",
354 name);
355 freehostent(hp);
356 fails++;
357 return;
359 if (len != (int)hp->h_length ||
360 memcmp(hp->h_addr_list[0], addrbuf, hp->h_length) != 0)
362 char outbuf[16];
363 (void)inet_ntop(af, hp->h_addr_list[0],
364 outbuf, sizeof(outbuf));
365 printf("I:getipnodebyname(%s) returned %s, "
366 "expected %s\n", name, outbuf, address);
367 freehostent(hp);
368 fails++;
369 return;
371 freehostent(hp);
375 static void
376 test_gethostbyaddr(const char *address, int af, const char *name) {
377 struct hostent *hp;
378 char addrbuf[16];
379 int len, ret;
381 if (af == AF_INET)
382 len = 4;
383 else
384 len = 16;
385 ret = inet_pton(af, address, addrbuf);
386 assert(ret == 1);
388 hp = gethostbyaddr(addrbuf, len, af);
390 if (hp == NULL) {
391 if (name == NULL && h_errno == HOST_NOT_FOUND)
392 return;
393 else if (h_errno != HOST_NOT_FOUND) {
394 printf("I:gethostbyaddr(%s) failed: %s\n",
395 address, hstrerror(h_errno));
396 fails++;
397 return;
398 } else {
399 printf("I:gethostbyaddr(%s) returned not found\n",
400 address);
401 fails++;
402 return;
404 } else {
405 if (strcmp(hp->h_name, name) != 0) {
406 printf("I:gethostbyname(%s) returned %s, "
407 "expected %s\n", address, hp->h_name, name);
408 fails++;
409 return;
414 static void
415 test_getipnodebyaddr(const char *address, int af, const char *name) {
416 struct hostent *hp;
417 char addrbuf[16];
418 int len, ret;
419 int error_num;
421 if (af == AF_INET)
422 len = 4;
423 else
424 len = 16;
425 ret = inet_pton(af, address, addrbuf);
426 assert(ret == 1);
428 hp = getipnodebyaddr(addrbuf, len, af, &error_num);
430 if (hp == NULL) {
431 if (name == NULL && error_num == HOST_NOT_FOUND)
432 return;
433 else if (error_num != HOST_NOT_FOUND) {
434 printf("I:getipnodebyaddr(%s) failed: %d\n",
435 address, error_num);
436 fails++;
437 return;
438 } else {
439 printf("I:getipnodebyaddr(%s) returned not found\n",
440 address);
441 fails++;
442 return;
444 } else {
445 if (strcmp(hp->h_name, name) != 0) {
446 printf("I:getipnodebyaddr(%s) returned %s, "
447 "expected %s\n", address, hp->h_name, name);
448 freehostent(hp);
449 fails++;
450 return;
452 freehostent(hp);
456 static void
457 test_getaddrinfo(const char *name, int af, int v4ok, int v6ok,
458 const char *address)
460 unsigned int len;
461 int ret;
462 struct addrinfo *ai;
463 struct addrinfo hint;
464 unsigned char addrbuf[16];
466 if (v4ok == 1 && v6ok== 1) {
467 ret = getaddrinfo(name, NULL, NULL, &ai);
468 } else {
469 memset(&hint, 0, sizeof(hint));
470 if (v4ok)
471 hint.ai_family = AF_INET;
472 else
473 hint.ai_family = AF_INET6;
474 ret = getaddrinfo(name, NULL, &hint, &ai);
476 if (ret != 0) {
477 if (address == NULL && ret == EAI_NODATA)
478 return;
479 else if (ret != EAI_NODATA) {
480 printf("I:getaddrinfo(%s,%d,%d) failed: %s\n",
481 name, v4ok, v6ok, gai_strerror(ret));
482 fails++;
483 return;
484 } else {
485 printf("I:getaddrinfo(%s,%d,%d) returned not found\n",
486 name, v4ok, v6ok);
487 fails++;
488 return;
490 } else {
491 if (af == AF_INET)
492 len = sizeof(struct sockaddr_in);
493 else
494 len = sizeof(struct sockaddr_in6);
495 ret = inet_pton(af, address, addrbuf);
496 assert(ret == 1);
497 if (ai->ai_family != af) {
498 printf("I:getaddrinfo(%s) returned wrong family\n",
499 name);
500 fails++;
501 freeaddrinfo(ai);
502 return;
504 if (len != (unsigned int) ai->ai_addrlen) {
505 char outbuf[16];
506 (void)inet_ntop(af, ai->ai_addr,
507 outbuf, sizeof(outbuf));
508 printf("I:getaddrinfo(%s) returned %lub, "
509 "expected %ub\n", name,
510 (unsigned long)ai->ai_addrlen, len);
511 fails++;
512 freeaddrinfo(ai);
513 return;
514 } else if (af == AF_INET) {
515 struct sockaddr_in *sin;
516 sin = (struct sockaddr_in *) ai->ai_addr;
517 if (memcmp(&sin->sin_addr.s_addr, addrbuf, 4) != 0) {
518 char outbuf[16];
519 (void)inet_ntop(af, &sin->sin_addr.s_addr,
520 outbuf, sizeof(outbuf));
521 printf("I:getaddrinfo(%s) returned %s, "
522 "expected %s\n", name, outbuf, address);
523 fails++;
524 freeaddrinfo(ai);
525 return;
527 } else {
528 struct sockaddr_in6 *sin6;
529 sin6 = (struct sockaddr_in6 *) ai->ai_addr;
530 if (memcmp(sin6->sin6_addr.s6_addr, addrbuf, 16) != 0)
532 char outbuf[16];
533 (void)inet_ntop(af, &sin6->sin6_addr.s6_addr,
534 outbuf, sizeof(outbuf));
535 printf("I:getaddrinfo(%s) returned %s, "
536 "expected %s\n", name, outbuf, address);
537 fails++;
538 freeaddrinfo(ai);
539 return;
542 freeaddrinfo(ai);
546 static void
547 test_getnameinfo(const char *address, int af, const char *name) {
548 int ret;
549 struct sockaddr_in sin;
550 struct sockaddr_in6 sin6;
551 struct sockaddr *sa;
552 int salen;
553 char host[1025];
555 if (af == AF_INET) {
556 memset(&sin, 0, sizeof(sin));
557 ret = inet_pton(AF_INET, address, &sin.sin_addr.s_addr);
558 assert(ret == 1);
559 sin.sin_family = AF_INET;
560 #ifdef LWRES_PLATFORM_HAVESALEN
561 sin.sin_len = sizeof(sin);
562 #endif
563 sa = (struct sockaddr *) &sin;
564 salen = sizeof(sin);
565 } else {
566 memset(&sin6, 0, sizeof(sin6));
567 ret = inet_pton(AF_INET6, address, sin6.sin6_addr.s6_addr);
568 assert(ret == 1);
569 sin6.sin6_family = AF_INET6;
570 #ifdef LWRES_PLATFORM_HAVESALEN
571 sin6.sin6_len = sizeof(sin6);
572 #endif
573 sa = (struct sockaddr *) &sin6;
574 salen = sizeof(sin6);
576 sa->sa_family = af;
578 ret = getnameinfo(sa, salen, host, sizeof(host), NULL, 0, NI_NAMEREQD);
580 if (ret != 0) {
581 if (name == NULL && ret == ENI_NOHOSTNAME)
582 return;
583 else if (ret != ENI_NOHOSTNAME) {
584 printf("I:getnameinfo(%s) failed: %d\n",
585 address, ret);
586 fails++;
587 return;
588 } else {
589 printf("I:getnameinfo(%s) returned not found\n",
590 address);
591 fails++;
592 return;
594 } else {
595 if (name == NULL) {
596 printf("I:getnameinfo(%s) returned %s, "
597 "expected NULL\n", address, host);
598 fails++;
599 return;
600 } else if (strcmp(host, name) != 0) {
601 printf("I:getnameinfo(%s) returned %s, expected %s\n",
602 address, host, name);
603 fails++;
604 return;
609 static void
610 test_getrrsetbyname(const char *name, int rdclass, int rdtype,
611 unsigned int nrdatas, unsigned int nsigs,
612 int should_pass)
614 int ret;
615 struct rrsetinfo *rrinfo = NULL;
616 ret = getrrsetbyname(name, rdclass, rdtype, 0, &rrinfo);
617 if (ret != 0 && should_pass == 1) {
618 printf("I:getrrsetbyname(%s, %d) failed\n", name, rdtype);
619 fails++;
620 return;
621 } else if (ret == 0 && should_pass == 0) {
622 printf("I:getrrsetbyname(%s, %d) unexpectedly succeeded\n",
623 name, rdtype);
624 fails++;
625 freerrset(rrinfo);
626 return;
627 } else if (ret != 0)
628 return;
629 if (rrinfo->rri_nrdatas != nrdatas) {
630 printf("I:getrrsetbyname(%s, %d): got %d rr, expected %d\n",
631 name, rdtype, rrinfo->rri_nrdatas, nrdatas);
632 fails++;
634 if (rrinfo->rri_nsigs != nsigs) {
635 printf("I:getrrsetbyname(%s, %d): got %d sig, expected %d\n",
636 name, rdtype, rrinfo->rri_nsigs, nsigs);
637 fails++;
639 freerrset(rrinfo);
640 return;
644 main(void) {
645 lwres_result_t ret;
647 lwres_udp_port = 9210;
648 lwres_resolv_conf = "resolv.conf";
650 ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0);
651 CHECK(ret, "lwres_context_create");
653 ret = lwres_conf_parse(ctx, "resolv.conf");
654 CHECK(ret, "lwres_conf_parse");
656 test_noop();
658 test_gabn("a.example1", LWRES_R_SUCCESS, "10.0.1.1",
659 LWRES_ADDRTYPE_V4);
660 test_gabn("a.example1.", LWRES_R_SUCCESS, "10.0.1.1",
661 LWRES_ADDRTYPE_V4);
662 test_gabn("a.example2", LWRES_R_SUCCESS, "10.0.2.1",
663 LWRES_ADDRTYPE_V4);
664 test_gabn("a.example2.", LWRES_R_SUCCESS, "10.0.2.1",
665 LWRES_ADDRTYPE_V4);
666 test_gabn("a.example3", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V4);
667 test_gabn("a.example3.", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V4);
668 test_gabn("a", LWRES_R_SUCCESS, "10.0.1.1", LWRES_ADDRTYPE_V4);
669 test_gabn("a.", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V4);
671 test_gabn("a2", LWRES_R_SUCCESS, "10.0.1.1", LWRES_ADDRTYPE_V4);
672 test_gabn("a3", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V4);
674 test_gabn("b.example1", LWRES_R_SUCCESS,
675 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
676 LWRES_ADDRTYPE_V6);
677 test_gabn("b.example1.", LWRES_R_SUCCESS,
678 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
679 LWRES_ADDRTYPE_V6);
680 test_gabn("b.example2", LWRES_R_SUCCESS,
681 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
682 LWRES_ADDRTYPE_V6);
683 test_gabn("b.example2.", LWRES_R_SUCCESS,
684 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
685 LWRES_ADDRTYPE_V6);
686 test_gabn("b.example3", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V6);
687 test_gabn("b.example3.", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V6);
688 test_gabn("b", LWRES_R_SUCCESS,
689 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
690 LWRES_ADDRTYPE_V6);
691 test_gabn("b.", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V6);
693 test_gabn("d.example1", LWRES_R_NOTFOUND, NULL, LWRES_ADDRTYPE_V6);
695 test_gabn("x", LWRES_R_SUCCESS, "10.1.10.1", LWRES_ADDRTYPE_V4);
696 test_gabn("x.", LWRES_R_SUCCESS, "10.1.10.1", LWRES_ADDRTYPE_V4);
698 test_gnba("10.10.10.1", LWRES_ADDRTYPE_V4, LWRES_R_SUCCESS,
699 "ipv4.example");
700 test_gnba("10.10.10.17", LWRES_ADDRTYPE_V4, LWRES_R_NOTFOUND,
701 NULL);
702 test_gnba("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
703 LWRES_ADDRTYPE_V6, LWRES_R_SUCCESS, "ip6.int.example");
704 test_gnba("0123:4567:89ab:cdef:0123:4567:89ab:cde0",
705 LWRES_ADDRTYPE_V6, LWRES_R_NOTFOUND, NULL);
706 test_gnba("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
707 LWRES_ADDRTYPE_V6, LWRES_R_SUCCESS, "ip6.arpa.example");
708 test_gnba("1123:4567:89ab:cdef:0123:4567:89ab:cde0",
709 LWRES_ADDRTYPE_V6, LWRES_R_NOTFOUND, NULL);
711 test_gethostbyname("a.example1.", "10.0.1.1");
712 test_gethostbyname("q.example1.", NULL);
714 test_gethostbyname2("a.example1.", "10.0.1.1", AF_INET);
715 test_gethostbyname2("b.example1.",
716 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
717 AF_INET6);
718 test_gethostbyname2("q.example1.", NULL, AF_INET);
720 test_getipnodebyname("a.example1.", "10.0.1.1", AF_INET, 0, 0);
721 test_getipnodebyname("b.example1.",
722 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
723 AF_INET6, 0, 0);
724 test_getipnodebyname("a.example1.",
725 "::ffff:10.0.1.1", AF_INET6, 1, 0);
726 test_getipnodebyname("a.example1.",
727 "::ffff:10.0.1.1", AF_INET6, 1, 1);
728 test_getipnodebyname("b.example1.",
729 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff",
730 AF_INET6, 1, 1);
731 test_getipnodebyname("q.example1.", NULL, AF_INET, 0, 0);
733 test_gethostbyaddr("10.10.10.1", AF_INET, "ipv4.example");
734 test_gethostbyaddr("10.10.10.17", AF_INET, NULL);
735 test_gethostbyaddr("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
736 AF_INET6, "ip6.int.example");
737 test_gethostbyaddr("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
738 AF_INET6, "ip6.arpa.example");
740 test_getipnodebyaddr("10.10.10.1", AF_INET, "ipv4.example");
741 test_getipnodebyaddr("10.10.10.17", AF_INET, NULL);
742 test_getipnodebyaddr("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
743 AF_INET6, "ip6.int.example");
744 test_getipnodebyaddr("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
745 AF_INET6, "ip6.arpa.example");
747 test_getaddrinfo("a.example1.", AF_INET, 1, 1, "10.0.1.1");
748 test_getaddrinfo("a.example1.", AF_INET, 1, 0, "10.0.1.1");
749 test_getaddrinfo("a.example1.", AF_INET, 0, 1, NULL);
750 test_getaddrinfo("b.example1.", AF_INET6, 1, 1,
751 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff");
752 test_getaddrinfo("b.example1.", AF_INET6, 1, 0, NULL);
753 test_getaddrinfo("b.example1.", AF_INET6, 0, 1,
754 "eeee:eeee:eeee:eeee:ffff:ffff:ffff:ffff");
756 test_getnameinfo("10.10.10.1", AF_INET, "ipv4.example");
757 test_getnameinfo("10.10.10.17", AF_INET, NULL);
758 test_getnameinfo("0123:4567:89ab:cdef:0123:4567:89ab:cdef",
759 AF_INET6, "ip6.int.example");
760 test_getnameinfo("1123:4567:89ab:cdef:0123:4567:89ab:cdef",
761 AF_INET6, "ip6.arpa.example");
762 test_getnameinfo("1122:3344:5566:7788:99aa:bbcc:ddee:ff00",
763 AF_INET6, "dname.example1");
765 test_getrrsetbyname("a", 1, 1, 1, 0, 1);
766 test_getrrsetbyname("a.example1.", 1, 1, 1, 0, 1);
767 test_getrrsetbyname("e.example1.", 1, 1, 1, 1, 1);
768 test_getrrsetbyname("e.example1.", 1, 255, 1, 1, 0);
769 test_getrrsetbyname("e.example1.", 1, 46, 2, 0, 1);
770 test_getrrsetbyname("", 1, 1, 0, 0, 0);
772 if (fails == 0)
773 printf("I:ok\n");
774 return (fails);