summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.bin/netstat/if.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index 0bb2581..4b802d4 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -37,7 +37,7 @@ static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
+#include <sys/param.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@@ -231,7 +231,8 @@ intpr(int interval, void (*pfunc)(char *), int af)
{
struct ifaddrs *ifap, *ifa;
struct ifmaddrs *ifmap, *ifma;
-
+ u_int ifn_len_max = 5;
+
if (interval)
return sidewaysintpr(interval);
@@ -240,11 +241,19 @@ intpr(int interval, void (*pfunc)(char *), int af)
if (aflag && getifmaddrs(&ifmap) != 0)
err(EX_OSERR, "getifmaddrs");
+ if (Wflag) {
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ if (interface != NULL &&
+ strcmp(ifa->ifa_name, interface) != 0)
+ continue;
+ if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af)
+ continue;
+ ifn_len_max = MAX(ifn_len_max, strlen(ifa->ifa_name));
+ }
+ }
+
if (!pfunc) {
- if (Wflag)
- printf("%-7.7s", "Name");
- else
- printf("%-5.5s", "Name");
+ printf("%-*.*s", ifn_len_max, ifn_len_max, "Name");
printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s",
"Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop");
if (bflag)
@@ -283,10 +292,7 @@ intpr(int interval, void (*pfunc)(char *), int af)
if (af != AF_UNSPEC && ifa->ifa_addr->sa_family != af)
continue;
- if (Wflag)
- printf("%-7.7s", ifa->ifa_name);
- else
- printf("%-5.5s", ifa->ifa_name);
+ printf("%-*.*s", ifn_len_max, ifn_len_max, ifa->ifa_name);
#define IFA_MTU(ifa) (((struct if_data *)(ifa)->ifa_data)->ifi_mtu)
show_stat("lu", 6, IFA_MTU(ifa), IFA_MTU(ifa), 0);
OpenPOWER on IntegriCloud