etc/services - sync with NetBSD-8
[minix.git] / crypto / external / bsd / heimdal / dist / lib / roken / resolve-test.c
blob8a3e5aad5331e8dad530021386a8b2ff89012915
1 /* $NetBSD: resolve-test.c,v 1.1.1.2 2014/04/24 12:45:52 pettai Exp $ */
3 /*
4 * Copyright (c) 1995 - 2004 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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
33 * SUCH DAMAGE.
37 #include <config.h>
39 #include <krb5/roken.h>
40 #include <krb5/getarg.h>
41 #ifdef HAVE_ARPA_NAMESER_H
42 #include <arpa/nameser.h>
43 #endif
44 #ifdef HAVE_RESOLV_H
45 #include <resolv.h>
46 #endif
47 #include <krb5/resolve.h>
49 static int loop_integer = 1;
50 static int version_flag = 0;
51 static int help_flag = 0;
53 static struct getargs args[] = {
54 {"loop", 0, arg_integer, &loop_integer,
55 "loop resolving", NULL },
56 {"version", 0, arg_flag, &version_flag,
57 "print version", NULL },
58 {"help", 0, arg_flag, &help_flag,
59 NULL, NULL }
62 static void
63 usage (int ret)
65 arg_printusage (args,
66 sizeof(args)/sizeof(*args),
67 NULL,
68 "dns-record resource-record-type");
69 exit (ret);
72 int
73 main(int argc, char **argv)
75 struct rk_dns_reply *r;
76 struct rk_resource_record *rr;
77 int optidx = 0, i, exit_code = 0;
79 setprogname (argv[0]);
81 if(getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
82 usage(1);
84 if (help_flag)
85 usage (0);
87 if(version_flag){
88 printf("some version\n");
89 exit(0);
92 argc -= optidx;
93 argv += optidx;
95 if (argc != 2)
96 usage(1);
98 for (i = 0; i < loop_integer; i++) {
100 r = rk_dns_lookup(argv[0], argv[1]);
101 if(r == NULL){
102 printf("No reply.\n");
103 exit_code = 1;
104 break;
106 if(r->q.type == rk_ns_t_srv)
107 rk_dns_srv_order(r);
109 for(rr = r->head; rr;rr=rr->next){
110 printf("%-30s %-5s %-6d ", rr->domain, rk_dns_type_to_string(rr->type), rr->ttl);
111 switch(rr->type){
112 case rk_ns_t_ns:
113 case rk_ns_t_cname:
114 case rk_ns_t_ptr:
115 printf("%s\n", (char*)rr->u.data);
116 break;
117 case rk_ns_t_a:
118 printf("%s\n", inet_ntoa(*rr->u.a));
119 break;
120 case rk_ns_t_mx:
121 case rk_ns_t_afsdb:{
122 printf("%d %s\n", rr->u.mx->preference, rr->u.mx->domain);
123 break;
125 case rk_ns_t_srv:{
126 struct rk_srv_record *srv = rr->u.srv;
127 printf("%d %d %d %s\n", srv->priority, srv->weight,
128 srv->port, srv->target);
129 break;
131 case rk_ns_t_txt: {
132 printf("%s\n", rr->u.txt);
133 break;
135 case rk_ns_t_sig : {
136 struct rk_sig_record *sig = rr->u.sig;
137 const char *type_string = rk_dns_type_to_string (sig->type);
139 printf ("type %u (%s), algorithm %u, labels %u, orig_ttl %u, sig_expiration %u, sig_inception %u, key_tag %u, signer %s\n",
140 sig->type, type_string ? type_string : "",
141 sig->algorithm, sig->labels, sig->orig_ttl,
142 sig->sig_expiration, sig->sig_inception, sig->key_tag,
143 sig->signer);
144 break;
146 case rk_ns_t_key : {
147 struct rk_key_record *key = rr->u.key;
149 printf ("flags %u, protocol %u, algorithm %u\n",
150 key->flags, key->protocol, key->algorithm);
151 break;
153 case rk_ns_t_sshfp : {
154 struct rk_sshfp_record *sshfp = rr->u.sshfp;
155 size_t i;
157 printf ("alg %u type %u length %lu data ", sshfp->algorithm,
158 sshfp->type, (unsigned long)sshfp->sshfp_len);
159 for (i = 0; i < sshfp->sshfp_len; i++)
160 printf("%02X", sshfp->sshfp_data[i]);
161 printf("\n");
163 break;
165 case rk_ns_t_ds : {
166 struct rk_ds_record *ds = rr->u.ds;
167 size_t i;
169 printf ("key tag %u alg %u type %u length %lu data ",
170 ds->key_tag, ds->algorithm, ds->digest_type,
171 (unsigned long)ds->digest_len);
172 for (i = 0; i < ds->digest_len; i++)
173 printf("%02X", ds->digest_data[i]);
174 printf("\n");
176 break;
178 default:
179 printf("\n");
180 break;
183 rk_dns_free_data(r);
186 return exit_code;