1 /* $NetBSD: gxba_test.c,v 1.6 2014/12/10 04:37:53 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: gxba_test.c,v 1.13 2007/06/19 23:46:59 tbox Exp */
29 #include <lwres/netdb.h>
32 print_he(struct hostent
*he
, int error
, const char *fun
, const char *name
) {
37 printf("%s(%s):\n", fun
, name
);
38 printf("\tname = %s\n", he
->h_name
);
39 printf("\taddrtype = %d\n", he
->h_addrtype
);
40 printf("\tlength = %d\n", he
->h_length
);
44 printf("\talias[%d] = %s\n", i
, *c
);
52 inet_ntop(he
->h_addrtype
, *c
, buf
, sizeof(buf
));
53 printf("\taddress[%d] = %s\n", i
, buf
);
58 printf("%s(%s): error = %d (%s)\n", fun
, name
, error
,
64 main(int argc
, char **argv
) {
67 struct in_addr in_addr
;
68 struct in6_addr in6_addr
;
75 while (argv
[1] != NULL
) {
76 if (inet_pton(AF_INET
, argv
[1], &in_addr
) == 1) {
79 len
= sizeof(in_addr
);
80 } else if (inet_pton(AF_INET6
, argv
[1], &in6_addr
) == 1) {
83 len
= sizeof(in6_addr
);
85 printf("unable to convert \"%s\" to an address\n",
90 he
= gethostbyaddr(addr
, len
, af
);
91 print_he(he
, h_errno
, "gethostbyaddr", argv
[1]);
93 he
= getipnodebyaddr(addr
, len
, af
, &error
);
94 print_he(he
, error
, "getipnodebyaddr", argv
[1]);