diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-02-05 18:46:51 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2000-02-05 18:46:51 +0000 |
commit | ceeff0869b041497a8661d7a54bb6a449e573c49 (patch) | |
tree | 0698350220613216f85d79f8f62dc199d94291f0 /usr.bin/netstat/if.c | |
parent | f0c4bfe6054c7326d8746f80720e06380d98778c (diff) |
fix -in printing on IPv6 (network portion was not masked properly).
enable scopeid for -in.
don't truncate output on -inv.
Diffstat (limited to 'usr.bin/netstat/if.c')
-rw-r--r-- | usr.bin/netstat/if.c | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index 69db5e376d9..4c0d1bc2d2e 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.19 2000/01/18 05:39:34 itojun Exp $ */ +/* $OpenBSD: if.c,v 1.20 2000/02/05 18:46:50 itojun Exp $ */ /* $NetBSD: if.c,v 1.16.4.2 1996/06/07 21:46:46 thorpej Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94"; #else -static char *rcsid = "$OpenBSD: if.c,v 1.19 2000/01/18 05:39:34 itojun Exp $"; +static char *rcsid = "$OpenBSD: if.c,v 1.20 2000/02/05 18:46:50 itojun Exp $"; #endif #endif /* not lint */ @@ -99,6 +99,7 @@ intpr(interval, ifnetaddr) struct sockaddr *sa; struct ifnet_head ifhead; /* TAILQ_HEAD */ char name[IFNAMSIZ]; + int n; if (ifnetaddr == 0) { printf("ifnet: symbol not defined\n"); @@ -175,15 +176,23 @@ intpr(interval, ifnetaddr) */ in = inet_makeaddr(ifaddr.in.ia_subnet, INADDR_ANY); - printf("%-11.11s ", netname(in.s_addr, - ifaddr.in.ia_subnetmask)); + cp = netname(in.s_addr, + ifaddr.in.ia_subnetmask); #else - printf("%-11.11s ", - netname(ifaddr.in.ia_subnet, - ifaddr.in.ia_subnetmask)); + cp = netname(ifaddr.in.ia_subnet, + ifaddr.in.ia_subnetmask); #endif - printf("%-17.17s ", - routename(sin->sin_addr.s_addr)); + if (vflag) + n = strlen(cp) < 11 ? 11 : strlen(cp); + else + n = 11; + printf("%-*.*s ", n, n, cp); + cp = routename(sin->sin_addr.s_addr); + if (vflag) + n = strlen(cp) < 17 ? 17 : strlen(cp); + else + n = 17; + printf("%-*.*s ", n, n, cp); if (aflag) { u_long multiaddr; @@ -202,10 +211,31 @@ intpr(interval, ifnetaddr) #ifdef INET6 case AF_INET6: sin6 = (struct sockaddr_in6 *)sa; - printf("%-11.11s ", - netname6(&ifaddr.in6.ia_addr, - &ifaddr.in6.ia_prefixmask.sin6_addr)); - printf("%-17.17s ", routename6(sin6)); +#ifdef KAME_SCOPEID + if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { + sin6->sin6_scope_id = + ntohs(*(u_int16_t *) + &sin6->sin6_addr.s6_addr[2]); + /* too little width */ + if (!vflag) + sin6->sin6_scope_id = 0; + sin6->sin6_addr.s6_addr[2] = 0; + sin6->sin6_addr.s6_addr[3] = 0; + } +#endif + cp = netname6(&ifaddr.in6.ia_addr, + &ifaddr.in6.ia_prefixmask.sin6_addr); + if (vflag) + n = strlen(cp) < 11 ? 11 : strlen(cp); + else + n = 11; + printf("%-*.*s ", n, n, cp); + cp = routename6(sin6); + if (vflag) + n = strlen(cp) < 17 ? 17 : strlen(cp); + else + n = 17; + printf("%-*.*s ", n, n, cp); if (aflag) { u_long multiaddr; struct in6_multi inm; |