summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/netstat/if.c56
-rw-r--r--usr.bin/netstat/route.c23
2 files changed, 57 insertions, 22 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;
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index f884be8ee78..756f5e51ff5 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.34 2000/01/14 19:59:18 deraadt Exp $ */
+/* $OpenBSD: route.c,v 1.35 2000/02/05 18:46:50 itojun Exp $ */
/* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-static char *rcsid = "$OpenBSD: route.c,v 1.34 2000/01/14 19:59:18 deraadt Exp $";
+static char *rcsid = "$OpenBSD: route.c,v 1.35 2000/02/05 18:46:50 itojun Exp $";
#endif
#endif /* not lint */
@@ -708,7 +708,7 @@ netname6(sa6, mask)
struct in6_addr *mask;
{
static char line[MAXHOSTNAMELEN + 1];
- struct in6_addr net6;
+ struct sockaddr_in6 sin6;
u_char *p;
u_char *lim;
int masklen, final = 0, illegal = 0;
@@ -720,15 +720,15 @@ netname6(sa6, mask)
int flag = 0;
#endif
- net6 = sa6->sin6_addr;
- for (i = 0; i < sizeof(net6); i++)
- net6.s6_addr[i] &= mask->s6_addr[i];
+ sin6 = *sa6;
masklen = 0;
- lim = (u_char *)mask + 16;
+ lim = (u_char *)(mask + 1);
+ i = 0;
for (p = (u_char *)mask; p < lim; p++) {
if (final && *p) {
illegal++;
+ sin6.sin6_addr.s6_addr[i++] = 0x00;
continue;
}
@@ -772,9 +772,14 @@ netname6(sa6, mask)
illegal++;
break;
}
+
+ if (!illegal)
+ sin6.sin6_addr.s6_addr[i++] &= *p;
+ else
+ sin6.sin6_addr.s6_addr[i++] = 0x00;
}
- if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sa6->sin6_addr))
+ if (masklen == 0 && IN6_IS_ADDR_UNSPECIFIED(&sin6.sin6_addr))
return("default");
if (illegal)
@@ -782,7 +787,7 @@ netname6(sa6, mask)
if (nflag)
flag |= NI_NUMERICHOST;
- getnameinfo((struct sockaddr *)sa6, sa6->sin6_len, hbuf, sizeof(hbuf),
+ getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, hbuf, sizeof(hbuf),
NULL, 0, flag);
snprintf(line, sizeof(line), "%s/%d", hbuf, masklen);
return line;