Annotation of 43BSDReno/usr.sbin/named/tools/nsquery/nsquery.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1986 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted provided
                      6:  * that: (1) source distributions retain this entire copyright notice and
                      7:  * comment, and (2) distributions including binaries display the following
                      8:  * acknowledgement:  ``This product includes software developed by the
                      9:  * University of California, Berkeley and its contributors'' in the
                     10:  * documentation or other materials provided with the distribution and in
                     11:  * all advertising materials mentioning features or use of this software.
                     12:  * Neither the name of the University nor the names of its contributors may
                     13:  * be used to endorse or promote products derived from this software without
                     14:  * specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: char copyright[] =
                     22: "@(#) Copyright (c) 1986 Regents of the University of California.\n\
                     23:  All rights reserved.\n";
                     24: #endif /* not lint */
                     25: 
                     26: #ifndef lint
                     27: static char sccsid[] = "@(#)nsquery.c  4.8 (Berkeley) 6/1/90";
                     28: #endif /* not lint */
                     29: 
                     30: #include <sys/param.h>
                     31: #include <arpa/nameser.h>
                     32: #include <netdb.h>
                     33: #include <sys/socket.h>
                     34: #include <netinet/in.h>
                     35: #include <resolv.h>
                     36: #include <stdio.h>
                     37: 
                     38: main(argc, argv)
                     39:        int argc;
                     40:        char **argv;
                     41: {
                     42:        extern struct state _res;
                     43:        register struct hostent *hp;
                     44:        register char *s;
                     45: 
                     46:        if (argc >= 2 && strcmp(argv[1], "-d") == 0) {
                     47:                _res.options |= RES_DEBUG;
                     48:                argc--;
                     49:                argv++;
                     50:        }
                     51:        if (argc < 2) {
                     52:                fprintf(stderr, "usage: nsquery [-d] host [server]\n");
                     53:                exit(1);
                     54:        }
                     55:        if (argc == 3) {
                     56:                hp = gethostbyname(argv[2]);
                     57:                if (hp == NULL) {
                     58:                        fprintf(stderr, "nsquery:");
                     59:                        herror(argv[2]);
                     60:                        exit(1);
                     61:                }
                     62:                printf("\nServer:\n");
                     63:                printanswer(hp);
                     64:                _res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr;
                     65:        }
                     66: 
                     67:        hp = gethostbyname(argv[1]);
                     68:        if (hp == NULL) {
                     69:                fprintf(stderr, "nsquery: %s: ", argv[1]);
                     70:                herror((char *)NULL);
                     71:                exit(1);
                     72:        }
                     73:        printanswer(hp);
                     74:        exit(0);
                     75: }
                     76: 
                     77: printanswer(hp)
                     78:        register struct hostent *hp;
                     79: {
                     80:        register char **cp;
                     81:        extern char *inet_ntoa();
                     82: 
                     83:        printf("Name: %s\n", hp->h_name);
                     84: #if BSD >= 43 || defined(h_addr)
                     85:        printf("Addresses:");
                     86:        for (cp = hp->h_addr_list; cp && *cp; cp++)
                     87:                printf(" %s", inet_ntoa(*(struct in_addr *)(*cp)));
                     88:        printf("\n");
                     89: #else
                     90:        printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr));
                     91: #endif
                     92:        printf("Aliases:");
                     93:        for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
                     94:                printf(" %s", *cp);
                     95:        printf("\n\n");
                     96: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.