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

Defined functions

main defined in line 27; never used

Defined variables

copyright defined in line 8; never used
sccsid defined in line 14; never used

Defined macros

NICHOST defined in line 25; used 1 times
  • in line 34
Last modified: 1993-04-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2548
Valid CSS Valid XHTML 1.0 Strict