(feature change request) remove link-layer generated
routes from netstat -r
Giorgos Keramidas
keramida at ceid.upatras.gr
Fri Feb 24 05:01:20 PST 2006
On 2006-02-24 11:32, Nikos Vassiliadis <nvass at teledomenet.gr> wrote:
>On Thursday 23 February 2006 20:24, Giorgos Keramidas wrote:
>>
>> ... about using a switch to shorten the netstat output (by not
>> displaying the link-layer entries):
>>
>> How about making the new behavior non-default, i.e. toggled by a -s
>> switch to the netstat -r command?
>>
>> % netstat -rs
>>
>> Then 's' can stand for 'short' output, and everyone can experiment with
>> the new feature. Then, after a couple of minor releases, if we find
>> that this is a feature that is very often used, we can make it the
>> default.
>
> That would be a well balanced compromise. I can live with it.
Unfortunately, the -s option is taken already. It enables the display
of statistics. A possible alternative is the -c (compact) option,
i.e. with a patch similar to the following:
%%%
Index: main.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.81
diff -u -r1.81 main.c
--- main.c 28 Dec 2005 20:36:55 -0000 1.81
+++ main.c 24 Feb 2006 12:54:39 -0000
@@ -286,6 +286,7 @@
int aflag; /* show all sockets (including servers) */
int Bflag; /* show information about bpf consumers */
int bflag; /* show i/f total bytes in/out */
+int cflag; /* show compact output format */
int dflag; /* show i/f dropped packets */
int gflag; /* show group (multicast) routing or stats */
int hflag; /* show counters in human readable format */
@@ -316,7 +317,7 @@
af = AF_UNSPEC;
- while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:rSstuWw:z")) != -1)
+ while ((ch = getopt(argc, argv, "AaBbcdf:ghI:iLlM:mN:np:rSstuWw:z")) != -1)
switch(ch) {
case 'A':
Aflag = 1;
@@ -330,6 +331,9 @@
case 'b':
bflag = 1;
break;
+ case 'c':
+ cflag = 1;
+ break;
case 'd':
dflag = 1;
break;
Index: netstat.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/netstat.1,v
retrieving revision 1.56
diff -u -r1.56 netstat.1
--- netstat.1 18 Dec 2005 19:38:43 -0000 1.56
+++ netstat.1 24 Feb 2006 12:59:34 -0000
@@ -32,7 +32,7 @@
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\" $FreeBSD: src/usr.bin/netstat/netstat.1,v 1.56 2005/12/18 19:38:43 csjp Exp $
.\"
-.Dd September 7, 2005
+.Dd February 24, 2006
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -209,7 +209,7 @@
.Bk -words
.Nm
.Fl r
-.Op Fl AanW
+.Op Fl AacnW
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
@@ -231,6 +231,13 @@
.Dv RTF_PRCLONING
parent route);
normally these routes are not shown.
+If
+.Fl c
+is also present,
+hide routes that were generated by link-layer events (i.e. by ARP),
+resulting in a more
+.Dq compact
+output format.
When
.Fl W
is also present,
Index: netstat.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.47
diff -u -r1.47 netstat.h
--- netstat.h 28 Dec 2005 20:36:55 -0000 1.47
+++ netstat.h 24 Feb 2006 12:55:35 -0000
@@ -39,6 +39,7 @@
extern int Aflag; /* show addresses of protocol control block */
extern int aflag; /* show all sockets (including servers) */
extern int bflag; /* show i/f total bytes in/out */
+extern int cflag; /* show compact output format */
extern int dflag; /* show i/f dropped packets */
extern int gflag; /* show group (multicast) routing or stats */
extern int hflag; /* show counters in human readable format */
Index: route.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/netstat/route.c,v
retrieving revision 1.76
diff -u -r1.76 route.c
--- route.c 13 May 2005 16:31:10 -0000 1.76
+++ route.c 24 Feb 2006 12:54:29 -0000
@@ -720,6 +720,13 @@
return;
}
+ /*
+ * Skip routes that were generated by link-layer (i.e. ARP) if we are
+ * in `compact output' mode.
+ */
+ if (rt->rt_flags & RTF_LLINFO && cflag)
+ return;
+
bzero(&addr, sizeof(addr));
if ((sa = kgetsa(rt_key(rt))))
bcopy(sa, &addr, sa->sa_len);
%%%
More information about the freebsd-hackers
mailing list