0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
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/.
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: lwres_test.c,v 1.31 2007/06/19 23:46:59 tbox Exp $ */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graffstatic inline void
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff fprintf(stderr, "%s returned %d\n", msg, val);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencehexdump(const char *msg, void *base, size_t len) {
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff unsigned char *p;
b6b21d80450f81d873d7e8cd21e7b72fdf512507Mark Andrews printf("*** %s (%lu bytes @ %p)\n", msg, (unsigned long)len, base);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencestatic const char *TESTSTRING = "This is a test. This is only a test. !!!";
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_nooprequest_t nooprequest, *nooprequest2;
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff lwres_noopresponse_t noopresponse, *noopresponse2;
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence /* XXXDCL maybe "nooprequest.data" should be const. */
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ret = lwres_nooprequest_render(ctx, &nooprequest, &pkt, &b);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff hexdump("rendered noop request", b.base, b.used);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff * Now, parse it into a new structure.
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff ret = lwres_nooprequest_parse(ctx, &b, &pkt2, &nooprequest2);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff assert(nooprequest.datalength == nooprequest2->datalength);
e4f074a2c2340ea80099beebecc3b89aa234fa8fMichael Graff assert(memcmp(nooprequest.data, nooprequest2->data,
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrence /* XXXDCL maybe "noopresponse.data" should be const. */
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ret = lwres_noopresponse_render(ctx, &noopresponse, &pkt, &b);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff hexdump("rendered noop response", b.base, b.used);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff * Now, parse it into a new structure.
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff ret = lwres_noopresponse_parse(ctx, &b, &pkt2, &noopresponse2);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff assert(noopresponse.datalength == noopresponse2->datalength);
c05e003dce672b2f8555a3e56857f29ce89c1677Michael Graff assert(memcmp(noopresponse.data, noopresponse2->data,
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff unsigned int i;
291b0d910d115e41a4b69d0603c3376aebf0c630Michael Graff printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
1b6d529cb5ee0ad44f8518e1b8c2cbca54bbdf18David Lawrencetest_gnba(const char *target, lwres_uint32_t af) {
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff unsigned int i;
e24f605ad64182532640dc6721070456b13112d5Michael Graff ret = lwres_getnamebyaddr(ctx, af, len, addrbuf, &res);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
ae7d0a4375abaecfd5c5b0816616d9882831e69bMichael Graff * Wrappers around our memory management stuff, for the lwres functions.
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0);
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0);
2311073ce0ef26c0250e91e4a083d7cc94fa7d33Michael Graff ret = lwres_conf_parse(ctx, "/etc/resolv.conf");
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 test_gabn("alias-05.test"); /* exact, then search. */
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)*/
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);