lwres_test.c revision b6b21d80450f81d873d7e8cd21e7b72fdf512507
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/*
523ad879ce1abb51cae579a6393da0e0436fe8dfTinderbox User * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000, 2001 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and distribute this software for any
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * purpose with or without fee is hereby granted, provided that the above
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id: lwres_test.c,v 1.28 2005/03/16 22:22:29 marka Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <config.h>
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <assert.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <stdlib.h>
f1788d67add6bf3d301e91b3f54fa3c90a87328eBrian Wellington#include <string.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <isc/mem.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <isc/netaddr.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/util.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <lwres/lwres.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#define USE_ISC_MEM
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic inline void
6098d364b690cb9dabf96e9664c4689c8559bd2eMark AndrewsCHECK(int val, const char *msg) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (val != 0) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley fprintf(stderr, "%s returned %d\n", msg, val);
c1ee8bb4ba3e9ab1463403ed685729631de406b1Mark Andrews exit(1);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley }
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic void
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrewshexdump(const char *msg, void *base, size_t len) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley unsigned char *p;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley unsigned int cnt;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley p = base;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley cnt = 0;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews printf("*** %s (%lu bytes @ %p)\n", msg, (unsigned long)len, base);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews while (cnt < len) {
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews if (cnt % 16 == 0)
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews printf("%p: ", p);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews else if (cnt % 8 == 0)
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf(" |");
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf(" %02x", *p++);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley cnt++;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (cnt % 16 == 0)
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews printf("\n");
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley }
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (cnt % 16 != 0)
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("\n");
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic const char *TESTSTRING = "This is a test. This is only a test. !!!";
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic lwres_context_t *ctx;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic void
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleytest_noop(void) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley int ret;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_lwpacket_t pkt, pkt2;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_nooprequest_t nooprequest, *nooprequest2;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_noopresponse_t noopresponse, *noopresponse2;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_buffer_t b;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley pkt.pktflags = 0;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley pkt.serial = 0x11223344;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley pkt.recvlength = 0x55667788;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley pkt.result = 0;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley nooprequest.datalength = strlen(TESTSTRING);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley /* XXXDCL maybe "nooprequest.data" should be const. */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley DE_CONST(TESTSTRING, nooprequest.data);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ret = lwres_nooprequest_render(ctx, &nooprequest, &pkt, &b);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley CHECK(ret, "lwres_nooprequest_render");
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley hexdump("rendered noop request", b.base, b.used);
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley /*
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Now, parse it into a new structure.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_buffer_first(&b);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ret = lwres_lwpacket_parseheader(&b, &pkt2);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley CHECK(ret, "lwres_lwpacket_parseheader");
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley hexdump("parsed pkt2", &pkt2, sizeof(pkt2));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley nooprequest2 = NULL;
7cd4c3ddd1baf5f2b204562fdba3da37c716cc78Andreas Gustafsson ret = lwres_nooprequest_parse(ctx, &b, &pkt2, &nooprequest2);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley CHECK(ret, "lwres_nooprequest_parse");
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews assert(nooprequest.datalength == nooprequest2->datalength);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews assert(memcmp(nooprequest.data, nooprequest2->data,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews nooprequest.datalength) == 0);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews lwres_nooprequest_free(ctx, &nooprequest2);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews lwres_context_freemem(ctx, b.base, b.length);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews b.base = NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews b.length = 0;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews pkt.pktflags = 0;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews pkt.serial = 0x11223344;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews pkt.recvlength = 0x55667788;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews pkt.result = 0xdeadbeef;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews noopresponse.datalength = strlen(TESTSTRING);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews /* XXXDCL maybe "noopresponse.data" should be const. */
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews DE_CONST(TESTSTRING, noopresponse.data);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews ret = lwres_noopresponse_render(ctx, &noopresponse, &pkt, &b);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley CHECK(ret, "lwres_noopresponse_render");
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley hexdump("rendered noop response", b.base, b.used);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley /*
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Now, parse it into a new structure.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_buffer_first(&b);
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley ret = lwres_lwpacket_parseheader(&b, &pkt2);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(ret, "lwres_lwpacket_parseheader");
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley hexdump("parsed pkt2", &pkt2, sizeof(pkt2));
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews noopresponse2 = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ret = lwres_noopresponse_parse(ctx, &b, &pkt2, &noopresponse2);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley CHECK(ret, "lwres_noopresponse_parse");
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley assert(noopresponse.datalength == noopresponse2->datalength);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley assert(memcmp(noopresponse.data, noopresponse2->data,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley noopresponse.datalength) == 0);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley lwres_noopresponse_free(ctx, &noopresponse2);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_context_freemem(ctx, b.base, b.length);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley b.base = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley b.length = 0;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic void
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewstest_gabn(const char *target) {
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews lwres_gabnresponse_t *res;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews lwres_addr_t *addr;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews int ret;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned int i;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews char outbuf[64];
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews res = NULL;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews ret = lwres_getaddrsbyname(ctx, target,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley &res);
7cd4c3ddd1baf5f2b204562fdba3da37c716cc78Andreas Gustafsson printf("gabn %s ret == %d\n", target, ret);
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley if (ret != 0) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence printf("FAILURE!\n");
4607e7a9b8dfb1b41c70e51c2b603daaf22cf302Mark Andrews if (res != NULL)
4607e7a9b8dfb1b41c70e51c2b603daaf22cf302Mark Andrews lwres_gabnresponse_free(ctx, &res);
4607e7a9b8dfb1b41c70e51c2b603daaf22cf302Mark Andrews return;
4607e7a9b8dfb1b41c70e51c2b603daaf22cf302Mark Andrews }
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("Returned real name: (%u, %s)\n",
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley res->realnamelen, res->realname);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("%u aliases:\n", res->naliases);
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley for (i = 0; i < res->naliases; i++)
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley printf("%u addresses:\n", res->naddrs);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley addr = LWRES_LIST_HEAD(res->addrs);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley for (i = 0; i < res->naddrs; i++) {
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley INSIST(addr != NULL);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley if (addr->family == LWRES_ADDRTYPE_V4)
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews (void)inet_ntop(AF_INET, addr->address,
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley outbuf, sizeof(outbuf));
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley else
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews (void)inet_ntop(AF_INET6, addr->address,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews outbuf, sizeof(outbuf));
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley printf("\tAddr len %u family %08x %s\n",
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley addr->length, addr->family, outbuf);
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley addr = LWRES_LIST_NEXT(addr, link);
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley }
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley lwres_gabnresponse_free(ctx, &res);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley}
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleystatic void
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleytest_gnba(const char *target, lwres_uint32_t af) {
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley lwres_gnbaresponse_t *res;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley int ret;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley unsigned int i;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley unsigned char addrbuf[16];
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley unsigned int len;
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (af == LWRES_ADDRTYPE_V4) {
fbe2cff19f5cddc67b967764ad95038dfcafc85aEvan Hunt len = 4;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley ret = inet_pton(AF_INET, target, addrbuf);
b5fff54fe9335b20c02d749831fc0eaeda97198fBrian Wellington assert(ret == 1);
b5fff54fe9335b20c02d749831fc0eaeda97198fBrian Wellington } else {
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews len = 16;
32f985bcf464816d3a8700185afdebb122cb4cecMark Andrews ret = inet_pton(AF_INET6, target, addrbuf);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley assert(ret == 1);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley }
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley res = NULL;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley ret = lwres_getnamebyaddr(ctx, af, len, addrbuf, &res);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley printf("gnba %s ret == %d\n", target, ret);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley assert(ret == 0);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews assert(res != NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews printf("Returned real name: (%u, %s)\n",
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews res->realnamelen, res->realname);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews printf("%u aliases:\n", res->naliases);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for (i = 0; i < res->naliases; i++)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews lwres_gnbaresponse_free(ctx, &res);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#ifdef USE_ISC_MEM
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews/*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Wrappers around our memory management stuff, for the lwres functions.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleystatic void *
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleymem_alloc(void *arg, size_t size) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley return (isc_mem_get(arg, size));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic void
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleymem_free(void *arg, void *mem, size_t size) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley isc_mem_put(arg, mem, size);
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley}
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley#endif
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleyint
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halleymain(int argc, char *argv[]) {
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley int ret;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley#ifdef USE_ISC_MEM
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley isc_mem_t *mem;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley isc_result_t result;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley#endif
c1ee8bb4ba3e9ab1463403ed685729631de406b1Mark Andrews
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley (void)argc;
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley (void)argv;
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#ifdef USE_ISC_MEM
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews mem = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley result = isc_mem_create(0, 0, &mem);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley INSIST(result == ISC_R_SUCCESS);
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson#endif
1f1d36a87b65186d9f89aac7f456ab1fd2a39ef6Andreas Gustafsson
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews ctx = NULL;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews#ifdef USE_ISC_MEM
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt#else
421e4cf66e4cba0b0751a34a9c027e39fe0474f9Mark Andrews ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0);
421e4cf66e4cba0b0751a34a9c027e39fe0474f9Mark Andrews#endif
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews CHECK(ret, "lwres_context_create");
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
55254a46f91419b92eee0d20dfb958e8dd52526cBob Halley ret = lwres_conf_parse(ctx, "/etc/resolv.conf");
08af8bf5ade4131fe44926ad04fd489e64a620bbBob Halley CHECK(ret, "lwres_conf_parse");
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_conf_print(ctx, stdout);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley test_noop();
b2ca6fd3a8293440b4d263723525396059cf2400Brian Wellington
84185d19c7a9ef1ac23cc6236c8773697d4efeb1Brian Wellington /*
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * The following comments about tests all assume your search path is
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews * nominum.com isc.org flame.org
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley * and ndots is the default of 1.
8569ab045a4cf6ecd1b5a3354ddb1c93ef34ea57Brian Wellington */
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("alias-05.test"); /* exact, then search. */
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("f.root-servers.net.");
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("poofball.flame.org.");
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("foo.ip6.int.");
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("notthereatall.flame.org"); /* exact, then search (!found)*/
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("shell"); /* search (found in nominum.com), then exact */
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("kechara"); /* search (found in flame.org), then exact */
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("lkasdjlaksjdlkasjdlkasjdlkasjd"); /* search, exact(!found)*/
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gnba("198.133.199.1", LWRES_ADDRTYPE_V4);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gnba("204.152.184.79", LWRES_ADDRTYPE_V4);
569d094440399b000e059d4cb3434391c2c4d330Michael Graff test_gnba("3ffe:8050:201:1860:42::1", LWRES_ADDRTYPE_V6);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt lwres_conf_clear(ctx);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_context_destroy(&ctx);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley#ifdef USE_ISC_MEM
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_mem_stats(mem, stdout);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_mem_destroy(&mem);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#endif
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (0);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley