diff options
author | ume <ume@FreeBSD.org> | 2002-04-15 18:45:20 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2002-04-15 18:45:20 +0000 |
commit | 31dc2e2cc426590eef1626c19b77a7f4491f82e3 (patch) | |
tree | 62d6952b6b82af7d8447a99a2d3af9498d9cd431 /lib/libc | |
parent | 4cfa23df554c7ea7a88c06ca7f696d4b783af7e1 (diff) | |
download | FreeBSD-src-31dc2e2cc426590eef1626c19b77a7f4491f82e3.zip FreeBSD-src-31dc2e2cc426590eef1626c19b77a7f4491f82e3.tar.gz |
Add awareness of an IPv6.
MFC after: 1 week
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/rcmdsh.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/lib/libc/net/rcmdsh.c b/lib/libc/net/rcmdsh.c index b5cc292..7972e34 100644 --- a/lib/libc/net/rcmdsh.c +++ b/lib/libc/net/rcmdsh.c @@ -57,17 +57,18 @@ __FBSDID("$FreeBSD$"); * program in place of a direct rcmd(3) function call so as to * avoid having to be root. Note that rport is ignored. */ -/* ARGSUSED */ int rcmdsh(ahost, rport, locuser, remuser, cmd, rshprog) char **ahost; - int rport __unused; + int rport; const char *locuser, *remuser, *cmd, *rshprog; { - struct hostent *hp; - int cpid, sp[2]; + struct addrinfo hints, *res; + int cpid, sp[2], error; char *p; struct passwd *pw; + char num[8]; + static char hbuf[NI_MAXHOST]; /* What rsh/shell to use. */ if (rshprog == NULL) @@ -81,11 +82,23 @@ rcmdsh(ahost, rport, locuser, remuser, cmd, rshprog) /* Validate remote hostname. */ if (strcmp(*ahost, "localhost") != 0) { - if ((hp = gethostbyname(*ahost)) == NULL) { - herror(*ahost); + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_CANONNAME; + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + (void)snprintf(num, sizeof(num), "%d", ntohs(rport)); + error = getaddrinfo(*ahost, num, &hints, &res); + if (error) { + fprintf(stderr, "rcmdsh: getaddrinfo: %s\n", + gai_strerror(error)); return (-1); } - *ahost = hp->h_name; + if (res->ai_canonname) { + strncpy(hbuf, res->ai_canonname, sizeof(hbuf) - 1); + hbuf[sizeof(hbuf) - 1] = '\0'; + *ahost = hbuf; + } + freeaddrinfo(res); } /* Get a socketpair we'll use for stdin and stdout. */ |