=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/whois/whois.c,v retrieving revision 1.3 retrieving revision 1.4 diff -c -r1.3 -r1.4 *** src/usr.bin/whois/whois.c 1997/01/15 23:43:39 1.3 --- src/usr.bin/whois/whois.c 1998/02/24 10:09:50 1.4 *************** *** 1,4 **** ! /* $OpenBSD: whois.c,v 1.3 1997/01/15 23:43:39 millert Exp $ */ /* $NetBSD: whois.c,v 1.5 1994/11/14 05:13:25 jtc Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: whois.c,v 1.4 1998/02/24 10:09:50 deraadt Exp $ */ /* $NetBSD: whois.c,v 1.5 1994/11/14 05:13:25 jtc Exp $ */ /* *************** *** 44,50 **** #if 0 static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93"; #endif ! static char rcsid[] = "$OpenBSD: whois.c,v 1.3 1997/01/15 23:43:39 millert Exp $"; #endif /* not lint */ #include --- 44,50 ---- #if 0 static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93"; #endif ! static char rcsid[] = "$OpenBSD: whois.c,v 1.4 1998/02/24 10:09:50 deraadt Exp $"; #endif /* not lint */ #include *************** *** 54,62 **** #include #include #include #include ! #define NICHOST "whois.internic.net" static void usage(); --- 54,68 ---- #include #include #include + #include #include ! #define NICHOST "whois.internic.net" ! #define DNICHOST "nic.ddn.mil" ! #define ANICHOST "whois.arin.net" ! #define RNICHOST "whois.ripe.net" ! #define PNICHOST "whois.apnic.net" ! #define WHOIS_PORT 43 static void usage(); *************** *** 76,86 **** char *host; host = NICHOST; ! while ((ch = getopt(argc, argv, "h:")) != -1) switch((char)ch) { case 'h': host = optarg; break; case '?': default: usage(); --- 82,104 ---- char *host; host = NICHOST; ! while ((ch = getopt(argc, argv, "adh:pr")) != -1) switch((char)ch) { + case 'a': + host = ANICHOST; + break; + case 'd': + host = DNICHOST; + break; case 'h': host = optarg; break; + case 'p': + host = PNICHOST; + break; + case 'r': + host = RNICHOST; + break; case '?': default: usage(); *************** *** 91,132 **** if (!argc) usage(); ! hp = gethostbyname(host); ! if (hp == NULL) { ! (void)fprintf(stderr, "whois: %s: ", host); ! herror((char *)NULL); ! exit(1); } ! host = hp->h_name; ! s = socket(hp->h_addrtype, SOCK_STREAM, 0); ! if (s < 0) { ! perror("whois: socket"); ! exit(1); ! } ! bzero((caddr_t)&sin, sizeof (sin)); ! sin.sin_family = hp->h_addrtype; ! if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { ! perror("whois: bind"); ! exit(1); ! } ! bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length); sp = getservbyname("whois", "tcp"); ! if (sp == NULL) { ! (void)fprintf(stderr, "whois: whois/tcp: unknown service\n"); ! exit(1); ! } ! sin.sin_port = sp->s_port; ! if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { ! perror("whois: connect"); ! exit(1); ! } sfi = fdopen(s, "r"); sfo = fdopen(s, "w"); ! if (sfi == NULL || sfo == NULL) { ! perror("whois: fdopen"); ! (void)close(s); ! exit(1); ! } while (argc-- > 1) (void)fprintf(sfo, "%s ", *argv++); (void)fprintf(sfo, "%s\r\n", *argv); --- 109,143 ---- if (!argc) usage(); ! s = socket(PF_INET, SOCK_STREAM, 0); ! if (s < 0) ! err(EX_OSERR, "socket"); ! ! memset(&sin, 0, sizeof sin); ! sin.sin_len = sizeof sin; ! sin.sin_family = AF_INET; ! ! if (inet_aton(host, &sin.sin_addr) == 0) { ! hp = gethostbyname2(host, AF_INET); ! if (hp == NULL) ! errx(EX_NOHOST, "%s: %s", host, hstrerror(h_errno)); ! host = hp->h_name; ! sin.sin_addr = *(struct in_addr *)hp->h_addr_list[0]; } ! sp = getservbyname("whois", "tcp"); ! if (sp == NULL) ! sin.sin_port = htons(WHOIS_PORT); ! else ! sin.sin_port = sp->s_port; ! ! if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) ! err(EX_OSERR, "connect"); ! sfi = fdopen(s, "r"); sfo = fdopen(s, "w"); ! if (sfi == NULL || sfo == NULL) ! err(EX_OSERR, "fdopen"); while (argc-- > 1) (void)fprintf(sfo, "%s ", *argv++); (void)fprintf(sfo, "%s\r\n", *argv); *************** *** 139,144 **** static void usage() { ! (void)fprintf(stderr, "usage: whois [-h hostname] name ...\n"); ! exit(1); } --- 150,155 ---- static void usage() { ! (void)fprintf(stderr, "usage: whois [-adpr] [-h hostname] name ...\n"); ! exit(EX_USAGE); }