Annotation of 43BSDReno/usr.bin/whois/whois.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980 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) 1980 Regents of the University of California.\n\
        !            23:  All rights reserved.\n";
        !            24: #endif /* not lint */
        !            25: 
        !            26: #ifndef lint
        !            27: static char sccsid[] = "@(#)whois.c    5.9 (Berkeley) 6/1/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: #include <sys/types.h>
        !            31: #include <sys/socket.h>
        !            32: #include <netinet/in.h>
        !            33: #include <netdb.h>
        !            34: #include <stdio.h>
        !            35: 
        !            36: #define        NICHOST "nic.ddn.mil"
        !            37: 
        !            38: main(argc, argv)
        !            39:        int argc;
        !            40:        char **argv;
        !            41: {
        !            42:        extern char *optarg;
        !            43:        extern int optind;
        !            44:        register FILE *sfi, *sfo;
        !            45:        register int ch;
        !            46:        struct sockaddr_in sin;
        !            47:        struct hostent *hp;
        !            48:        struct servent *sp;
        !            49:        int s;
        !            50:        char *host;
        !            51: 
        !            52:        host = NICHOST;
        !            53:        while ((ch = getopt(argc, argv, "h:")) != EOF)
        !            54:                switch((char)ch) {
        !            55:                case 'h':
        !            56:                        host = optarg;
        !            57:                        break;
        !            58:                case '?':
        !            59:                default:
        !            60:                        usage();
        !            61:                }
        !            62:        argc -= optind;
        !            63:        argv += optind;
        !            64: 
        !            65:        if (argc != 1)
        !            66:                usage();
        !            67: 
        !            68:        hp = gethostbyname(host);
        !            69:        if (hp == NULL) {
        !            70:                (void)fprintf(stderr, "whois: %s: ", host);
        !            71:                herror((char *)NULL);
        !            72:                exit(1);
        !            73:        }
        !            74:        host = hp->h_name;
        !            75:        s = socket(hp->h_addrtype, SOCK_STREAM, 0);
        !            76:        if (s < 0) {
        !            77:                perror("whois: socket");
        !            78:                exit(2);
        !            79:        }
        !            80:        bzero((caddr_t)&sin, sizeof (sin));
        !            81:        sin.sin_family = hp->h_addrtype;
        !            82:        if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
        !            83:                perror("whois: bind");
        !            84:                exit(3);
        !            85:        }
        !            86:        bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
        !            87:        sp = getservbyname("whois", "tcp");
        !            88:        if (sp == NULL) {
        !            89:                (void)fprintf(stderr, "whois: whois/tcp: unknown service\n");
        !            90:                exit(4);
        !            91:        }
        !            92:        sin.sin_port = sp->s_port;
        !            93:        if (connect(s, &sin, sizeof(sin)) < 0) {
        !            94:                perror("whois: connect");
        !            95:                exit(5);
        !            96:        }
        !            97:        sfi = fdopen(s, "r");
        !            98:        sfo = fdopen(s, "w");
        !            99:        if (sfi == NULL || sfo == NULL) {
        !           100:                perror("whois: fdopen");
        !           101:                (void)close(s);
        !           102:                exit(1);
        !           103:        }
        !           104:        (void)fprintf(sfo, "%s\r\n", *argv);
        !           105:        (void)fflush(sfo);
        !           106:        while ((ch = getc(sfi)) != EOF)
        !           107:                putchar(ch);
        !           108:        exit(0);
        !           109: }
        !           110: 
        !           111: static
        !           112: usage()
        !           113: {
        !           114:        (void)fprintf(stderr, "usage: whois [-h host] name\n");
        !           115:        exit(1);
        !           116: }

unix.superglobalmegacorp.com

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