if (_IO_fwide (stderr, 0) > 0) (void)__fwprintf(stderr, L"%s: %s\n", *ahost, __strerror_r(errno, errbuf, sizeof (errbuf))); else (void)fprintf(stderr, "%s: %s\n", *ahost, __strerror_r(errno, errbuf, sizeof (errbuf)));
(void)__fxprintf(NULL, "%s: %s\n", L"%s: %s\n", *ahost, __strerror_r(errno, errbuf, sizeof (errbuf)));
libc_hidden_proto (iruserok_af)libc_freeres_ptr(static char *ahostbuf);intrcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)	char **ahost;	u_short rport;	const char *locuser, *remuser, *cmd;	int *fd2p;	sa_family_t af;{	char paddr[INET6_ADDRSTRLEN];	struct addrinfo hints, *res, *ai;	struct sockaddr_storage from;	struct pollfd pfd[2];	int32_t oldmask;	pid_t pid;	int s, lport, timo, error;	char c;	int refused;	char num[8];	ssize_t n;	if (af != AF_INET && af != AF_INET6 && af != AF_UNSPEC)	  {	    __set_errno (EAFNOSUPPORT);	    return -1;	  }	pid = __getpid();	memset(&hints, '\0', sizeof(hints));	hints.ai_flags = AI_CANONNAME;	hints.ai_family = af;	hints.ai_socktype = SOCK_STREAM;	(void)__snprintf(num, sizeof(num), "%d", ntohs(rport));	error = getaddrinfo(*ahost, num, &hints, &res);	if (error) {		if (error == EAI_NONAME && *ahost != NULL) {			if (_IO_fwide (stderr, 0) > 0)				__fwprintf(stderr, L"%s: Unknown host\n",					   *ahost);			else				fprintf(stderr, "%s: Unknown host\n", *ahost);		} else {			if (_IO_fwide (stderr, 0) > 0)				__fwprintf(stderr, L"rcmd: getaddrinfo: %s\n",					   gai_strerror(error));			else				fprintf(stderr, "rcmd: getaddrinfo: %s\n",					gai_strerror(error));		}                return (-1);	}	pfd[0].events = POLLIN;	pfd[1].events = POLLIN;	if (res->ai_canonname){		free (ahostbuf);		ahostbuf = strdup (res->ai_canonname);		if (ahostbuf == NULL) {			if (_IO_fwide (stderr, 0) > 0)				__fwprintf(stderr, L"%s",					   _("rcmd: Cannot allocate memory\n"));			else				fputs(_("rcmd: Cannot allocate memory\n"),				      stderr);			return (-1);		}		*ahost = ahostbuf;	} else		*ahost = NULL;	ai = res;	refused = 0;	oldmask = __sigblock(sigmask(SIGURG));	for (timo = 1, lport = IPPORT_RESERVED - 1;;) {		char errbuf[200];		s = rresvport_af(&lport, ai->ai_family);		if (s < 0) {			if (errno == EAGAIN) {				if (_IO_fwide (stderr, 0) > 0)					__fwprintf(stderr, L"%s",						   _("rcmd: socket: All ports in use\n"));				else					fputs(_("rcmd: socket: All ports in use\n"),					      stderr);			} else {				if (_IO_fwide (stderr, 0) > 0)					__fwprintf(stderr,						   L"rcmd: socket: %m\n");				else					fprintf(stderr, "rcmd: socket: %m\n");			}			__sigsetmask(oldmask);			freeaddrinfo(res);			return -1;		}		__fcntl(s, F_SETOWN, pid);		if (__connect(s, ai->ai_addr, ai->ai_addrlen) >= 0)			break;		(void)__close(s);		if (errno == EADDRINUSE) {			lport--;			continue;		}		if (errno == ECONNREFUSED)			refused = 1;		if (ai->ai_next != NULL) {			int oerrno = errno;			char *buf = NULL;			getnameinfo(ai->ai_addr, ai->ai_addrlen,				    paddr, sizeof(paddr),				    NULL, 0,				    NI_NUMERICHOST);			if (__asprintf (&buf, _("connect to address %s: "),					paddr) >= 0)			  {			    if (_IO_fwide (stderr, 0) > 0)			      __fwprintf(stderr, L"%s", buf);			    else			      fputs (buf, stderr);			    free (buf);			  }			__set_errno (oerrno);			perror(0);			ai = ai->ai_next;			getnameinfo(ai->ai_addr, ai->ai_addrlen,				    paddr, sizeof(paddr),				    NULL, 0,				    NI_NUMERICHOST);			if (__asprintf (&buf, _("Trying %s...\n"), paddr) >= 0)			  {			    if (_IO_fwide (stderr, 0) > 0)			      __fwprintf (stderr, L"%s", buf);			    else			      fputs (buf, stderr);			    free (buf);			  }			continue;		}		if (refused && timo <= 16) {			(void)__sleep(timo);			timo *= 2;			ai = res;			refused = 0;			continue;		}		freeaddrinfo(res);		if (_IO_fwide (stderr, 0) > 0)			(void)__fwprintf(stderr, L"%s: %s\n", *ahost,					 __strerror_r(errno,						      errbuf, sizeof (errbuf)));		else			(void)fprintf(stderr, "%s: %s\n", *ahost,				      __strerror_r(errno,						   errbuf, sizeof (errbuf)));		__sigsetmask(oldmask);		return -1;	}	lport--;	if (fd2p == 0) {		__write(s, "", 1);		lport = 0;	} else {		char num[8];		int s2 = rresvport_af(&lport, ai->ai_family), s3;		socklen_t len = ai->ai_addrlen;		if (s2 < 0)			goto bad;		__listen(s2, 1);		(void)__snprintf(num, sizeof(num), "%d", lport);		if (__write(s, num, strlen(num)+1) != (ssize_t)strlen(num)+1) {			char *buf = NULL;			if (__asprintf (&buf, _("\rcmd: write (setting up stderr): %m\n")) >= 0)			  {			    if (_IO_fwide (stderr, 0) > 0)			      __fwprintf(stderr, L"%s", buf);			    else			      fputs (buf, stderr);			    free (buf);			  }			(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){			char *buf = NULL;			if ((errno != 0			     && __asprintf(&buf, _("\rcmd: poll (setting up stderr): %m\n")) >= 0)			    || (errno == 0				&& __asprintf(&buf, _("\poll: protocol failure in circuit setup\n")) >= 0))			  {			    if (_IO_fwide (stderr, 0) > 0)			      __fwprintf (stderr, L"%s", buf);			    else			      fputs (buf, stderr);			    free  (buf);			  }			(void)__close(s2);			goto bad;		}		s3 = TEMP_FAILURE_RETRY (accept(s2, (struct sockaddr *)&from,						&len));		switch (from.ss_family) {		case AF_INET:			rport = ntohs(((struct sockaddr_in *)&from)->sin_port);			break;		case AF_INET6:			rport = ntohs(((struct sockaddr_in6 *)&from)->sin6_port);			break;		default:			rport = 0;			break;		}		(void)__close(s2);		if (s3 < 0) {			if (_IO_fwide (stderr, 0) > 0)				(void)__fwprintf(stderr,						 L"rcmd: accept: %m\n");			else				(void)fprintf(stderr,					      "rcmd: accept: %m\n");			lport = 0;			goto bad;		}		*fd2p = s3;		if (rport >= IPPORT_RESERVED || rport < IPPORT_RESERVED / 2){			char *buf = NULL;			if (__asprintf(&buf, _("\socket: protocol failure in circuit setup\n")) >= 0)			  {			    if (_IO_fwide (stderr, 0) > 0)			      __fwprintf (stderr, L"%s", buf);			    else			      fputs (buf, stderr);			    free (buf);			  }			goto bad2;		}	}	struct iovec iov[3] =	  {	    [0] = { .iov_base = (void *) locuser,		    .iov_len = strlen (locuser) + 1 },	    [1] = { .iov_base = (void *) remuser,		    .iov_len = strlen (remuser) + 1 },	    [2] = { .iov_base = (void *) cmd,		    .iov_len = strlen (cmd) + 1 }	  };	(void) TEMP_FAILURE_RETRY (__writev (s, iov, 3));	n = TEMP_FAILURE_RETRY (__read(s, &c, 1));	if (n != 1) {		char *buf = NULL;		if ((n == 0		     && __asprintf(&buf, _("rcmd: %s: short read"),				   *ahost) >= 0)		    || (n != 0			&& __asprintf(&buf, "rcmd: %s: %m\n", *ahost) >= 0))		  {		    if (_IO_fwide (stderr, 0) > 0)		      __fwprintf (stderr, L"%s", buf);		    else		      fputs (buf, stderr);		    free (buf);		  }		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);	freeaddrinfo(res);	return s;bad2:	if (lport)		(void)__close(*fd2p);bad:	(void)__close(s);	__sigsetmask(oldmask);	freeaddrinfo(res);	return -1;}