summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/netstat/main.c9
-rw-r--r--usr.bin/netstat/netstat.117
-rw-r--r--usr.bin/netstat/netstat.h3
-rw-r--r--usr.bin/netstat/route.c83
4 files changed, 51 insertions, 61 deletions
diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c
index 6ceb6764e2c..f035fca2c46 100644
--- a/usr.bin/netstat/main.c
+++ b/usr.bin/netstat/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.12 1997/07/23 04:38:33 denny Exp $ */
+/* $OpenBSD: main.c,v 1.13 1998/02/26 10:06:07 peter Exp $ */
/* $NetBSD: main.c,v 1.9 1996/05/07 02:55:02 thorpej Exp $ */
/*
@@ -44,7 +44,7 @@ char copyright[] =
#if 0
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
#else
-static char *rcsid = "$OpenBSD: main.c,v 1.12 1997/07/23 04:38:33 denny Exp $";
+static char *rcsid = "$OpenBSD: main.c,v 1.13 1998/02/26 10:06:07 peter Exp $";
#endif
#endif /* not lint */
@@ -248,7 +248,7 @@ main(argc, argv)
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "Aadf:ghI:iM:mN:np:rstuw:")) != -1)
+ while ((ch = getopt(argc, argv, "Aadf:ghI:iM:mN:np:rstuvw:")) != -1)
switch(ch) {
case 'A':
Aflag = 1;
@@ -326,6 +326,9 @@ main(argc, argv)
case 'u':
af = AF_UNIX;
break;
+ case 'v':
+ vflag = 1;
+ break;
case 'w':
interval = atoi(optarg);
iflag = 1;
diff --git a/usr.bin/netstat/netstat.1 b/usr.bin/netstat/netstat.1
index 84c4f427702..3b15298ed8b 100644
--- a/usr.bin/netstat/netstat.1
+++ b/usr.bin/netstat/netstat.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: netstat.1,v 1.9 1997/09/19 09:24:22 deraadt Exp $
+.\" $OpenBSD: netstat.1,v 1.10 1998/02/26 10:06:09 peter Exp $
.\" $NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $
.\"
.\" Copyright (c) 1983, 1990, 1992, 1993
@@ -186,6 +186,8 @@ Show the routing tables.
When
.Fl s
is also present, show routing statistics instead.
+.It Fl v
+be verbose. This currently has no effect.
.It Fl w Ar wait
Show network interface statistics at intervals of
.Ar wait
@@ -223,12 +225,13 @@ statistics regarding packets transferred, errors, and collisions.
The network addresses of the interface
and the maximum transmission unit (``mtu'') are also displayed.
.Pp
-The routing table display indicates the available routes and
-their status. Each route consists of a destination host or network
-and a gateway to use in forwarding packets. The flags field shows
-a collection of information about the route stored as
-binary choices. The individual flags are discussed in more
-detail in the
+The routing table display indicates the available routes and their
+status. Each route consists of a destination host or network and
+a gateway to use in forwarding packets. If the destination is a
+network in numeric format, the netmask (in /24 style format) is
+appended. The flags field shows a collection of information about
+the route stored as binary choices. The individual flags are
+discussed in more detail in the
.Xr route 8
and
.Xr route 4
diff --git a/usr.bin/netstat/netstat.h b/usr.bin/netstat/netstat.h
index 68ac481a183..678f3cd0af5 100644
--- a/usr.bin/netstat/netstat.h
+++ b/usr.bin/netstat/netstat.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: netstat.h,v 1.10 1997/07/23 04:38:34 denny Exp $ */
+/* $OpenBSD: netstat.h,v 1.11 1998/02/26 10:06:11 peter Exp $ */
/* $NetBSD: netstat.h,v 1.6 1996/05/07 02:55:05 thorpej Exp $ */
/*
@@ -52,6 +52,7 @@ int pflag; /* show given protocol */
int rflag; /* show routing tables (or routing stats) */
int sflag; /* show protocol statistics */
int tflag; /* show i/f watchdog timers */
+int vflag; /* be verbose */
int interval; /* repeat interval for i/f stats */
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 816d9073471..c9f4bc1ccc6 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.20 1997/07/28 18:56:03 kstailey Exp $ */
+/* $OpenBSD: route.c,v 1.21 1998/02/26 10:06:13 peter 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.20 1997/07/28 18:56:03 kstailey Exp $";
+static char *rcsid = "$OpenBSD: route.c,v 1.21 1998/02/26 10:06:13 peter Exp $";
#endif
#endif /* not lint */
@@ -121,7 +121,7 @@ static void p_tree __P((struct radix_node *));
static void p_rtnode __P(());
static void ntreestuff __P(());
static void np_rtentry __P((struct rt_msghdr *));
-static void p_sockaddr __P((struct sockaddr *, int, int));
+static void p_sockaddr __P((struct sockaddr *, struct sockaddr *, int, int));
static void p_flags __P((int, char *));
static void p_rtentry __P((struct rtentry *));
static void encap_print __P((struct rtentry *));
@@ -274,7 +274,7 @@ again:
p_rtnode();
} else {
p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_key),
- 0, 44);
+ 0, 0, 44);
putchar('\n');
}
if ((rn = rnode.rn_dupedkey))
@@ -301,7 +301,7 @@ p_rtnode()
if (rnode.rn_mask) {
printf("\t mask ");
p_sockaddr(kgetsa((struct sockaddr *)rnode.rn_mask),
- 0, -1);
+ 0, 0, -1);
} else if (rm == 0)
return;
} else {
@@ -314,7 +314,7 @@ p_rtnode()
sprintf(nbuf, " %d refs, ", rmask.rm_refs);
printf(" mk = %16p {(%d),%s",
rm, -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " ");
- p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), 0, -1);
+ p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), 0, 0, -1);
putchar('}');
if ((rm = rmask.rm_mklist))
printf(" ->");
@@ -385,21 +385,21 @@ np_rtentry(rtm)
old_af = af;
}
if (rtm->rtm_addrs == RTA_DST)
- p_sockaddr(sa, 0, 36);
+ p_sockaddr(sa, 0, 0, 36);
else {
- p_sockaddr(sa, rtm->rtm_flags, 16);
+ p_sockaddr(sa, 0, rtm->rtm_flags, 16);
if (sa->sa_len == 0)
sa->sa_len = sizeof(in_addr_t);
sa = (struct sockaddr *)(sa->sa_len + (char *)sa);
- p_sockaddr(sa, 0, 18);
+ p_sockaddr(sa, 0, 0, 18);
}
p_flags(rtm->rtm_flags & interesting, "%-6.6s ");
putchar('\n');
}
static void
-p_sockaddr(sa, flags, width)
- struct sockaddr *sa;
+p_sockaddr(sa, mask, flags, width)
+ struct sockaddr *sa, *mask;
int flags, width;
{
char workbuf[128], *cplim;
@@ -409,11 +409,13 @@ p_sockaddr(sa, flags, width)
case AF_INET:
{
register struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+ register struct sockaddr_in *msin = (struct sockaddr_in *)mask;
cp = (sin->sin_addr.s_addr == 0) ? "default" :
((flags & RTF_HOST) ?
routename(sin->sin_addr.s_addr) :
- netname(sin->sin_addr.s_addr, INADDR_ANY));
+ netname(sin->sin_addr.s_addr, msin->sin_addr.s_addr));
+
break;
}
@@ -510,17 +512,23 @@ p_rtentry(rt)
register struct rtentry *rt;
{
static struct ifnet ifnet, *lastif;
- struct sockaddr *sa;
-
- sa = kgetsa(rt_key(rt));
+ struct sockaddr sock1, sock2;
+ struct sockaddr *sa = &sock1, *mask = &sock2;
+ bcopy(kgetsa(rt_key(rt)), sa, sizeof(struct sockaddr));
+
if (sa->sa_family == AF_ENCAP) {
encap_print(rt);
return;
}
+
+ if (rt_mask(rt))
+ bcopy(kgetsa(rt_mask(rt)), mask, sizeof(struct sockaddr));
+ else
+ mask = 0;
- p_sockaddr(sa, rt->rt_flags, WID_DST);
- p_sockaddr(kgetsa(rt->rt_gateway), RTF_HOST, WID_GW);
+ p_sockaddr(sa, mask, rt->rt_flags, WID_DST);
+ p_sockaddr(kgetsa(rt->rt_gateway), 0, RTF_HOST, WID_GW);
p_flags(rt->rt_flags, "%-6.6s ");
printf("%6d %8ld ", rt->rt_refcnt, rt->rt_use);
if (rt->rt_rmx.rmx_mtu)
@@ -590,51 +598,26 @@ netname(in, mask)
static char line[MAXHOSTNAMELEN + 1];
struct netent *np = 0;
in_addr_t net, subnetshift;
+ int mbits;
in = ntohl(in);
mask = ntohl(mask);
if (!nflag && in != INADDR_ANY) {
- np = getnetbyaddr(in, AF_INET);
- if (np == NULL) {
- if (mask == INADDR_ANY) {
- if (IN_CLASSA(in)) {
- mask = IN_CLASSA_NET;
- subnetshift = 8;
- } else if (IN_CLASSB(in)) {
- mask = IN_CLASSB_NET;
- subnetshift = 8;
- } else {
- mask = IN_CLASSC_NET;
- subnetshift = 4;
- }
- /*
- * If there are more bits than the standard mask
- * would suggest, subnets must be in use.
- * Guess at the subnet mask, assuming reasonable
- * width subnet fields.
- */
- while (in &~ mask)
- mask = (int)mask >> subnetshift;
- }
- net = in & mask;
- while ((mask & 1) == 0)
- mask >>= 1, net >>= 1;
- np = getnetbyaddr(net, AF_INET);
- }
- if (np)
+ if (np = getnetbyaddr(in, AF_INET))
cp = np->n_name;
}
+ mbits = mask ? 33 - ffs(mask) : 0;
if (cp)
strncpy(line, cp, sizeof(line) - 1);
else if ((in & 0xffffff) == 0)
- sprintf(line, "%u", C(in >> 24));
+ sprintf(line, "%u/%d", C(in >> 24), mbits);
else if ((in & 0xffff) == 0)
- sprintf(line, "%u.%u", C(in >> 24) , C(in >> 16));
+ sprintf(line, "%u.%u/%d", C(in >> 24) , C(in >> 16), mbits);
else if ((in & 0xff) == 0)
- sprintf(line, "%u.%u.%u", C(in >> 24), C(in >> 16), C(in >> 8));
+ sprintf(line, "%u.%u.%u/%d", C(in >> 24), C(in >> 16), C(in >> 8), mbits);
else
- sprintf(line, "%u.%u.%u.%u", C(in >> 24),
- C(in >> 16), C(in >> 8), C(in));
+ sprintf(line, "%u.%u.%u.%u/%d", C(in >> 24),
+ C(in >> 16), C(in >> 8), C(in), mbits);
return (line);
}