Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107478617
D45594.id141479.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D45594.id141479.diff
View Options
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c
--- a/usr.sbin/arp/arp.c
+++ b/usr.sbin/arp/arp.c
@@ -70,7 +70,7 @@
#include <libxo/xo.h>
#include "arp.h"
-typedef void (action_fn)(struct sockaddr_dl *sdl, struct sockaddr_in *s_in,
+typedef void (action_fn)(struct sockaddr_dl *sdl, struct sockaddr *sa,
struct rt_msghdr *rtm);
static void nuke_entries(uint32_t ifindex, struct in_addr addr);
static int print_entries(uint32_t ifindex, struct in_addr addr);
@@ -255,20 +255,25 @@
struct sockaddr_in *
getaddr(char *host)
{
- struct hostent *hp;
+ struct addrinfo *res;
static struct sockaddr_in reply;
+ int error;
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));
+ error = getaddrinfo(host, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &res);
+ if (error != 0) {
+ xo_warnx("%s: %s", host, (error == EAI_SYSTEM)
+ ? strerror(errno) : gai_strerror(error));
return (NULL);
}
- bcopy((char *)hp->h_addr, (char *)&reply.sin_addr,
- sizeof reply.sin_addr);
+ memcpy(&reply, res->ai_addr, res->ai_addrlen);
+ freeaddrinfo(res);
}
return (&reply);
}
@@ -578,7 +583,7 @@
(addr != sin2->sin_addr.s_addr))
continue;
found_entry = 1;
- (*action)(sdl, sin2, rtm);
+ (*action)(sdl, (struct sockaddr *)sin2, rtm);
}
free(buf);
return (found_entry);
@@ -590,11 +595,13 @@
static void
print_entry(struct sockaddr_dl *sdl,
- struct sockaddr_in *addr, struct rt_msghdr *rtm)
+ struct sockaddr *addr, struct rt_msghdr *rtm)
{
+ struct sockaddr_in *sin = (struct sockaddr_in *)addr;
const char *host;
- struct hostent *hp;
+ char hostbuf[NI_MAXHOST];
struct if_nameindex *p;
+ int error;
if (ifnameindex == NULL)
if ((ifnameindex = if_nameindex()) == NULL)
@@ -602,20 +609,20 @@
xo_open_instance("arp-cache");
- if (!opts.nflag)
- hp = gethostbyaddr((caddr_t)&(addr->sin_addr),
- sizeof addr->sin_addr, AF_INET);
- else
- hp = 0;
- if (hp)
- host = hp->h_name;
- else {
- host = "?";
- if (h_errno == TRY_AGAIN)
- opts.nflag = true;
+ if (!opts.nflag) {
+ error = getnameinfo(addr, addr->sa_len, hostbuf,
+ sizeof(hostbuf), NULL, 0, NI_NAMEREQD);
+ if (error != 0) {
+ host = "?";
+ if (error == EAI_AGAIN)
+ opts.nflag = true;
+ }
+ else {
+ host = hostbuf;
+ }
}
xo_emit("{:hostname/%s} ({:ip-address/%s}) at ", host,
- inet_ntoa(addr->sin_addr));
+ inet_ntoa(sin->sin_addr));
if (sdl->sdl_alen) {
if ((sdl->sdl_type == IFT_ETHER ||
sdl->sdl_type == IFT_L2VLAN ||
@@ -703,14 +710,15 @@
*/
static void
nuke_entry(struct sockaddr_dl *sdl __unused,
- struct sockaddr_in *addr, struct rt_msghdr *rtm)
+ struct sockaddr *addr, struct rt_msghdr *rtm)
{
+ struct sockaddr_in *sin = (struct sockaddr_in *)addr;
char ip[20];
if (rtm->rtm_flags & RTF_PINNED)
return;
- snprintf(ip, sizeof(ip), "%s", inet_ntoa(addr->sin_addr));
+ snprintf(ip, sizeof(ip), "%s", inet_ntoa(sin->sin_addr));
delete(ip);
}
diff --git a/usr.sbin/arp/arp_netlink.c b/usr.sbin/arp/arp_netlink.c
--- a/usr.sbin/arp/arp_netlink.c
+++ b/usr.sbin/arp/arp_netlink.c
@@ -177,22 +177,24 @@
print_entry(struct snl_parsed_neigh *neigh, struct snl_parsed_link_simple *link)
{
const char *host;
- struct hostent *hp;
- struct sockaddr_in *addr = (struct sockaddr_in *)neigh->nda_dst;
+ char hostbuf[NI_MAXHOST];
+ struct sockaddr *sa = neigh->nda_dst;
+ struct sockaddr_in *addr = (struct sockaddr_in *)sa;
+ int error;
xo_open_instance("arp-cache");
- if (!opts.nflag)
- hp = gethostbyaddr((caddr_t)&(addr->sin_addr),
- sizeof(addr->sin_addr), AF_INET);
- else
- hp = 0;
- if (hp)
- host = hp->h_name;
- else {
- host = "?";
- if (h_errno == TRY_AGAIN)
- opts.nflag = true;
+ if (!opts.nflag) {
+ error = getnameinfo(sa, sa->sa_len, hostbuf,
+ sizeof(hostbuf), NULL, 0, NI_NAMEREQD);
+ if (error != 0) {
+ host = "?";
+ if (error == EAI_AGAIN)
+ opts.nflag = true;
+ }
+ else {
+ host = hostbuf;
+ }
}
xo_emit("{:hostname/%s} ({:ip-address/%s}) at ", host,
inet_ntoa(addr->sin_addr));
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 15, 6:47 PM (15 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15814094
Default Alt Text
D45594.id141479.diff (4 KB)
Attached To
Mode
D45594: arp: remove gethostby*() calls
Attached
Detach File
Event Timeline
Log In to Comment