a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff */
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: lwres_test.c,v 1.31 2007/06/19 23:46:59 tbox Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <config.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff#include <assert.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <stdlib.h>
142784f574e0b63e8bbcccb762eb8727ac7c76feBrian Wellington#include <string.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <isc/mem.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff#include <isc/netaddr.h>
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont#include <isc/print.h>
7df0472d8a76c83d2137bd9549414a30787d58cfBrian Wellington#include <isc/util.h>
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff#include <lwres/lwres.h>
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#define USE_ISC_MEM
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffstatic inline void
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David LawrenceCHECK(int val, const char *msg) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (val != 0) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff fprintf(stderr, "%s returned %d\n", msg, val);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff exit(1);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff }
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffstatic void
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencehexdump(const char *msg, void *base, size_t len) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff unsigned char *p;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff unsigned int cnt;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff p = base;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff cnt = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
b6b21d80450f81d873d7e8cd21e7b72fdf512507Mark Andrews printf("*** %s (%lu bytes @ %p)\n", msg, (unsigned long)len, base);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff while (cnt < len) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (cnt % 16 == 0)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff printf("%p: ", p);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff else if (cnt % 8 == 0)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff printf(" |");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff printf(" %02x", *p++);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff cnt++;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (cnt % 16 == 0)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff printf("\n");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff }
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff if (cnt % 16 != 0)
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff printf("\n");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff}
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *TESTSTRING = "This is a test. This is only a test. !!!";
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffstatic lwres_context_t *ctx;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencetest_noop(void) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff int ret;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_lwpacket_t pkt, pkt2;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_nooprequest_t nooprequest, *nooprequest2;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_noopresponse_t noopresponse, *noopresponse2;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_buffer_t b;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff pkt.pktflags = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff pkt.serial = 0x11223344;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff pkt.recvlength = 0x55667788;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff pkt.result = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff nooprequest.datalength = strlen(TESTSTRING);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence /* XXXDCL maybe "nooprequest.data" should be const. */
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence DE_CONST(TESTSTRING, nooprequest.data);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ret = lwres_nooprequest_render(ctx, &nooprequest, &pkt, &b);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff CHECK(ret, "lwres_nooprequest_render");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff hexdump("rendered noop request", b.base, b.used);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff /*
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Now, parse it into a new structure.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_buffer_first(&b);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ret = lwres_lwpacket_parseheader(&b, &pkt2);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff CHECK(ret, "lwres_lwpacket_parseheader");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff hexdump("parsed pkt2", &pkt2, sizeof(pkt2));
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff nooprequest2 = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ret = lwres_nooprequest_parse(ctx, &b, &pkt2, &nooprequest2);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff CHECK(ret, "lwres_nooprequest_parse");
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff assert(nooprequest.datalength == nooprequest2->datalength);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff assert(memcmp(nooprequest.data, nooprequest2->data,
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff nooprequest.datalength) == 0);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_nooprequest_free(ctx, &nooprequest2);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_context_freemem(ctx, b.base, b.length);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff b.base = NULL;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff b.length = 0;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
58ff88cca7c169f7fbebc9b6e93bbba1fb345157Michael Graff pkt.pktflags = 0;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff pkt.serial = 0x11223344;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff pkt.recvlength = 0x55667788;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff pkt.result = 0xdeadbeef;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff noopresponse.datalength = strlen(TESTSTRING);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence /* XXXDCL maybe "noopresponse.data" should be const. */
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence DE_CONST(TESTSTRING, noopresponse.data);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ret = lwres_noopresponse_render(ctx, &noopresponse, &pkt, &b);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff CHECK(ret, "lwres_noopresponse_render");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff hexdump("rendered noop response", b.base, b.used);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff /*
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * Now, parse it into a new structure.
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff */
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff lwres_buffer_first(&b);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ret = lwres_lwpacket_parseheader(&b, &pkt2);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff CHECK(ret, "lwres_lwpacket_parseheader");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff hexdump("parsed pkt2", &pkt2, sizeof(pkt2));
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff noopresponse2 = NULL;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ret = lwres_noopresponse_parse(ctx, &b, &pkt2, &noopresponse2);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff CHECK(ret, "lwres_noopresponse_parse");
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff assert(noopresponse.datalength == noopresponse2->datalength);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff assert(memcmp(noopresponse.data, noopresponse2->data,
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff noopresponse.datalength) == 0);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff lwres_noopresponse_free(ctx, &noopresponse2);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff lwres_context_freemem(ctx, b.base, b.length);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff b.base = NULL;
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff b.length = 0;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff}
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffstatic void
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencetest_gabn(const char *target) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff lwres_gabnresponse_t *res;
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff lwres_addr_t *addr;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff int ret;
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff unsigned int i;
e24f605ad64182532640dc6721070456b13112d5Michael Graff char outbuf[64];
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff res = NULL;
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff ret = lwres_getaddrsbyname(ctx, target,
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6,
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff &res);
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff printf("gabn %s ret == %d\n", target, ret);
4e675038a097065ff13944232cd7c89ac5961984Michael Graff if (ret != 0) {
4e675038a097065ff13944232cd7c89ac5961984Michael Graff printf("FAILURE!\n");
4e675038a097065ff13944232cd7c89ac5961984Michael Graff if (res != NULL)
4e675038a097065ff13944232cd7c89ac5961984Michael Graff lwres_gabnresponse_free(ctx, &res);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff return;
4e675038a097065ff13944232cd7c89ac5961984Michael Graff }
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff printf("Returned real name: (%u, %s)\n",
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff res->realnamelen, res->realname);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff printf("%u aliases:\n", res->naliases);
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < res->naliases; i++)
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff printf("%u addresses:\n", res->naddrs);
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff addr = LWRES_LIST_HEAD(res->addrs);
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < res->naddrs; i++) {
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff INSIST(addr != NULL);
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff if (addr->family == LWRES_ADDRTYPE_V4)
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff (void)inet_ntop(AF_INET, addr->address,
e24f605ad64182532640dc6721070456b13112d5Michael Graff outbuf, sizeof(outbuf));
e24f605ad64182532640dc6721070456b13112d5Michael Graff else
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff (void)inet_ntop(AF_INET6, addr->address,
e24f605ad64182532640dc6721070456b13112d5Michael Graff outbuf, sizeof(outbuf));
e24f605ad64182532640dc6721070456b13112d5Michael Graff printf("\tAddr len %u family %08x %s\n",
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff addr->length, addr->family, outbuf);
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff addr = LWRES_LIST_NEXT(addr, link);
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff }
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff lwres_gabnresponse_free(ctx, &res);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff}
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffstatic void
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencetest_gnba(const char *target, lwres_uint32_t af) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff lwres_gnbaresponse_t *res;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff int ret;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff unsigned int i;
e24f605ad64182532640dc6721070456b13112d5Michael Graff unsigned char addrbuf[16];
e24f605ad64182532640dc6721070456b13112d5Michael Graff unsigned int len;
e24f605ad64182532640dc6721070456b13112d5Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff if (af == LWRES_ADDRTYPE_V4) {
e24f605ad64182532640dc6721070456b13112d5Michael Graff len = 4;
e24f605ad64182532640dc6721070456b13112d5Michael Graff ret = inet_pton(AF_INET, target, addrbuf);
e24f605ad64182532640dc6721070456b13112d5Michael Graff assert(ret == 1);
e24f605ad64182532640dc6721070456b13112d5Michael Graff } else {
e24f605ad64182532640dc6721070456b13112d5Michael Graff len = 16;
e24f605ad64182532640dc6721070456b13112d5Michael Graff ret = inet_pton(AF_INET6, target, addrbuf);
e24f605ad64182532640dc6721070456b13112d5Michael Graff assert(ret == 1);
e24f605ad64182532640dc6721070456b13112d5Michael Graff }
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff res = NULL;
e24f605ad64182532640dc6721070456b13112d5Michael Graff ret = lwres_getnamebyaddr(ctx, af, len, addrbuf, &res);
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff printf("gnba %s ret == %d\n", target, ret);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff assert(ret == 0);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff assert(res != NULL);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff printf("Returned real name: (%u, %s)\n",
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff res->realnamelen, res->realname);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff printf("%u aliases:\n", res->naliases);
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < res->naliases; i++)
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff lwres_gnbaresponse_free(ctx, &res);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#ifdef USE_ISC_MEM
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff/*
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * Wrappers around our memory management stuff, for the lwres functions.
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff */
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffstatic void *
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencemem_alloc(void *arg, size_t size) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff return (isc_mem_get(arg, size));
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graffstatic void
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencemem_free(void *arg, void *mem, size_t size) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_mem_put(arg, mem, size);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff}
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#endif
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffint
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrencemain(int argc, char *argv[]) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff int ret;
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#ifdef USE_ISC_MEM
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_mem_t *mem;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_result_t result;
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#endif
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff (void)argc;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff (void)argv;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#ifdef USE_ISC_MEM
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff mem = NULL;
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff result = isc_mem_create(0, 0, &mem);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff INSIST(result == ISC_R_SUCCESS);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#endif
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff ctx = NULL;
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#ifdef USE_ISC_MEM
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#else
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#endif
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff CHECK(ret, "lwres_context_create");
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff ret = lwres_conf_parse(ctx, "/etc/resolv.conf");
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff CHECK(ret, "lwres_conf_parse");
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff lwres_conf_print(ctx, stdout);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff test_noop();
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff /*
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff * The following comments about tests all assume your search path is
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff * nominum.com isc.org flame.org
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff * and ndots is the default of 1.
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff */
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff test_gabn("alias-05.test"); /* exact, then search. */
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff test_gabn("f.root-servers.net.");
e24f605ad64182532640dc6721070456b13112d5Michael Graff test_gabn("poofball.flame.org.");
4e675038a097065ff13944232cd7c89ac5961984Michael Graff test_gabn("foo.ip6.int.");
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff test_gabn("notthereatall.flame.org"); /* exact, then search (!found)*/
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff test_gabn("shell"); /* search (found in nominum.com), then exact */
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff test_gabn("kechara"); /* search (found in flame.org), then exact */
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff test_gabn("lkasdjlaksjdlkasjdlkasjdlkasjd"); /* search, exact(!found)*/
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff
e24f605ad64182532640dc6721070456b13112d5Michael Graff test_gnba("198.133.199.1", LWRES_ADDRTYPE_V4);
e24f605ad64182532640dc6721070456b13112d5Michael Graff test_gnba("204.152.184.79", LWRES_ADDRTYPE_V4);
e24f605ad64182532640dc6721070456b13112d5Michael Graff test_gnba("3ffe:8050:201:1860:42::1", LWRES_ADDRTYPE_V6);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff lwres_conf_clear(ctx);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_context_destroy(&ctx);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#ifdef USE_ISC_MEM
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_mem_stats(mem, stdout);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff isc_mem_destroy(&mem);
74889a341cac183d477e15cfead391a8f7bdba95Michael Graff#endif
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff return (0);
a3ab70dae26d009bf78b0594b2ab5eb9208f4b91Michael Graff}