Annotation of 43BSDTahoe/etc/named/tools/nsquery.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)nsquery.c  4.2 (Berkeley) 11/21/87";
        !             3: #endif
        !             4: 
        !             5: /*
        !             6:  * Copyright (c) 1986 Regents of the University of California
        !             7:  *     All Rights Reserved
        !             8:  */
        !             9: 
        !            10: #include <stdio.h>
        !            11: #include <sys/types.h>
        !            12: #include <arpa/nameser.h>
        !            13: #include <netdb.h>
        !            14: #include <sys/socket.h>
        !            15: #include <netinet/in.h>
        !            16: #include <resolv.h>
        !            17: 
        !            18: struct state orig;
        !            19: extern struct state _res;
        !            20: extern int h_errno;
        !            21: 
        !            22: main(c, v)
        !            23:        char **v;
        !            24: {
        !            25:        char h[32];
        !            26:        register struct hostent *hp;
        !            27:        register char *s;
        !            28: 
        !            29:        gethostname(h, 32);
        !            30:        s = h;
        !            31:        if (c < 2) {
        !            32:                fprintf(stderr, "Usage: lookup host [server]\n");
        !            33:                exit(1);
        !            34:        }
        !            35:        if (c > 2)
        !            36:                s = v[2];
        !            37: 
        !            38:        hp = gethostbyname(s);
        !            39:        if (hp == NULL) {
        !            40:                herror(h_errno);
        !            41:                exit(1);
        !            42:        }
        !            43:        printanswer(hp);
        !            44: 
        !            45:        _res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr;
        !            46:        _res.options &= ~RES_DEFNAMES;
        !            47: 
        !            48:        hp = gethostbyname(v[1]);
        !            49:        if (hp == NULL) {
        !            50:                herror(h_errno);
        !            51:                exit(1);
        !            52:        }
        !            53:        printanswer(hp);
        !            54:        exit(0);
        !            55: }
        !            56: 
        !            57: printanswer(hp)
        !            58:        register struct hostent *hp;
        !            59: {
        !            60:        register char **cp;
        !            61:        extern char *inet_ntoa();
        !            62: 
        !            63:        printf("Name: %s\n", hp->h_name);
        !            64:        printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr));
        !            65:        printf("Aliases:");
        !            66:        for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
        !            67:                printf(" %s", *cp);
        !            68:        printf("\n\n");
        !            69: }

unix.superglobalmegacorp.com

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