&hp, &herr) < 0)
&hp, &herr) != 0)
rcmd(ahost, rport, locuser, remuser, cmd, fd2p)	char **ahost;	u_short rport;	const char *locuser, *remuser, *cmd;	int *fd2p;{	struct hostent hostbuf, *hp;	size_t hstbuflen;	char *tmphstbuf;	struct sockaddr_in sin, from;	struct pollfd pfd[2];	int32_t oldmask;	pid_t pid;	int s, lport, timo;	char c;	int herr;	pid = __getpid();	hstbuflen = 1024;	tmphstbuf = __alloca (hstbuflen);	while (__gethostbyname_r (*ahost, &hostbuf, tmphstbuf, hstbuflen,				  &hp, &herr) < 0)	  if (herr != NETDB_INTERNAL || errno != ERANGE)	    {	      __set_h_errno (herr);	      herror(*ahost);	      return -1;	    }	  else	    {	      /* Enlarge the buffer.  */	      hstbuflen *= 2;	      tmphstbuf = __alloca (hstbuflen);	    }	pfd[0].events = POLLIN;	pfd[1].events = POLLIN;	*ahost = hp->h_name;	oldmask = __sigblock(sigmask(SIGURG));	for (timo = 1, lport = IPPORT_RESERVED - 1;;) {		s = rresvport(&lport);		if (s < 0) {			if (errno == EAGAIN)				(void)fprintf(stderr,				    _("rcmd: socket: All ports in use\n"));			else				(void)fprintf(stderr, "rcmd: socket: %m\n");			__sigsetmask(oldmask);			return -1;		}		__fcntl(s, F_SETOWN, pid);		sin.sin_family = hp->h_addrtype;		bcopy(hp->h_addr_list[0], &sin.sin_addr,		      MIN (sizeof (sin.sin_addr), hp->h_length));		sin.sin_port = rport;		if (__connect(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0)			break;		(void)__close(s);		if (errno == EADDRINUSE) {			lport--;			continue;		}		if (errno == ECONNREFUSED && timo <= 16) {			(void)__sleep(timo);			timo *= 2;			continue;		}		if (hp->h_addr_list[1] != NULL) {			int oerrno = errno;			(void)fprintf(stderr, _("connect to address %s: "),			    inet_ntoa(sin.sin_addr));			__set_errno (oerrno);			perror(0);			hp->h_addr_list++;			bcopy(hp->h_addr_list[0], &sin.sin_addr,			      MIN (sizeof (sin.sin_addr), hp->h_length));			(void)fprintf(stderr, _("Trying %s...\n"),			    inet_ntoa(sin.sin_addr));			continue;		}		(void)fprintf(stderr, "%s: %m\n", hp->h_name);		__sigsetmask(oldmask);		return -1;	}	lport--;	if (fd2p == 0) {		__write(s, "", 1);		lport = 0;	} else {		char num[8];		int s2 = rresvport(&lport), s3;		size_t len = sizeof(from);		if (s2 < 0)			goto bad;		listen(s2, 1);		(void)__snprintf(num, sizeof(num), "%d", lport);		if (__write(s, num, strlen(num)+1) != strlen(num)+1) {			(void)fprintf(stderr,			    _("rcmd: write (setting up stderr): %m\n"));			(void)__close(s2);			goto bad;		}		pfd[0].fd = s;		pfd[1].fd = s2;		__set_errno (0);		if (__poll (pfd, 2, -1) < 1 || (pfd[1].revents & POLLIN) == 0){			if (errno != 0)				(void)fprintf(stderr,				  _("rcmd: poll (setting up stderr): %m\n"));			else				(void)fprintf(stderr,			     _("poll: protocol failure in circuit setup\n"));			(void)__close(s2);			goto bad;		}		s3 = accept(s2, (struct sockaddr *)&from, &len);		(void)__close(s2);		if (s3 < 0) {			(void)fprintf(stderr,			    "rcmd: accept: %m\n");			lport = 0;			goto bad;		}		*fd2p = s3;		from.sin_port = ntohs((u_short)from.sin_port);		if (from.sin_family != AF_INET ||		    from.sin_port >= IPPORT_RESERVED ||		    from.sin_port < IPPORT_RESERVED / 2) {			(void)fprintf(stderr,			    _("socket: protocol failure in circuit setup\n"));			goto bad2;		}	}	(void)__write(s, locuser, strlen(locuser)+1);	(void)__write(s, remuser, strlen(remuser)+1);	(void)__write(s, cmd, strlen(cmd)+1);	if (__read(s, &c, 1) != 1) {		(void)fprintf(stderr,		    "rcmd: %s: %m\n", *ahost);		goto bad2;	}	if (c != 0) {		while (__read(s, &c, 1) == 1) {			(void)__write(STDERR_FILENO, &c, 1);			if (c == '\n')				break;		}		goto bad2;	}	__sigsetmask(oldmask);	return s;bad2:	if (lport)		(void)__close(*fd2p);bad:	(void)__close(s);	__sigsetmask(oldmask);	return -1;}