Annotation of 42BSD/ucb/whois.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)whois.c    4.2 83/06/10";
                      3: #endif
                      4: 
                      5: #include <sys/types.h>
                      6: #include <sys/socket.h>
                      7: 
                      8: #include <netinet/in.h>
                      9: 
                     10: #include <stdio.h>
                     11: #include <netdb.h>
                     12: 
                     13: #define        NICHOST "sri-nic"
                     14: 
                     15: main(argc, argv)
                     16:        int argc;
                     17:        char *argv[];
                     18: {
                     19:        int s;
                     20:        register FILE *sfi, *sfo;
                     21:        register char c;
                     22:        char *host = NICHOST;
                     23:        struct sockaddr_in sin;
                     24:        struct hostent *hp;
                     25:        struct servent *sp;
                     26: 
                     27:        argc--, argv++;
                     28:        if (argc > 2 && strcmp(*argv, "-h") == 0) {
                     29:                argv++, argc--;
                     30:                host = *argv++;
                     31:                argc--;
                     32:        }
                     33:        if (argc != 1) {
                     34:                fprintf(stderr, "usage: whois [ -h host ] name\n");
                     35:                exit(1);
                     36:        }
                     37:        hp = gethostbyname(host);
                     38:        if (hp == NULL) {
                     39:                fprintf(stderr, "whois: %s: host unknown\n", host);
                     40:                exit(1);
                     41:        }
                     42:        host = hp->h_name;
                     43:        s = socket(hp->h_addrtype, SOCK_STREAM, 0, 0);
                     44:        if (s < 0) {
                     45:                perror("whois: socket");
                     46:                exit(2);
                     47:        }
                     48:        sin.sin_family = hp->h_addrtype;
                     49:        if (bind(s, &sin, sizeof (sin), 0) < 0) {
                     50:                perror("whois: bind");
                     51:                exit(3);
                     52:        }
                     53:        bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
                     54:        sp = getservbyname("whois", "tcp");
                     55:        if (sp == NULL) {
                     56:                fprintf(stderr, "whois: whois/tcp: unknown service\n");
                     57:                exit(4);
                     58:        }
                     59:        sin.sin_port = sp->s_port;
                     60:        if (connect(s, &sin, sizeof (sin), 0) < 0) {
                     61:                perror("whois: connect");
                     62:                exit(5);
                     63:        }
                     64:        sfi = fdopen(s, "r");
                     65:        sfo = fdopen(s, "w");
                     66:        if (sfi == NULL || sfo == NULL) {
                     67:                perror("fdopen");
                     68:                close(s);
                     69:                exit(1);
                     70:        }
                     71:        fprintf(sfo, "%s\r\n", *argv);
                     72:        fflush(sfo);
                     73:        while ((c = getc(sfi)) != EOF)
                     74:                putchar(c);
                     75: }

unix.superglobalmegacorp.com

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