Index: usr.sbin/arp/arp.c =================================================================== --- usr.sbin/arp/arp.c +++ usr.sbin/arp/arp.c @@ -68,6 +68,7 @@ #include +#include #include #include #include @@ -271,22 +272,31 @@ static struct sockaddr_in * getaddr(char *host) { - struct hostent *hp; - static struct sockaddr_in reply; - - bzero(&reply, sizeof(reply)); - reply.sin_len = sizeof(reply); - reply.sin_family = AF_INET; - reply.sin_addr.s_addr = inet_addr(host); - if (reply.sin_addr.s_addr == INADDR_NONE) { - if (!(hp = gethostbyname(host))) { - xo_warnx("%s: %s", host, hstrerror(h_errno)); - return (NULL); - } - bcopy((char *)hp->h_addr, (char *)&reply.sin_addr, - sizeof reply.sin_addr); + struct addrinfo hints, *res; + static struct sockaddr_in sin; + int err; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + + err = getaddrinfo(host, NULL, &hints, &res); + + if (err != 0) { + xo_warnx("%s: %s", host, gai_strerror(err)); + return (NULL); + } + + if (res->ai_next != NULL) { + xo_warnx("%s resolved to multiple addresses", host); + freeaddrinfo(res); + return (NULL); } - return (&reply); + + assert(res->ai_addrlen == sizeof(struct sockaddr_in)); + memcpy(&sin, res->ai_addr, res->ai_addrlen); + + freeaddrinfo(res); + return (&sin); } /*