warn(cause);
warn("%s", cause);
hookup(host, port)	char *host;	char *port;{	int s, len, tos, error;	static char hostnamebuf[MAXHOSTNAMELEN];	struct addrinfo hints, *res, *res0;	char hbuf[MAXHOSTNAMELEN];	char *cause = "unknown";	epsv4bad = 0;	memset((char *)&hisctladdr, 0, sizeof (hisctladdr));	memset(&hints, 0, sizeof(hints));	hints.ai_flags = AI_CANONNAME;	hints.ai_family = AF_UNSPEC;	hints.ai_socktype = SOCK_STREAM;	hints.ai_protocol = 0;	error = getaddrinfo(host, port, &hints, &res0);	if (error == EAI_SERVICE) {		/*		 * If the services file is corrupt/missing, fall back		 * on our hard-coded defines.		 */		char pbuf[NI_MAXSERV];		pbuf[0] = '\0';		if (strcmp(port, "ftp") == 0)			snprintf(pbuf, sizeof(pbuf), "%d", FTP_PORT);		else if (strcmp(port, "ftpgate") == 0)			snprintf(pbuf, sizeof(pbuf), "%d", GATE_PORT);		else if (strcmp(port, "http") == 0)			snprintf(pbuf, sizeof(pbuf), "%d", HTTP_PORT);		if (pbuf[0])			error = getaddrinfo(host, pbuf, &hints, &res0);	}	if (error) {		warn(gai_strerror(error));		code = -1;		return (0);	}	if (res0->ai_canonname)		strncpy(hostnamebuf, res0->ai_canonname, sizeof(hostnamebuf));	else		strncpy(hostnamebuf, host, sizeof(hostnamebuf));	hostnamebuf[sizeof(hostnamebuf) - 1] = '\0';	hostname = hostnamebuf;		s = -1;	for (res = res0; res; res = res->ai_next) {#if 0	/*old behavior*/		if (res != res0)	/* not on the first address */#else		if (res0->ai_next)	/* if we have multiple possibilities */#endif		{			getnameinfo(res->ai_addr, res->ai_addrlen,				hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST);			fprintf(ttyout, "Trying %s...\n", hbuf);		}		s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);		if (s < 0) {			cause = "socket";			continue;		}		while ((error = connect(s, res->ai_addr, res->ai_addrlen)) < 0				&& errno == EINTR) {			;		}		if (error) {			/* this "if" clause is to prevent print warning twice */			if (res->ai_next) {				getnameinfo(res->ai_addr, res->ai_addrlen,					hbuf, sizeof(hbuf), NULL, 0,					NI_NUMERICHOST);				warn("connect to address %s", hbuf);			}			cause = "connect";			close(s);			s = -1;			continue;		}		/* finally we got one */		break;	}	if (s < 0) {		warn(cause);		code = -1;		freeaddrinfo(res0);		return 0;	}	memcpy(&hisctladdr, res->ai_addr, res->ai_addrlen);	len = res->ai_addrlen;	freeaddrinfo(res0);	res0 = res = NULL;	if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) {		warn("getsockname");		code = -1;		goto bad;	}#if defined(IPPROTO_IP) && defined(IP_TOS)	if (hisctladdr.su_family == AF_INET) {		tos = IPTOS_LOWDELAY;		if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)			warn("setsockopt TOS (ignored)");	}#endif	cin = fdopen(s, "r");	cout = fdopen(s, "w");	if (cin == NULL || cout == NULL) {		warnx("fdopen failed.");		if (cin)			(void)fclose(cin);		if (cout)			(void)fclose(cout);		code = -1;		goto bad;	}	if (verbose)		fprintf(ttyout, "Connected to %s.\n", hostname);	if (getreply(0) > 2) { 	/* read startup message from server */		if (cin)			(void)fclose(cin);		if (cout)			(void)fclose(cout);		code = -1;		goto bad;	}#ifdef SO_OOBINLINE	{	int on = 1;	if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on))		< 0 && debug) {			warn("setsockopt");		}	}#endif /* SO_OOBINLINE */	return (hostname);bad:	(void)close(s);	return ((char *)0);}