lwres_test.c revision b6b21d80450f81d873d7e8cd21e7b72fdf512507
523ad879ce1abb51cae579a6393da0e0436fe8dfTinderbox User * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000, 2001 Internet Software Consortium.
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.
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.
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id: lwres_test.c,v 1.28 2005/03/16 22:22:29 marka Exp $ */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsstatic inline void
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrewshexdump(const char *msg, void *base, size_t len) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley unsigned char *p;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley unsigned int cnt;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews printf("*** %s (%lu bytes @ %p)\n", msg, (unsigned long)len, base);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic const char *TESTSTRING = "This is a test. This is only a test. !!!";
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley lwres_noopresponse_t noopresponse, *noopresponse2;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley /* XXXDCL maybe "nooprequest.data" should be const. */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ret = lwres_nooprequest_render(ctx, &nooprequest, &pkt, &b);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley hexdump("rendered noop request", b.base, b.used);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Now, parse it into a new structure.
7cd4c3ddd1baf5f2b204562fdba3da37c716cc78Andreas Gustafsson ret = lwres_nooprequest_parse(ctx, &b, &pkt2, &nooprequest2);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews assert(nooprequest.datalength == nooprequest2->datalength);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews assert(memcmp(nooprequest.data, nooprequest2->data,
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews /* XXXDCL maybe "noopresponse.data" should be const. */
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews ret = lwres_noopresponse_render(ctx, &noopresponse, &pkt, &b);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley hexdump("rendered noop response", b.base, b.used);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Now, parse it into a new structure.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley ret = lwres_noopresponse_parse(ctx, &b, &pkt2, &noopresponse2);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley assert(noopresponse.datalength == noopresponse2->datalength);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley assert(memcmp(noopresponse.data, noopresponse2->data,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned int i;
7cd4c3ddd1baf5f2b204562fdba3da37c716cc78Andreas Gustafsson printf("gabn %s ret == %d\n", target, ret);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleytest_gnba(const char *target, lwres_uint32_t af) {
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley unsigned int i;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley unsigned int len;
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halley ret = lwres_getnamebyaddr(ctx, af, len, addrbuf, &res);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews printf("\t(%u, %s)\n", res->aliaslen[i], res->aliases[i]);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Wrappers around our memory management stuff, for the lwres functions.
e0df061f35a26d2bbd0986aa889f88b3710b32d4Bob Halleystatic void *
66b2f0d4bfa342770aa5e26a005a0c0ec5071231Bob Halley ret = lwres_context_create(&ctx, mem, mem_alloc, mem_free, 0);
421e4cf66e4cba0b0751a34a9c027e39fe0474f9Mark Andrews ret = lwres_context_create(&ctx, NULL, NULL, NULL, 0);
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.
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley test_gabn("alias-05.test"); /* exact, then search. */
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)*/
569d094440399b000e059d4cb3434391c2c4d330Michael Graff test_gnba("3ffe:8050:201:1860:42::1", LWRES_ADDRTYPE_V6);