Date: Sat, 19 Mar 2016 20:56:35 +0000 From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 161986] [patch] netstat(1): Interface auto-width in "netstat -rn" Message-ID: <bug-161986-8-Q6A3EkAOUx@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-161986-8@https.bugs.freebsd.org/bugzilla/> References: <bug-161986-8@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=161986 Yaroslav Shvets <yaroslav.shvets@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yaroslav.shvets@gmail.com --- Comment #4 from Yaroslav Shvets <yaroslav.shvets@gmail.com> --- I prefer to rename interfaces for convenient operation in ipfw by masks: # ipfw add allow ... in via if_wan* # ipfw add deny ... out via if_vpn* etc I also observe the effect of trimming interface names after the renaming ones: # ifconfig lagg0.17 name if_wan_kav_bgp $ netstat -i | head -2 Name Mtu Network Address Ipkts Ierrs Idrop Opkts Oerrs Coll if_wa 1500 <Link#1> 00:0c:29:6a:c0:7f 119703 0 0 88432 1027 0 ^^^^^ if_wa instead if_wan_kav_bgp $ netstat -iW | head -2 Name Mtu Network Address Ipkts Ierrs Idrop Opkts Oerrs Coll if_wan_ 1500 <Link#1> 00:0c:29:6a:c0:7f 119713 0 0 88440 1027 0 ^^^^^^^ if_wan_ instead if_wan_kav_bgp $ netstat -r | head -5 | tail -2 Destination Gateway Flags Netif Expire default gw-kav UGS if_wan_k ^^^^^^^^ if_wan_k instead if_wan_kav_bgp $ netstat -rW | head -5 | tail -2 Destination Gateway Flags Use Mtu Netif Expire default gw-kav-bgp UGS 762465 1500 if_wan_kav ^^^^^^^^^^ if_wan_kav instead if_wan_kav_bgp The problem of trimmed interface names in the output of netstat is to use uncorrectly hardcoded length interface names. There are two patches that use IFNAMSIZ from <net/if.h> instead of fixed values. $ cd /usr/src/usr.bin/netstat $ cat patch-if.c --- if.c.orig 2016-03-19 15:05:31.758234000 +0200 +++ if.c 2016-03-19 21:10:58.987339000 +0200 @@ -240,9 +240,9 @@ if (!pfunc) { if (Wflag) - printf("%-7.7s", "Name"); + printf("%-*.*s", IFNAMSIZ-1, IFNAMSIZ-1, "Name"); else - printf("%-5.5s", "Name"); + printf("%-*.*s", IFNAMSIZ-1, IFNAMSIZ-1, "Name"); printf(" %5.5s %-13.13s %-17.17s %8.8s %5.5s %5.5s", "Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop"); if (bflag) @@ -282,9 +282,9 @@ continue; if (Wflag) - printf("%-7.7s", ifa->ifa_name); + printf("%-*.*s", IFNAMSIZ-1, IFNAMSIZ-1, ifa->ifa_name); else - printf("%-5.5s", ifa->ifa_name); + printf("%-*.*s", IFNAMSIZ-1, IFNAMSIZ-1, 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)); $ cat patch-route.c --- route.c.orig 2016-03-19 15:05:31.783407000 +0200 +++ route.c 2016-03-19 21:09:28.400830000 +0200 @@ -238,13 +238,13 @@ #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 ? 10 : 8) /* width of netif column */ +#define WID_IF_DEFAULT(af) IFNAMSIZ-1 /* 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 ? 10 : 8)) +#define WID_IF_DEFAULT(af) ((af) == AF_INET6 ? 8 : IFNAMSIZ-1) #endif /*INET6*/ static int wid_dst; -- You are receiving this mail because: You are the assignee for the bug.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-161986-8-Q6A3EkAOUx>
