1999-12-03 11:22:09 +03:00
|
|
|
/* $NetBSD: whois.c,v 1.12 1999/12/03 08:22:09 fair Exp $ */
|
1994-11-14 08:13:14 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1999-05-19 02:36:36 +04:00
|
|
|
* RIPE version marten@ripe.net
|
|
|
|
* many changes & networkupdate by david@ripe.net
|
|
|
|
* cosmetics by steven@dante.org.uk -- gcc stopped complaining mostly,
|
|
|
|
* code is still messy, though.
|
|
|
|
*
|
|
|
|
* 1.15 94/09/07
|
|
|
|
*
|
|
|
|
* 1.2 9705/02
|
|
|
|
* "-v" option added; ambrose@ripe.net
|
|
|
|
* "whois.ripe.net" replaced by "bsdbase.ripe.net"; ambrose@ripe.net
|
|
|
|
* "bsdbase.ripe.net" replaced by "joshua.ripe.net"; marek@ripe.net
|
|
|
|
* "joshua.ripe.net" replaced by "whois.ripe.net"; roman@ripe.net 981105
|
|
|
|
*
|
|
|
|
* Copyright (c) 1980 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-19 18:46:16 +04:00
|
|
|
#include <sys/cdefs.h>
|
1999-05-19 02:36:36 +04:00
|
|
|
#if defined(sun) && defined(solaris)
|
|
|
|
#define SYSV
|
|
|
|
#endif
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-10-19 18:46:16 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1999-05-19 02:36:36 +04:00
|
|
|
#ifndef RIPE
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1994-11-14 08:13:14 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93";
|
1997-10-19 18:46:16 +04:00
|
|
|
#else
|
1999-12-03 11:22:09 +03:00
|
|
|
__RCSID("$NetBSD: whois.c,v 1.12 1999/12/03 08:22:09 fair Exp $");
|
1994-11-14 08:13:14 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif /* not RIPE */
|
|
|
|
|
|
|
|
#ifdef RIPE
|
|
|
|
#ifndef lint
|
|
|
|
char sccsid[] =
|
|
|
|
"@(#)whois.c 5.11 (Berkeley) 3/2/91 - RIPE 1.15 94/09/07 marten@ripe.net";
|
|
|
|
#endif /* not lint */
|
|
|
|
#endif /* RIPE */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
1999-05-19 02:36:36 +04:00
|
|
|
#include <sys/param.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <netinet/in.h>
|
1997-10-20 07:23:37 +04:00
|
|
|
#include <err.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <stdio.h>
|
1993-08-28 02:30:10 +04:00
|
|
|
#include <stdlib.h>
|
1999-05-19 02:36:36 +04:00
|
|
|
#include <ctype.h>
|
1993-08-28 02:30:10 +04:00
|
|
|
#include <string.h>
|
1999-05-19 02:36:36 +04:00
|
|
|
#include <errno.h>
|
1993-08-28 02:30:10 +04:00
|
|
|
#include <unistd.h>
|
1999-05-19 02:36:36 +04:00
|
|
|
#include <pwd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#if defined(SYSV)
|
|
|
|
#include <crypt.h>
|
|
|
|
#endif /* SYSV */
|
|
|
|
|
|
|
|
#ifndef __NetBSD__
|
|
|
|
#ifdef __STDC__
|
|
|
|
extern int getopt(int argc, char * const *argv, const char *optstring);
|
|
|
|
extern int kill(pid_t pid, int sig);
|
|
|
|
extern FILE *fdopen(int fildes, const char *type);
|
|
|
|
extern int gethostname(char *name, int namelen);
|
|
|
|
#else /* !__STDC__ */
|
|
|
|
extern int gethostname();
|
|
|
|
#endif /* __STDC__ */
|
|
|
|
#endif /* __NetBSD__ */
|
|
|
|
|
|
|
|
#if defined(SYSV) || defined(__STDC__)
|
|
|
|
|
|
|
|
#define index(s,c) strchr((const char*)(s),(int)(c))
|
|
|
|
#define rindex(s,c) strrchr((const char*)(s),(int)(c))
|
|
|
|
#define bzero(s,n) memset((void*)s,0,(size_t)n)
|
|
|
|
|
|
|
|
#ifdef HASMEMMOVE
|
|
|
|
# define bcopy(s,d,n) memmove((void*)(d),(void*)(s),(size_t)(n))
|
|
|
|
#else
|
|
|
|
# define bcopy(s,d,n) memcpy((void*)(d),(void*)(s),(size_t)(n))
|
|
|
|
#endif /* HASMEMMOVE */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif /* SYSV || __STDC__ */
|
|
|
|
|
|
|
|
#ifdef GLIBC
|
|
|
|
typedef __u_short u_short;
|
|
|
|
typedef __caddr_t caddr_t;
|
|
|
|
#endif /* GLIBC */
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
# the following defines can be used but are not fully functional anymore...
|
|
|
|
#
|
|
|
|
# CLEVER- Use a educated guess of the whereabouts of the nearest server
|
|
|
|
# This is done by taking the top-level domain of the current
|
|
|
|
# machine, and looking for a CNAME record for a server with name
|
|
|
|
# <top-level-domain>-whois.ripe.net
|
|
|
|
# If this machine does not exsist or the current machine's top-level
|
|
|
|
# domain could not be found,it will fall back to whois.ripe.net
|
|
|
|
# the default for this RIPE version of whois
|
|
|
|
# The CLEVER option implies the RIPE option.
|
|
|
|
|
|
|
|
# TOPDOMAIN=\"<top-level-domain>\"
|
|
|
|
# - This option will fix the default host to be
|
|
|
|
# <top-level-domain>-whois.ripe.net, which may point to a secondary
|
|
|
|
# server inside your top-level domain. If there is no such secondary
|
|
|
|
# server, it will point to whois.ripe.net, the default. This option
|
|
|
|
# overrules the CLEVER option.
|
|
|
|
# The TOPDOMAIN option implies the RIPE option.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(TOPDOMAIN) || defined(CLEVER)
|
|
|
|
#ifndef RIPE
|
|
|
|
#define RIPE
|
|
|
|
#endif /* !RIPE */
|
|
|
|
#endif /* TOPDOMAIN || CLEVER */
|
|
|
|
|
|
|
|
#if defined(RIPE) && !defined(__NetBSD__)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#define NICHOST "whois.ripe.net"
|
|
|
|
#else
|
1999-12-03 11:22:09 +03:00
|
|
|
#define NICHOST "whois.networksolutions.com"
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-19 18:46:16 +04:00
|
|
|
int main __P((int, char **));
|
|
|
|
static void usage __P((void));
|
1999-05-19 02:36:36 +04:00
|
|
|
static void closesocket __P((int, int));
|
|
|
|
static void termhandler __P((int));
|
1993-08-28 02:30:10 +04:00
|
|
|
|
1999-05-19 02:36:36 +04:00
|
|
|
void usage()
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1999-05-19 02:36:36 +04:00
|
|
|
#ifdef RIPE
|
|
|
|
#ifdef NETWORKUPDATE
|
1999-09-03 17:51:28 +04:00
|
|
|
(void)fprintf(stderr, "\nUsage: networkupdate [-46] [-h hostname] [-p port]");
|
1999-05-19 02:36:36 +04:00
|
|
|
#else
|
1999-09-03 17:51:28 +04:00
|
|
|
(void)fprintf(stderr, "\nUsage: whois [-46aFLmMrSvR] [-h hostname] [-s sources] [-T types] [-i attr] keys\n");
|
1999-05-19 02:36:36 +04:00
|
|
|
(void)fprintf(stderr, " whois -t type");
|
|
|
|
(void)fprintf(stderr, " whois -v type");
|
|
|
|
#endif
|
|
|
|
#else
|
1999-09-03 17:51:28 +04:00
|
|
|
(void)fprintf(stderr, "\nUsage: whois [-46] [-h hostname] [-p port] name ...");
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif
|
|
|
|
(void)fprintf(stderr, "\n\nWhere:\n\n");
|
1999-09-03 17:51:28 +04:00
|
|
|
(void)fprintf(stderr, "-4 Use IPv4 Only\n");
|
|
|
|
(void)fprintf(stderr, "-6 Use IPv6 Only\n");
|
1999-05-19 02:36:36 +04:00
|
|
|
#ifdef RIPE
|
|
|
|
#ifndef NETWORKUPDATE
|
|
|
|
(void)fprintf(stderr, "-a search all databases\n");
|
|
|
|
(void)fprintf(stderr, "-F fast raw output\n");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
(void)fprintf(stderr, "-h hostname search alternate server\n");
|
|
|
|
#ifdef RIPE
|
|
|
|
#ifndef NETWORKUPDATE
|
|
|
|
(void)fprintf(stderr, "-i [attr][[,attr] ... ] do an inverse lookup for specified attributes\n");
|
|
|
|
(void)fprintf(stderr, "-L find all Less specific matches\n");
|
|
|
|
(void)fprintf(stderr, "-m find first level more specific matches\n");
|
|
|
|
(void)fprintf(stderr, "-M find all More specific matches\n");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
(void)fprintf(stderr, "-p port port to connect to\n");
|
|
|
|
#ifdef RIPE
|
|
|
|
#ifndef NETWORKUPDATE
|
|
|
|
(void)fprintf(stderr, "-r turn off recursive lookups\n");
|
|
|
|
(void)fprintf(stderr, "-s source[[,source] ... ] search databases with source 'source'\n");
|
|
|
|
(void)fprintf(stderr, "-S tell server to leave out 'syntactic sugar'\n");
|
|
|
|
(void)fprintf(stderr, "-t type requests template for object of type 'type'\n");
|
|
|
|
(void)fprintf(stderr, "-v type requests verbose template for object of type 'type'\n");
|
|
|
|
(void)fprintf(stderr, "-R force to show local copy of the domain object even if it contains referral\n");
|
|
|
|
(void)fprintf(stderr, "-T type[[,type] ... ] only look for objects of type 'type'\n\n");
|
|
|
|
(void)fprintf(stderr, "Please note that most of these flags are NOT understood by\n");
|
|
|
|
(void)fprintf(stderr, "non RIPE whois servers\n");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
(void)fprintf(stderr, "\n");
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int s;
|
|
|
|
|
|
|
|
void closesocket(s, child)
|
|
|
|
int s, child;
|
|
|
|
{
|
|
|
|
/* printf("close connection child=%i\n", child); */
|
|
|
|
|
|
|
|
close(s);
|
|
|
|
|
|
|
|
#ifdef NETWORKUPDATE
|
|
|
|
if (child==0) {
|
|
|
|
kill(getppid(), SIGTERM);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void termhandler(sig)
|
|
|
|
int sig;
|
|
|
|
{
|
|
|
|
closesocket(s,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef RIPE
|
|
|
|
#if defined(__STDC__) || defined(SYSV)
|
|
|
|
#define occurs(str,pat) ((int) strstr((str),(pat)))
|
|
|
|
#else /* !__STDC__ && !SYSV */
|
|
|
|
int occurs(str, pat)
|
|
|
|
char *str, *pat;
|
|
|
|
{
|
|
|
|
register char *point = str;
|
|
|
|
|
|
|
|
while ((point=index(point, *pat)))
|
|
|
|
{
|
|
|
|
if (strncmp(point, pat, strlen(pat)) == 0)
|
|
|
|
return(1);
|
|
|
|
point++;
|
|
|
|
}
|
|
|
|
return(0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-05-19 02:36:36 +04:00
|
|
|
int main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1999-05-19 02:36:36 +04:00
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
FILE *sfi;
|
|
|
|
FILE *sfo;
|
|
|
|
int ch;
|
1999-09-03 17:51:28 +04:00
|
|
|
struct addrinfo *dst, hints;
|
1999-09-06 10:23:08 +04:00
|
|
|
int af=PF_UNSPEC;
|
1999-09-03 17:51:28 +04:00
|
|
|
int error;
|
1999-05-19 02:36:36 +04:00
|
|
|
char *host, *whoishost;
|
1999-09-03 17:51:28 +04:00
|
|
|
int optp=0;
|
|
|
|
char *optport="whois";
|
|
|
|
#ifdef DEBUG
|
|
|
|
int verb=1;
|
|
|
|
#else /*DEBUG */
|
|
|
|
int verb=0;
|
|
|
|
#endif
|
1999-05-19 02:36:36 +04:00
|
|
|
#ifdef RIPE
|
1999-09-03 17:51:28 +04:00
|
|
|
int opthost=0;
|
1999-05-19 02:36:36 +04:00
|
|
|
#ifndef NETWORKUPDATE
|
|
|
|
/* normal whois client */
|
|
|
|
char *string;
|
|
|
|
int alldatabases=0;
|
|
|
|
int optsource=0, optrecur=0, optfast=0, opttempl=0, optverbose=0;
|
|
|
|
int optobjtype=0, optsugar=0, optinverselookup=0, optgetupdates=0;
|
|
|
|
int optL=0, optm=0, optM=0, optchanged=0, optnonreferral=0;
|
|
|
|
char *source=NULL, *templ=NULL, *verbose=NULL, *objtype=NULL,
|
|
|
|
*inverselookup=NULL, *getupdates=NULL;
|
|
|
|
#else /* NETWORKUPDATE */
|
|
|
|
/* networkupdate client */
|
|
|
|
int prev;
|
|
|
|
char domainname[64]; /* that's what sys/param.h says */
|
|
|
|
struct passwd *passwdentry;
|
|
|
|
int child;
|
|
|
|
#endif
|
|
|
|
#ifdef CLEVER
|
|
|
|
int myerror;
|
|
|
|
char *mytoplevel;
|
|
|
|
char *myhost;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TOPDOMAIN
|
|
|
|
host = strcat(TOPDOMAIN, "-whois.ripe.net");
|
|
|
|
#else
|
|
|
|
host = NICHOST;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RIPE
|
|
|
|
#ifdef NETWORKUPDATE
|
1999-09-03 17:51:28 +04:00
|
|
|
while ((ch = getopt(argc, argv, "46h:p:")) != EOF)
|
1999-05-19 02:36:36 +04:00
|
|
|
#else
|
1999-09-03 17:51:28 +04:00
|
|
|
while ((ch = getopt(argc, argv, "46acFg:h:i:LmMp:rs:SRt:T:v:")) != EOF)
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif
|
|
|
|
#else
|
1999-09-03 17:51:28 +04:00
|
|
|
while ((ch = getopt(argc, argv, "46h:p:")) != EOF)
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif
|
|
|
|
switch((char)ch) {
|
1999-09-03 17:51:28 +04:00
|
|
|
case '4':
|
1999-09-06 10:23:08 +04:00
|
|
|
af = PF_INET;
|
1999-09-03 17:51:28 +04:00
|
|
|
break;
|
|
|
|
case '6':
|
1999-09-06 10:23:08 +04:00
|
|
|
af = PF_INET6;
|
1999-09-03 17:51:28 +04:00
|
|
|
break;
|
1999-05-19 02:36:36 +04:00
|
|
|
case 'h':
|
|
|
|
host = optarg;
|
|
|
|
opthost = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
1999-09-03 17:51:28 +04:00
|
|
|
optport=optarg;
|
1999-05-19 02:36:36 +04:00
|
|
|
optp =1;
|
|
|
|
break;
|
|
|
|
#ifdef RIPE
|
|
|
|
#ifndef NETWORKUPDATE
|
|
|
|
case 'a':
|
|
|
|
alldatabases=1;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
optchanged=1;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
optfast = 1;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
getupdates=optarg;
|
|
|
|
optgetupdates=1;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
inverselookup=optarg;
|
|
|
|
optinverselookup = 1;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
if (optM || optm) {
|
|
|
|
fprintf(stderr, "Only one of -L, -m or -M allowed\n\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
optL=1;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if (optM || optL) {
|
|
|
|
fprintf(stderr, "Only one of -L, -m or -M allowed\n\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
optm=1;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
if (optL || optm) {
|
|
|
|
fprintf(stderr, "Only one of -L, -m or -M allowed\n\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
optM=1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
source = optarg;
|
|
|
|
optsource=1;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
optsugar=1;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
optnonreferral=1;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
optrecur=1;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
templ=optarg;
|
|
|
|
opttempl=1;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose=optarg;
|
|
|
|
optverbose=1;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
objtype=optarg;
|
|
|
|
optobjtype=1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
#ifdef RIPE
|
|
|
|
#ifdef NETWORKUPDATE
|
|
|
|
if (argc>0)
|
|
|
|
usage();
|
|
|
|
#else
|
|
|
|
if ((argc<=0) && !opttempl && !optverbose && !optgetupdates && (!(opttempl && optgetupdates)))
|
|
|
|
usage();
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
if (argc<=0)
|
|
|
|
usage();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!opthost) {
|
|
|
|
|
|
|
|
#ifdef CLEVER
|
|
|
|
whoishost=(char *)calloc(MAXHOSTNAMELEN, sizeof(char));
|
|
|
|
myhost =(char *)calloc(MAXHOSTNAMELEN, sizeof(char));
|
|
|
|
myerror = gethostname(myhost, MAXHOSTNAMELEN);
|
|
|
|
if (myerror >= 0) {
|
|
|
|
if (occurs(myhost, ".")) {
|
|
|
|
mytoplevel = rindex(myhost,'.');
|
|
|
|
mytoplevel++;
|
|
|
|
(void) sprintf(whoishost, "%s-whois.ripe.net", mytoplevel);
|
|
|
|
if (verb) fprintf(stderr, "Clever guess: %s\n", whoishost);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-03 17:51:28 +04:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_flags = AI_CANONNAME;
|
1999-09-06 10:23:08 +04:00
|
|
|
hints.ai_family = af;
|
1999-09-03 17:51:28 +04:00
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
error = getaddrinfo(host, optport, &hints, &dst);
|
|
|
|
if ((error) && (verb))
|
|
|
|
fprintf(stderr,"No such host: %s\n", whoishost);
|
|
|
|
if (error) {
|
1999-05-19 02:36:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
whoishost=NICHOST;
|
|
|
|
|
1999-09-06 10:23:08 +04:00
|
|
|
if (verb)
|
|
|
|
fprintf(stderr, "Default host: %s\n\n", whoishost);
|
1999-09-03 17:51:28 +04:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_flags = AI_CANONNAME;
|
1999-09-06 10:23:08 +04:00
|
|
|
hints.ai_family = af;
|
1999-09-03 17:51:28 +04:00
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
error = getaddrinfo(host, optport , &hints, &dst);
|
|
|
|
if (error) {
|
1999-05-19 02:36:36 +04:00
|
|
|
fprintf(stderr,"No such host: %s\n", whoishost);
|
|
|
|
if (verb) fprintf(stderr, "Now I give up ...\n");
|
|
|
|
perror("Unknown host");
|
1999-09-03 17:51:28 +04:00
|
|
|
exit(1);
|
1999-05-19 02:36:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CLEVER
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
1999-09-06 10:23:08 +04:00
|
|
|
if (verb)
|
|
|
|
fprintf(stderr, "Trying: %s\n\n", host);
|
1999-09-03 17:51:28 +04:00
|
|
|
memset(&hints, 0, sizeof(hints));
|
|
|
|
hints.ai_flags = AI_CANONNAME;
|
1999-09-06 10:23:08 +04:00
|
|
|
hints.ai_family = af;
|
1999-09-03 17:51:28 +04:00
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
error = getaddrinfo(host, optport, &hints, &dst);
|
|
|
|
if (error) {
|
1999-05-19 02:36:36 +04:00
|
|
|
(void)fprintf(stderr, "whois: %s: ", host);
|
|
|
|
perror("Unknown host");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-06 10:23:08 +04:00
|
|
|
for (/*nothing*/; dst; dst = dst->ai_next) {
|
1999-09-03 17:51:28 +04:00
|
|
|
s = socket(dst->ai_family, dst->ai_socktype, dst->ai_protocol);
|
1999-09-06 10:23:08 +04:00
|
|
|
if (s < 0)
|
|
|
|
continue;
|
1999-09-03 17:51:28 +04:00
|
|
|
if (connect(s, dst->ai_addr, dst->ai_addrlen) < 0) {
|
1999-09-06 10:23:08 +04:00
|
|
|
close(s);
|
1999-09-03 17:51:28 +04:00
|
|
|
if (verb) (void)fprintf(stderr, "whois: connect miss\n");
|
|
|
|
continue;
|
|
|
|
}
|
1999-09-06 10:23:08 +04:00
|
|
|
/*okay*/
|
1999-09-03 17:51:28 +04:00
|
|
|
break;
|
1999-05-19 02:36:36 +04:00
|
|
|
}
|
1999-09-06 10:23:08 +04:00
|
|
|
if (dst == NULL) {
|
|
|
|
perror("whois: connect");
|
|
|
|
exit(1);
|
|
|
|
}
|
1999-09-03 17:51:28 +04:00
|
|
|
if (verb) (void)fprintf(stderr, "whois: connect success\n");
|
1999-05-19 02:36:36 +04:00
|
|
|
|
|
|
|
#ifndef NETWORKUPDATE
|
|
|
|
sfi = fdopen(s, "r");
|
|
|
|
sfo = fdopen(s, "w");
|
|
|
|
if (sfi == NULL || sfo == NULL) {
|
|
|
|
perror("whois: fdopen");
|
|
|
|
(void)close(s);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
signal(SIGTERM, termhandler);
|
|
|
|
|
|
|
|
#ifdef RIPE
|
|
|
|
#ifdef NETWORKUPDATE
|
|
|
|
|
|
|
|
if ((child=fork())==0) {
|
|
|
|
|
|
|
|
sfo = fdopen(s, "w");
|
|
|
|
if (sfo == NULL) {
|
|
|
|
perror("whois: fdopen");
|
|
|
|
(void)close(s);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gethostname(domainname, sizeof(domainname))) {
|
|
|
|
fprintf(stderr, "error when doing gethostname()");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
passwdentry=getpwuid(getuid());
|
|
|
|
|
|
|
|
fprintf(sfo, "-Vnc2.0 -U %s %s\n", passwdentry->pw_name, domainname);
|
|
|
|
fflush(sfo);
|
|
|
|
|
|
|
|
prev='\0';
|
|
|
|
|
|
|
|
while ((ch=getchar()) != EOF) {
|
|
|
|
|
|
|
|
fputc(ch, sfo);
|
|
|
|
|
|
|
|
if (ch=='\n') fflush(sfo);
|
|
|
|
if (feof(sfo)) closesocket(s, child);
|
|
|
|
if ((ch=='.') && (prev=='\n')) closesocket(s, child);
|
|
|
|
if (!isspace(ch) || ((!isspace(prev)) && (ch=='\n'))) prev=ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
closesocket(s, child);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sfi = fdopen(s, "r");
|
|
|
|
if (sfi == NULL) {
|
|
|
|
perror("whois: fdopen");
|
|
|
|
(void)close(s);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
if (alldatabases)
|
|
|
|
(void)fprintf(sfo, "-a ");
|
|
|
|
if (optchanged)
|
|
|
|
(void)fprintf(sfo, "-c ");
|
|
|
|
if (optfast)
|
|
|
|
(void)fprintf(sfo, "-F ");
|
|
|
|
if (optgetupdates)
|
|
|
|
(void)fprintf(sfo, "-g %s ", getupdates);
|
|
|
|
if (optinverselookup)
|
|
|
|
(void)fprintf(sfo, "-i %s ", inverselookup);
|
|
|
|
if (optL)
|
|
|
|
(void)fprintf(sfo, "-L ");
|
|
|
|
if (optm)
|
|
|
|
(void)fprintf(sfo, "-m ");
|
|
|
|
if (optM)
|
|
|
|
(void)fprintf(sfo, "-M ");
|
|
|
|
if (optrecur)
|
|
|
|
(void)fprintf(sfo, "-r ");
|
|
|
|
if (optsource)
|
|
|
|
(void)fprintf(sfo, "-s %s ", source);
|
|
|
|
if (optsugar)
|
|
|
|
(void)fprintf(sfo, "-S ");
|
|
|
|
if (optnonreferral)
|
|
|
|
(void)fprintf(sfo, "-R ");
|
|
|
|
if (opttempl)
|
|
|
|
(void)fprintf(sfo, "-t %s ", templ);
|
|
|
|
if (optverbose)
|
|
|
|
(void)fprintf(sfo, "-v %s ", verbose);
|
|
|
|
if (optobjtype)
|
|
|
|
(void)fprintf(sfo, "-T %s ", objtype);
|
|
|
|
|
|
|
|
/* we can only send the -V when we are sure that we are dealing with
|
|
|
|
a RIPE whois server :-( */
|
|
|
|
|
|
|
|
whoishost=(char *)calloc(strlen(host)+1, sizeof(char));
|
|
|
|
strcpy(whoishost, host);
|
|
|
|
for (string=whoishost;(*string=(char)tolower(*string));string++);
|
|
|
|
|
|
|
|
if (strstr(whoishost, "ripe.net") ||
|
|
|
|
strstr(whoishost, "ra.net") ||
|
|
|
|
strstr(whoishost, "apnic.net") ||
|
|
|
|
strstr(whoishost, "mci.net") ||
|
|
|
|
strstr(whoishost, "isi.edu") ||
|
|
|
|
strstr(whoishost, "garr.it") ||
|
|
|
|
strstr(whoishost, "ans.net") ||
|
|
|
|
alldatabases || optfast || optgetupdates || optinverselookup ||
|
|
|
|
optL || optm || optM || optrecur || optsugar || optsource ||
|
|
|
|
opttempl || optverbose || optobjtype)
|
|
|
|
(void)fprintf(sfo, "-VwC2.0 ");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NETWORKUPDATE
|
|
|
|
while (argc-- > 1)
|
|
|
|
(void)fprintf(sfo, "%s ", *argv++);
|
|
|
|
if (*argv) (void)fputs(*argv, sfo);
|
|
|
|
(void)fputs("\r\n", sfo);
|
|
|
|
(void)fflush(sfo);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while ((ch = getc(sfi)) != EOF)
|
|
|
|
putchar(ch);
|
|
|
|
|
|
|
|
closesocket(s, 1);
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|