diff options
author | hrs <hrs@FreeBSD.org> | 2014-10-09 22:54:51 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2014-10-09 22:54:51 +0000 |
commit | 200a7a67a401e6a88245192b38b83d28879f528c (patch) | |
tree | 67fed4e38de8a81478112590fddcf6152ef9a561 /usr.bin/netstat/route.c | |
parent | 70056e5be98d58f5fe68ccf5cfe4b394f5709ae5 (diff) | |
download | FreeBSD-src-200a7a67a401e6a88245192b38b83d28879f528c.zip FreeBSD-src-200a7a67a401e6a88245192b38b83d28879f528c.tar.gz |
MFC r266494:
- Fix a bug which can make sysctl() fail when -F is specified.
- Increase WID_IF_DEFAULT() from 6 to 8 (the default for AF_INET6) because
we have interfaces with longer names than 6 chars like epairN{a,b}.
- Style fixes.
Diffstat (limited to 'usr.bin/netstat/route.c')
-rw-r--r-- | usr.bin/netstat/route.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c index 26581b4..3ddb17b 100644 --- a/usr.bin/netstat/route.c +++ b/usr.bin/netstat/route.c @@ -238,13 +238,13 @@ pr_family(int af1) #ifndef INET6 #define WID_DST_DEFAULT(af) 18 /* width of destination column */ #define WID_GW_DEFAULT(af) 18 /* width of gateway column */ -#define WID_IF_DEFAULT(af) (Wflag ? 8 : 6) /* width of netif column */ +#define WID_IF_DEFAULT(af) (Wflag ? 10 : 8) /* width of netif column */ #else #define WID_DST_DEFAULT(af) \ ((af) == AF_INET6 ? (numeric_addr ? 33: 18) : 18) #define WID_GW_DEFAULT(af) \ ((af) == AF_INET6 ? (numeric_addr ? 29 : 18) : 18) -#define WID_IF_DEFAULT(af) ((af) == AF_INET6 ? 8 : (Wflag ? 8 : 6)) +#define WID_IF_DEFAULT(af) ((af) == AF_INET6 ? 8 : (Wflag ? 10 : 8)) #endif /*INET6*/ static int wid_dst; @@ -594,16 +594,13 @@ p_rtable_sysctl(int fibnum, int af) mib[4] = NET_RT_DUMP; mib[5] = 0; mib[6] = fibnum; - if (sysctl(mib, 7, NULL, &needed, NULL, 0) < 0) { - err(1, "sysctl: net.route.0.%d.dump.%d estimate", af, fibnum); - } - - if ((buf = malloc(needed)) == 0) { + if (sysctl(mib, nitems(mib), NULL, &needed, NULL, 0) < 0) + err(EX_OSERR, "sysctl: net.route.0.%d.dump.%d estimate", af, + fibnum); + if ((buf = malloc(needed)) == NULL) errx(2, "malloc(%lu)", (unsigned long)needed); - } - if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { + if (sysctl(mib, nitems(mib), buf, &needed, NULL, 0) < 0) err(1, "sysctl: net.route.0.%d.dump.%d", af, fibnum); - } lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; |