summaryrefslogtreecommitdiffstats
path: root/freebsd/usr.bin/netstat/if.c
diff options
context:
space:
mode:
Diffstat (limited to 'freebsd/usr.bin/netstat/if.c')
-rw-r--r--freebsd/usr.bin/netstat/if.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/freebsd/usr.bin/netstat/if.c b/freebsd/usr.bin/netstat/if.c
index aaf1fd88..73f74967 100644
--- a/freebsd/usr.bin/netstat/if.c
+++ b/freebsd/usr.bin/netstat/if.c
@@ -68,6 +68,9 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
#include <libutil.h>
+#ifdef INET6
+#include <netdb.h>
+#endif
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
@@ -84,7 +87,7 @@ static void sidewaysintpr(int, u_long);
static void catchalarm(int);
#ifdef INET6
-static char ntop_buf[INET6_ADDRSTRLEN]; /* for inet_ntop() */
+static char addr_buf[NI_MAXHOST]; /* for getnameinfo() */
#endif
/*
@@ -196,7 +199,6 @@ intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
} ifaddr;
u_long ifaddraddr;
u_long ifaddrfound;
- u_long ifnetfound;
u_long opackets;
u_long ipackets;
u_long obytes;
@@ -260,7 +262,6 @@ intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
link_layer = 0;
if (ifaddraddr == 0) {
- ifnetfound = ifnetaddr;
if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) != 0)
return;
strlcpy(name, ifnet.if_xname, sizeof(name));
@@ -354,13 +355,14 @@ intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
#ifdef INET6
case AF_INET6:
sockin6 = (struct sockaddr_in6 *)sa;
+ in6_fillscopeid(&ifaddr.in6.ia_addr);
printf("%-13.13s ",
netname6(&ifaddr.in6.ia_addr,
&ifaddr.in6.ia_prefixmask.sin6_addr));
- printf("%-17.17s ",
- inet_ntop(AF_INET6,
- &sockin6->sin6_addr,
- ntop_buf, sizeof(ntop_buf)));
+ in6_fillscopeid(sockin6);
+ getnameinfo(sa, sa->sa_len, addr_buf,
+ sizeof(addr_buf), 0, 0, NI_NUMERICHOST);
+ printf("%-17.17s ", addr_buf);
network_layer = 1;
break;
@@ -409,7 +411,7 @@ intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
n = cp - sa->sa_data + 1;
cp = sa->sa_data;
hexprint:
- while (--n >= 0)
+ while ((--n >= 0) && (m < 30))
m += printf("%02x%c", *cp++ & 0xff,
n > 0 ? ':' : ' ');
m = 32 - m;
@@ -486,13 +488,13 @@ intpr(int interval1, u_long ifnetaddr, void (*pfunc)(char *))
break;
#ifdef INET6
case AF_INET6:
+ in6_fillscopeid(&msa.in6);
+ getnameinfo(&msa.sa, msa.sa.sa_len,
+ addr_buf, sizeof(addr_buf), 0, 0,
+ NI_NUMERICHOST);
printf("%*s %-19.19s(refs: %d)\n",
Wflag ? 27 : 25, "",
- inet_ntop(AF_INET6,
- &msa.in6.sin6_addr,
- ntop_buf,
- sizeof(ntop_buf)),
- ifma.ifma_refcount);
+ addr_buf, ifma.ifma_refcount);
break;
#endif /* INET6 */
case AF_LINK: