Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F160182372
D21589.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D21589.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D21589: arp.c: use getaddrinfo(3) instead of gethostbyname(3)
Attached
Detach File
Event Timeline
Log In to Comment