From 643168599fc9fe58ae1779ac93e435b3fa934eee Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 26 Jan 2000 02:58:39 +0000 Subject: [PATCH] Test getipnodebyname() & gethostbyname() implementations. --- bin/tests/gxbn_test.c | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 bin/tests/gxbn_test.c diff --git a/bin/tests/gxbn_test.c b/bin/tests/gxbn_test.c new file mode 100644 index 0000000000..eb3076d648 --- /dev/null +++ b/bin/tests/gxbn_test.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2000 Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#include +#include +#include + +static void +print_he(struct hostent *he, int error, const char *fun, const char *name) { + char **c; + int i; + + if (he != NULL) { + printf("%s(%s):\n", fun, name); + printf("\tname = %s\n", he->h_name); + printf("\taddrtype = %d\n", he->h_addrtype); + printf("\tlength = %d\n", he->h_length); + c = he->h_aliases; + i = 1; + while (*c != NULL) { + printf("\talias[%d] = %s\n", i, *c); + i++; + c++; + } + c = he->h_addr_list; + i = 1; + while (*c != NULL) { + char buf[128]; + inet_ntop(he->h_addrtype, c, buf, sizeof (buf)); + printf("\taddress[%d] = %s\n", i, buf); + c++; + i++; + } + } else { + printf("%s(%s): error = %d\n", fun, name, error); + } +} + +int +main(int argc, char **argv) { + struct hostent *he; + char **c; + int error; + + while (argv[1] != NULL) { + he = gethostbyname(argv[1]); + print_he(he, 0 /* XXX h_errno */, "gethostbyname", argv[1]); + + he = getipnodebyname(argv[1], AF_INET, AI_DEFAULT|AI_ALL, + &error); + print_he(he, error, "getipnodebyname", argv[1]); + if (he != NULL) + freehostent(he); + argv++; + } + exit(0); +}