1 /* $OpenBSD: getrrsetbyname.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */
2 /*
3 * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <sys/types.h>
19
20 #include <netinet/in.h>
21 #include <arpa/nameser.h>
22
23 #include <err.h>
24 #include <errno.h>
25 #include <getopt.h>
26 #include <resolv.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "common.h"
32
33 static void
usage(void)34 usage(void)
35 {
36 extern const char * __progname;
37
38 fprintf(stderr, "usage: %s [-e] [-t type] [host...]\n",
39 __progname);
40 exit(1);
41 }
42
43 int
main(int argc,char * argv[])44 main(int argc, char *argv[])
45 {
46 int ch, i;
47 uint16_t type = T_A;
48 char *host;
49 struct rrsetinfo *rrset;
50
51 while((ch = getopt(argc, argv, "R:et:")) != -1) {
52 switch(ch) {
53 case 'R':
54 parseresopt(optarg);
55 break;
56 case 'e':
57 long_err += 1;
58 break;
59 case 't':
60 if ((type = strtotype(optarg)) == 0)
61 usage();
62 break;
63 default:
64 usage();
65 /* NOTREACHED */
66 }
67 }
68 argc -= optind;
69 argv += optind;
70
71 for (i = 0; i < argc; i++) {
72
73 if (i)
74 printf("\n");
75 printf("===> \"%s\"\n", argv[i]);
76 host = gethostarg(argv[i]);
77
78 errno = 0;
79 h_errno = 0;
80 gai_errno = 0;
81 rrset_errno = 0;
82
83 rrset_errno = getrrsetbyname(host, C_IN, type, 0, &rrset);
84
85 if (rrset_errno == 0)
86 print_rrsetinfo(rrset);
87 print_errors();
88 }
89
90 return (0);
91 }
92