int ch, i, j;
int ch, i, j, error;
main(argc, argv)	int argc;	char **argv;{	int ch, i, j;	int use_qnichost, flags;	char *host;	char *qnichost;	struct servent *sp;	struct hostent *hp;	struct sockaddr_in sin;#ifdef SOCKS	SOCKSinit(argv[0]);#endif	host = NULL;	qnichost = NULL;	flags = 0;	use_qnichost = 0;	while ((ch = getopt(argc, argv, "adgh:impqQrR")) != -1)		switch((char)ch) {		case 'a':			host = ANICHOST;			break;		case 'd':			host = DNICHOST;			break;		case 'g':			host = GNICHOST;			break;		case 'h':			host = optarg;			break;		case 'i':			host = INICHOST;			break;		case 'm':			host = MNICHOST;			break;		case 'p':			host = PNICHOST;			break;		case 'q':			/* default */			break;		case 'Q':			flags |= WHOIS_QUICK;			break;		case 'r':			host = RNICHOST;			break;		case 'R':			host = RUNICHOST;			break;		case '?':		default:			usage();		}	argc -= optind;	argv += optind;	if (!argc)		usage();	memset(&sin, 0, sizeof sin);	sin.sin_len = sizeof(sin);	sin.sin_family = AF_INET;	sp = getservbyname("whois", "tcp");	if (sp == NULL)		sin.sin_port = htons(WHOIS_PORT);	else		sin.sin_port = sp->s_port;	/*	 * If no nic host is specified, use whois-servers.net	 * if there is a '.' in the name, else fall back to NICHOST.	 */	if (host == NULL) {		use_qnichost = 1;		host = NICHOST;		if (!(flags & WHOIS_QUICK))			flags |= WHOIS_INIC_FALLBACK | WHOIS_RECURSE;	}	while (argc--) {		if (use_qnichost) {			if (qnichost) {				free(qnichost);				qnichost = NULL;			}			for (i = j = 0; (*argv)[i]; i++)				if ((*argv)[i] == '.')					j = i;			if (j != 0) {				qnichost = (char *) calloc(i - j + 1 +				    strlen(QNICHOST_TAIL), sizeof(char));				if (!qnichost)					err(1, "malloc");				strcpy(qnichost, *argv + j + 1);				strcat(qnichost, QNICHOST_TAIL);				if (inet_aton(qnichost, &sin.sin_addr) == 0) {					hp = gethostbyname2(qnichost, AF_INET);					if (hp == NULL) {						free(qnichost);						qnichost = NULL;					} else {						sin.sin_addr = *(struct in_addr *)hp->h_addr_list[0];					}				}			}		}		if (!qnichost && 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];		}		whois(*argv++, &sin, flags);	}	exit(0);}