1*a9e85050Seric /* $OpenBSD: getrrsetbyname.c,v 1.2 2018/12/15 15:16:12 eric Exp $ */
24c1e55dcSeric /*
34c1e55dcSeric * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
44c1e55dcSeric *
54c1e55dcSeric * Permission to use, copy, modify, and distribute this software for any
64c1e55dcSeric * purpose with or without fee is hereby granted, provided that the above
74c1e55dcSeric * copyright notice and this permission notice appear in all copies.
84c1e55dcSeric *
94c1e55dcSeric * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
104c1e55dcSeric * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
114c1e55dcSeric * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
124c1e55dcSeric * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
134c1e55dcSeric * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
144c1e55dcSeric * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
154c1e55dcSeric * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
164c1e55dcSeric */
174c1e55dcSeric
184c1e55dcSeric #include <sys/types.h>
194c1e55dcSeric
204c1e55dcSeric #include <netinet/in.h>
214c1e55dcSeric #include <arpa/nameser.h>
224c1e55dcSeric
234c1e55dcSeric #include <err.h>
244c1e55dcSeric #include <errno.h>
254c1e55dcSeric #include <getopt.h>
264c1e55dcSeric #include <resolv.h>
274c1e55dcSeric #include <stdio.h>
284c1e55dcSeric #include <stdlib.h>
294c1e55dcSeric #include <string.h>
304c1e55dcSeric
314c1e55dcSeric #include "common.h"
324c1e55dcSeric
334c1e55dcSeric static void
usage(void)344c1e55dcSeric usage(void)
354c1e55dcSeric {
364c1e55dcSeric extern const char * __progname;
374c1e55dcSeric
384c1e55dcSeric fprintf(stderr, "usage: %s [-e] [-t type] [host...]\n",
394c1e55dcSeric __progname);
404c1e55dcSeric exit(1);
414c1e55dcSeric }
424c1e55dcSeric
434c1e55dcSeric int
main(int argc,char * argv[])444c1e55dcSeric main(int argc, char *argv[])
454c1e55dcSeric {
464c1e55dcSeric int ch, i;
474c1e55dcSeric uint16_t type = T_A;
484c1e55dcSeric char *host;
494c1e55dcSeric struct rrsetinfo *rrset;
504c1e55dcSeric
51*a9e85050Seric while((ch = getopt(argc, argv, "R:et:")) != -1) {
524c1e55dcSeric switch(ch) {
53*a9e85050Seric case 'R':
54*a9e85050Seric parseresopt(optarg);
55*a9e85050Seric break;
564c1e55dcSeric case 'e':
574c1e55dcSeric long_err += 1;
584c1e55dcSeric break;
594c1e55dcSeric case 't':
604c1e55dcSeric if ((type = strtotype(optarg)) == 0)
614c1e55dcSeric usage();
624c1e55dcSeric break;
634c1e55dcSeric default:
644c1e55dcSeric usage();
654c1e55dcSeric /* NOTREACHED */
664c1e55dcSeric }
674c1e55dcSeric }
684c1e55dcSeric argc -= optind;
694c1e55dcSeric argv += optind;
704c1e55dcSeric
714c1e55dcSeric for (i = 0; i < argc; i++) {
724c1e55dcSeric
734c1e55dcSeric if (i)
744c1e55dcSeric printf("\n");
754c1e55dcSeric printf("===> \"%s\"\n", argv[i]);
764c1e55dcSeric host = gethostarg(argv[i]);
774c1e55dcSeric
784c1e55dcSeric errno = 0;
794c1e55dcSeric h_errno = 0;
804c1e55dcSeric gai_errno = 0;
814c1e55dcSeric rrset_errno = 0;
824c1e55dcSeric
834c1e55dcSeric rrset_errno = getrrsetbyname(host, C_IN, type, 0, &rrset);
844c1e55dcSeric
854c1e55dcSeric if (rrset_errno == 0)
864c1e55dcSeric print_rrsetinfo(rrset);
874c1e55dcSeric print_errors();
884c1e55dcSeric }
894c1e55dcSeric
904c1e55dcSeric return (0);
914c1e55dcSeric }
92