1 /* $OpenBSD: getrrsetbyname.c,v 1.1.1.1 2012/07/13 17:49:54 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 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 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, "et:")) != -1) { 52 switch(ch) { 53 case 'e': 54 long_err += 1; 55 break; 56 case 't': 57 if ((type = strtotype(optarg)) == 0) 58 usage(); 59 break; 60 default: 61 usage(); 62 /* NOTREACHED */ 63 } 64 } 65 argc -= optind; 66 argv += optind; 67 68 for (i = 0; i < argc; i++) { 69 70 if (i) 71 printf("\n"); 72 printf("===> \"%s\"\n", argv[i]); 73 host = gethostarg(argv[i]); 74 75 errno = 0; 76 h_errno = 0; 77 gai_errno = 0; 78 rrset_errno = 0; 79 80 rrset_errno = getrrsetbyname(host, C_IN, type, 0, &rrset); 81 82 if (rrset_errno == 0) 83 print_rrsetinfo(rrset); 84 print_errors(); 85 } 86 87 return (0); 88 } 89