2 * Copyright (c) 1995 - 2004 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #ifdef HAVE_ARPA_NAMESER_H
40 #include <arpa/nameser.h>
47 static int version_flag
= 0;
48 static int help_flag
= 0;
50 static struct getargs args
[] = {
51 {"version", 0, arg_flag
, &version_flag
,
52 "print version", NULL
},
53 {"help", 0, arg_flag
, &help_flag
,
61 sizeof(args
)/sizeof(*args
),
63 "dns-record resource-record-type");
68 main(int argc
, char **argv
)
70 struct rk_dns_reply
*r
;
71 struct rk_resource_record
*rr
;
74 setprogname (argv
[0]);
76 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
83 printf("some version\n");
93 r
= rk_dns_lookup(argv
[0], argv
[1]);
95 printf("No reply.\n");
98 if(r
->q
.type
== rk_ns_t_srv
)
101 for(rr
= r
->head
; rr
;rr
=rr
->next
){
102 printf("%-30s %-5s %-6d ", rr
->domain
, rk_dns_type_to_string(rr
->type
), rr
->ttl
);
107 printf("%s\n", (char*)rr
->u
.data
);
110 printf("%s\n", inet_ntoa(*rr
->u
.a
));
114 printf("%d %s\n", rr
->u
.mx
->preference
, rr
->u
.mx
->domain
);
118 struct rk_srv_record
*srv
= rr
->u
.srv
;
119 printf("%d %d %d %s\n", srv
->priority
, srv
->weight
,
120 srv
->port
, srv
->target
);
124 printf("%s\n", rr
->u
.txt
);
128 struct rk_sig_record
*sig
= rr
->u
.sig
;
129 const char *type_string
= rk_dns_type_to_string (sig
->type
);
131 printf ("type %u (%s), algorithm %u, labels %u, orig_ttl %u, sig_expiration %u, sig_inception %u, key_tag %u, signer %s\n",
132 sig
->type
, type_string
? type_string
: "",
133 sig
->algorithm
, sig
->labels
, sig
->orig_ttl
,
134 sig
->sig_expiration
, sig
->sig_inception
, sig
->key_tag
,
139 struct rk_key_record
*key
= rr
->u
.key
;
141 printf ("flags %u, protocol %u, algorithm %u\n",
142 key
->flags
, key
->protocol
, key
->algorithm
);
145 case rk_ns_t_sshfp
: {
146 struct rk_sshfp_record
*sshfp
= rr
->u
.sshfp
;
149 printf ("alg %u type %u length %lu data ", sshfp
->algorithm
,
150 sshfp
->type
, (unsigned long)sshfp
->sshfp_len
);
151 for (i
= 0; i
< sshfp
->sshfp_len
; i
++)
152 printf("%02X", sshfp
->sshfp_data
[i
]);
158 struct rk_ds_record
*ds
= rr
->u
.ds
;
161 printf ("key tag %u alg %u type %u length %u data ",
162 ds
->key_tag
, ds
->algorithm
, ds
->digest_type
,
164 for (i
= 0; i
< ds
->digest_len
; i
++)
165 printf("%02X", ds
->digest_data
[i
]);