gxbn_test.c revision 499b34cea04a46823d003d4c0520c8b03e8513cb
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
f1788d67add6bf3d301e91b3f54fa3c90a87328eBrian Wellington * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
364a82f7c25b62967678027043425201a5e5171aBob Halley */
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley/* $Id: gxbn_test.c,v 1.10 2001/01/09 21:41:06 bwelling Exp $ */
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <config.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#include <stdio.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <isc/net.h>
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews#include <lwres/netdb.h>
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleystatic void
c1ee8bb4ba3e9ab1463403ed685729631de406b1Mark Andrewsprint_he(struct hostent *he, int error, const char *fun, const char *name) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley char **c;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley int i;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (he != NULL) {
b335299322e50f045f10e4636262cd2f8d407a8bMark Andrews printf("%s(%s):\n", fun, name);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("\tname = %s\n", he->h_name);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("\taddrtype = %d\n", he->h_addrtype);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("\tlength = %d\n", he->h_length);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley c = he->h_aliases;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley i = 1;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley while (*c != NULL) {
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews printf("\talias[%d] = %s\n", i, *c);
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews i++;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews c++;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews }
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews c = he->h_addr_list;
48019314431389cca5f8eba7ee9aa5bc08a67f4eMark Andrews i = 1;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley while (*c != NULL) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley char buf[128];
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley inet_ntop(he->h_addrtype, *c, buf, sizeof (buf));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("\taddress[%d] = %s\n", i, buf);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley c++;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews i++;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley }
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley } else {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley printf("%s(%s): error = %d (%s)\n", fun, name, error,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley hstrerror(error));
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence }
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleyint
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleymain(int argc, char **argv) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley struct hostent *he;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley int error;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley (void)argc;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley while (argv[1] != NULL) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley he = gethostbyname(argv[1]);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence print_he(he, h_errno, "gethostbyname", argv[1]);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley he = getipnodebyname(argv[1], AF_INET6, AI_DEFAULT|AI_ALL,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley &error);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley print_he(he, error, "getipnodebyname", argv[1]);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (he != NULL)
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley freehostent(he);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley he = getipnodebyname(argv[1], AF_INET6, AI_DEFAULT,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley &error);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley print_he(he, error, "getipnodebyname", argv[1]);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (he != NULL)
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley freehostent(he);
368b37b616234fce3d23099eb180f1dd38e1fb62Mark Andrews argv++;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley }
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley return (0);
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley}
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley