Page MenuHomeFreeBSD

D45594.id139879.diff
No OneTemporary

D45594.id139879.diff

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
@@ -255,20 +255,32 @@
struct sockaddr_in *
getaddr(char *host)
{
- struct hostent *hp;
+ struct addrinfo hints, *res, *p;
static struct sockaddr_in reply;
+ int status;
bzero(&reply, sizeof(reply));
- reply.sin_len = sizeof(reply);
- reply.sin_family = AF_INET;
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = 0;
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));
+ status = getaddrinfo(host, NULL, &hints, &res);
+ if (status != 0) {
+ xo_warnx("%s: %s", host, gai_strerror(status));
return (NULL);
}
- bcopy((char *)hp->h_addr, (char *)&reply.sin_addr,
- sizeof reply.sin_addr);
+ for (p = res; p != NULL; p = p->ai_next) {
+ if (p->ai_family == AF_INET) {
+ memcpy(&reply, p->ai_addr, p->ai_addrlen);
+ break;
+ }
+ }
+ freeaddrinfo(res);
+ if (p == NULL) {
+ xo_warnx("%s: No valid ipv4 address found", host);
+ return NULL;
+ }
}
return (&reply);
}
@@ -593,8 +605,9 @@
struct sockaddr_in *addr, struct rt_msghdr *rtm)
{
const char *host;
- struct hostent *hp;
+ char hostbuf[NI_MAXHOST];
struct if_nameindex *p;
+ int status;
if (ifnameindex == NULL)
if ((ifnameindex = if_nameindex()) == NULL)
@@ -602,17 +615,17 @@
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) {
+ status = getnameinfo((struct sockaddr *)addr, sizeof(struct sockaddr_in),
+ hostbuf, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
+ if (status != 0) {
+ host = "?";
+ if (status == EAI_AGAIN)
+ opts.nflag = true;
+ }
+ else {
+ host = hostbuf;
+ }
}
xo_emit("{:hostname/%s} ({:ip-address/%s}) at ", host,
inet_ntoa(addr->sin_addr));
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,23 @@
print_entry(struct snl_parsed_neigh *neigh, struct snl_parsed_link_simple *link)
{
const char *host;
- struct hostent *hp;
+ char hostbuf[NI_MAXHOST];
struct sockaddr_in *addr = (struct sockaddr_in *)neigh->nda_dst;
+ int status;
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) {
+ status = getnameinfo((struct sockaddr *)addr, sizeof(struct sockaddr_in),
+ hostbuf, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
+ if (status != 0) {
+ host = "?";
+ if (status == EAI_AGAIN)
+ opts.nflag = true;
+ }
+ else {
+ host = hostbuf;
+ }
}
xo_emit("{:hostname/%s} ({:ip-address/%s}) at ", host,
inet_ntoa(addr->sin_addr));

File Metadata

Mime Type
text/plain
Expires
Wed, Jan 15, 6:47 PM (15 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15814099
Default Alt Text
D45594.id139879.diff (3 KB)

Event Timeline