if (connect(s, (struct sockaddr *)sinp, sizeof(*sinp)) < 0) err(EX_OSERR, "connect");
break;	 } if (s < 0) { if (reason) err(EX_OSERR, "%s", reason); else errx(EX_OSERR, "unknown error in connection attempt"); }
whois(name, sinp, flags)	char *name;	struct sockaddr_in *sinp;	int flags;{	FILE *sfi, *sfo;	char *buf, *p, *nhost;	size_t len;	int s, nomatch;	s = socket(PF_INET, SOCK_STREAM, 0);	if (s < 0)		err(EX_OSERR, "socket");	if (connect(s, (struct sockaddr *)sinp, sizeof(*sinp)) < 0)		err(EX_OSERR, "connect");	sfi = fdopen(s, "r");	sfo = fdopen(s, "w");	if (sfi == NULL || sfo == NULL)		err(EX_OSERR, "fdopen");	(void)fprintf(sfo, "%s\r\n", name);	(void)fflush(sfo);	nhost = NULL;	nomatch = 0;	while ((buf = fgetln(sfi, &len))) {		if (buf[len - 2] == '\r')			buf[len - 2] = '\0';		else			buf[len - 1] = '\0';		if ((flags & WHOIS_RECURSE) && !nhost &&		    (p = strstr(buf, "Whois Server: "))) {			p += sizeof("Whois Server: ") - 1;			if ((len = strcspn(p, " \t\n\r"))) {				if ((nhost = malloc(len + 1)) == NULL)					err(1, "malloc");				memcpy(nhost, p, len);				nhost[len] = '\0';			}		}		if ((flags & WHOIS_INIC_FALLBACK) && !nhost && !nomatch &&		    (p = strstr(buf, "No match for \""))) {			p += sizeof("No match for \"") - 1;			if ((len = strcspn(p, "\"")) && len == strlen(name) &&			    strncasecmp(name, p, len) == 0)				nomatch = 1;		}		(void)puts(buf);	}	/* Do second lookup as needed */	if (nomatch && !nhost) {		(void)printf("Looking up %s at %s.\n\n", name, INICHOST);		nhost = INICHOST;	}	if (nhost) {		if (inet_aton(nhost, &sinp->sin_addr) == 0) {			struct hostent *hp = gethostbyname2(nhost, AF_INET);			if (hp == NULL)				return;			sinp->sin_addr = *(struct in_addr *)hp->h_addr_list[0];		}		if (!nomatch)			free(nhost);		whois(name, sinp, 0);	}}