1 /* $NetBSD: getaddrinfo-test.c,v 1.1.1.1 2011/04/13 18:15:41 elric Exp $ */
4 * Copyright (c) 1999 - 2000 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <krb5/roken.h>
39 #include <krb5/getarg.h>
45 static int verbose_counter
;
46 static int version_flag
;
49 static struct getargs args
[] = {
50 {"verbose", 0, arg_counter
, &verbose_counter
,"verbose", NULL
},
51 {"flags", 0, arg_integer
, &flags
, "flags", NULL
},
52 {"family", 0, arg_integer
, &family
, "family", NULL
},
53 {"socktype",0, arg_integer
, &socktype
, "socktype", NULL
},
54 {"version", 0, arg_flag
, &version_flag
, "print version",NULL
},
55 {"help", 0, arg_flag
, &help_flag
, NULL
, NULL
}
62 sizeof(args
) / sizeof(args
[0]),
64 "[nodename servname...]");
69 doit (const char *nodename
, const char *servname
)
71 struct addrinfo hints
;
72 struct addrinfo
*res
, *r
;
76 printf ("(%s,%s)... ", nodename
? nodename
: "null", servname
);
78 memset (&hints
, 0, sizeof(hints
));
79 hints
.ai_flags
= flags
;
80 hints
.ai_family
= family
;
81 hints
.ai_socktype
= socktype
;
83 ret
= getaddrinfo (nodename
, servname
, &hints
, &res
);
85 errx(1, "error: %s\n", gai_strerror(ret
));
90 for (r
= res
; r
!= NULL
; r
= r
->ai_next
) {
93 if (inet_ntop (r
->ai_family
,
94 socket_get_address (r
->ai_addr
),
95 addrstr
, sizeof(addrstr
)) == NULL
) {
97 printf ("\tbad address?\n");
100 if (verbose_counter
) {
101 printf ("\tfamily = %d, socktype = %d, protocol = %d, "
102 "address = \"%s\", port = %d",
103 r
->ai_family
, r
->ai_socktype
, r
->ai_protocol
,
105 ntohs(socket_get_port (r
->ai_addr
)));
107 printf (", canonname = \"%s\"", r
->ai_canonname
);
115 main(int argc
, char **argv
)
120 setprogname (argv
[0]);
122 if (getarg (args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
,
130 fprintf (stderr
, "%s from %s-%s\n", getprogname(), PACKAGE
, VERSION
);
140 for (i
= 0; i
< argc
; i
+= 2) {
141 const char *nodename
= argv
[i
];
143 if (strcmp (nodename
, "null") == 0)
146 doit (nodename
, argv
[i
+1]);