summaryrefslogtreecommitdiff
path: root/lib/libc/net
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2016-05-28 15:46:01 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2016-05-28 15:46:01 +0000
commit3a55204c7136fc2a34605609cc40179a0b8e8d91 (patch)
treed6e7b1008101392409fe1bac276e1f6860becfef /lib/libc/net
parenta9b53e09dcd851e31206b50f81924837ef459e3c (diff)
Use getaddrinfo() instead of the non-standard gethostbyname2().
OK deraadt@ jca@ jung@ florian@
Diffstat (limited to 'lib/libc/net')
-rw-r--r--lib/libc/net/rcmdsh.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/libc/net/rcmdsh.c b/lib/libc/net/rcmdsh.c
index 14275d414a4..b9cbd6d5d14 100644
--- a/lib/libc/net/rcmdsh.c
+++ b/lib/libc/net/rcmdsh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcmdsh.c,v 1.18 2015/11/24 22:03:33 millert Exp $ */
+/* $OpenBSD: rcmdsh.c,v 1.19 2016/05/28 15:46:00 millert Exp $ */
/*
* Copyright (c) 2001, MagniComp
@@ -38,6 +38,7 @@
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
+#include <limits.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
@@ -55,7 +56,8 @@ int
rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser,
const char *cmd, char *rshprog)
{
- struct hostent *hp;
+ static char hbuf[HOST_NAME_MAX+1];
+ struct addrinfo hint, *res;
int sp[2];
pid_t cpid;
char *p, pwbuf[_PW_BUF_LEN];
@@ -74,9 +76,16 @@ rcmdsh(char **ahost, int rport, const char *locuser, const char *remuser,
/* Validate remote hostname. */
if (strcmp(*ahost, "localhost") != 0) {
- if ((hp = gethostbyname2(*ahost, AF_INET)) ||
- (hp = gethostbyname2(*ahost, AF_INET6)))
- *ahost = hp->h_name;
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_family = PF_UNSPEC;
+ hint.ai_flags = AI_CANONNAME;
+ if (getaddrinfo(*ahost, NULL, &hint, &res) == 0) {
+ if (res->ai_canonname) {
+ strlcpy(hbuf, res->ai_canonname, sizeof(hbuf));
+ *ahost = hbuf;
+ }
+ freeaddrinfo(res);
+ }
}
/* Get a socketpair we'll use for stdin and stdout. */