Page MenuHomeFreeBSD

D21589.diff
No OneTemporary

D21589.diff

Index: usr.sbin/arp/arp.c
===================================================================
--- usr.sbin/arp/arp.c
+++ usr.sbin/arp/arp.c
@@ -68,6 +68,7 @@
#include <arpa/inet.h>
+#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -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);
}
/*

File Metadata

Mime Type
text/plain
Expires
Mon, Jun 22, 11:31 PM (6 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34218840
Default Alt Text
D21589.diff (1 KB)

Event Timeline