Give enough room for addresses when -W option is specified.
This commit is contained in:
parent
011ae9c907
commit
cca052c621
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=290391
@ -272,6 +272,7 @@ intpr(void (*pfunc)(char *), int af)
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
struct ifmaddrs *ifmap, *ifma;
|
||||
u_int ifn_len_max = 5, ifn_len;
|
||||
u_int has_ipv6 = 0, net_len = 13, addr_len = 17;
|
||||
|
||||
if (interval)
|
||||
return sidewaysintpr();
|
||||
@ -292,15 +293,23 @@ intpr(void (*pfunc)(char *), int af)
|
||||
if ((ifa->ifa_flags & IFF_UP) == 0)
|
||||
++ifn_len;
|
||||
ifn_len_max = MAX(ifn_len_max, ifn_len);
|
||||
if (ifa->ifa_addr->sa_family == AF_INET6)
|
||||
has_ipv6 = 1;
|
||||
}
|
||||
if (has_ipv6) {
|
||||
net_len = 24;
|
||||
addr_len = 39;
|
||||
} else
|
||||
net_len = 18;
|
||||
}
|
||||
|
||||
xo_open_list("interface");
|
||||
if (!pfunc) {
|
||||
xo_emit("{T:/%-*.*s}", ifn_len_max, ifn_len_max, "Name");
|
||||
xo_emit(" {T:/%5.5s} {T:/%-13.13s} {T:/%-17.17s} {T:/%8.8s} "
|
||||
xo_emit(" {T:/%5.5s} {T:/%-*.*s} {T:/%-*.*s} {T:/%8.8s} "
|
||||
"{T:/%5.5s} {T:/%5.5s}",
|
||||
"Mtu", "Network", "Address", "Ipkts", "Ierrs", "Idrop");
|
||||
"Mtu", net_len, net_len, "Network", addr_len, addr_len,
|
||||
"Address", "Ipkts", "Ierrs", "Idrop");
|
||||
if (bflag)
|
||||
xo_emit(" {T:/%10.10s}","Ibytes");
|
||||
xo_emit(" {T:/%8.8s} {T:/%5.5s}", "Opkts", "Oerrs");
|
||||
@ -357,22 +366,26 @@ intpr(void (*pfunc)(char *), int af)
|
||||
|
||||
switch (ifa->ifa_addr->sa_family) {
|
||||
case AF_UNSPEC:
|
||||
xo_emit("{:network/%-13.13s} ", "none");
|
||||
xo_emit("{:address/%-15.15s} ", "none");
|
||||
xo_emit("{:network/%-*.*s} ", net_len, net_len,
|
||||
"none");
|
||||
xo_emit("{:address/%-*.*s} ", addr_len, addr_len,
|
||||
"none");
|
||||
break;
|
||||
case AF_INET:
|
||||
#ifdef INET6
|
||||
case AF_INET6:
|
||||
#endif /* INET6 */
|
||||
if (Wflag) {
|
||||
xo_emit("{t:network/%-13s} ",
|
||||
xo_emit("{t:network/%-*s} ", net_len,
|
||||
netname(ifa->ifa_addr, ifa->ifa_netmask));
|
||||
xo_emit("{t:address/%-17s} ",
|
||||
xo_emit("{t:address/%-*s} ", addr_len,
|
||||
routename(ifa->ifa_addr, numeric_addr));
|
||||
} else {
|
||||
xo_emit("{t:network/%-13.13s} ",
|
||||
xo_emit("{t:network/%-*.*s} ",
|
||||
net_len, net_len,
|
||||
netname(ifa->ifa_addr, ifa->ifa_netmask));
|
||||
xo_emit("{t:address/%-17.17s} ",
|
||||
xo_emit("{t:address/%-*.*s} ",
|
||||
addr_len, addr_len,
|
||||
routename(ifa->ifa_addr, numeric_addr));
|
||||
}
|
||||
|
||||
@ -385,14 +398,15 @@ intpr(void (*pfunc)(char *), int af)
|
||||
|
||||
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
||||
sprintf(linknum, "<Link#%d>", sdl->sdl_index);
|
||||
xo_emit("{t:network/%-13.13s} ", linknum);
|
||||
xo_emit("{t:network/%-*.*s} ", net_len, net_len,
|
||||
linknum);
|
||||
if (sdl->sdl_nlen == 0 &&
|
||||
sdl->sdl_alen == 0 &&
|
||||
sdl->sdl_slen == 0)
|
||||
xo_emit("{P: }");
|
||||
else
|
||||
xo_emit("{:address/%-17.17s} ",
|
||||
routename(ifa->ifa_addr, 1));
|
||||
xo_emit("{:address/%-*.*s} ", addr_len,
|
||||
addr_len, routename(ifa->ifa_addr, 1));
|
||||
link = true;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user