1 /* $NetBSD: resolve-test.c,v 1.1.1.2 2014/04/24 12:45:52 pettai Exp $ */
4 * Copyright (c) 1995 - 2004 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
39 #include <krb5/roken.h>
40 #include <krb5/getarg.h>
41 #ifdef HAVE_ARPA_NAMESER_H
42 #include <arpa/nameser.h>
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
,
66 sizeof(args
)/sizeof(*args
),
68 "dns-record resource-record-type");
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
))
88 printf("some version\n");
98 for (i
= 0; i
< loop_integer
; i
++) {
100 r
= rk_dns_lookup(argv
[0], argv
[1]);
102 printf("No reply.\n");
106 if(r
->q
.type
== rk_ns_t_srv
)
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
);
115 printf("%s\n", (char*)rr
->u
.data
);
118 printf("%s\n", inet_ntoa(*rr
->u
.a
));
122 printf("%d %s\n", rr
->u
.mx
->preference
, rr
->u
.mx
->domain
);
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
);
132 printf("%s\n", rr
->u
.txt
);
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
,
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
);
153 case rk_ns_t_sshfp
: {
154 struct rk_sshfp_record
*sshfp
= rr
->u
.sshfp
;
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
]);
166 struct rk_ds_record
*ds
= rr
->u
.ds
;
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
]);