Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Apr 2010 06:50:18 GMT
From:      Dmitry Banshchikov <me@ubique.spb.ru>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/145934: [patch] add count option to netstat
Message-ID:  <201004220650.o3M6oI5A027519@www.freebsd.org>
Resent-Message-ID: <201004220700.o3M70Cdb068846@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         145934
>Category:       bin
>Synopsis:       [patch] add count option to netstat
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 22 07:00:12 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Dmitry Banshchikov
>Release:        FreeBSD 8.0-RELEASE
>Organization:
>Environment:
>Description:
Allows user to specify -c for netstat, to repeat display output in case of -w option(Similar to -c option of iostat utility)

Example usage:
#./netstat -w2 -c3
            input        (Total)           output
   packets  errs      bytes    packets  errs      bytes colls
        20     0       1830          5     0        334     0
         9     0       3037          9     0       1246     0
        14     0       1268          7     0        658     0
#


>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- if.c	2009-10-25 04:10:29.000000000 +0300
+++ if.c	2010-04-21 11:32:15.000000000 +0400
@@ -676,6 +676,10 @@
 	if (!first)
 		putchar('\n');
 	fflush(stdout);
+	if (cflag)
+		count--;
+	if (count < 0 && cflag)
+		exit(0);
 	oldmask = sigblock(sigmask(SIGALRM));
 	while (!signalled)
 		sigpause(0);
--- main.c	2009-10-25 04:10:29.000000000 +0300
+++ main.c	2010-04-22 10:30:57.000000000 +0400
@@ -322,6 +322,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;		/* repeat display */
 int	dflag;		/* show i/f dropped packets */
 int	gflag;		/* show group (multicast) routing or stats */
 int	hflag;		/* show counters in human readable format */
@@ -339,6 +340,7 @@
 int	zflag;		/* zero stats */
 
 int	interval;	/* repeat interval for i/f stats */
+int	count;		/* repeat display output */
 
 char	*interface;	/* desired i/f for stats, or NULL for all i/fs */
 int	unit;		/* unit number for above */
@@ -354,7 +356,7 @@
 
 	af = AF_UNSPEC;
 
-	while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:rSstuWw:xz")) != -1)
+	while ((ch = getopt(argc, argv, "AaBbc:df:ghI:iLlM:mN:np:rSstuWw:xz")) != -1)
 		switch(ch) {
 		case 'A':
 			Aflag = 1;
@@ -368,6 +370,10 @@
 		case 'b':
 			bflag = 1;
 			break;
+		case 'c':
+			cflag = 1;
+			count = atoi(optarg);
+			break;
 		case 'd':
 			dflag = 1;
 			break;
--- netstat.1	2009-10-25 04:10:29.000000000 +0300
+++ netstat.1	2010-04-22 10:27:40.000000000 +0400
@@ -132,6 +132,7 @@
 .Bk -words
 .Nm
 .Fl w Ar wait
+.Op Fl c Ar count
 .Op Fl I Ar interface
 .Op Fl d
 .Op Fl M Ar core
@@ -141,7 +142,9 @@
 At intervals of
 .Ar wait
 seconds,
-display the information regarding packet
+display
+.Ar count
+times the information regarding packet
 traffic on all configured network interfaces
 or a single
 .Ar interface .
--- netstat.h	2009-10-25 04:10:29.000000000 +0300
+++ netstat.h	2010-04-22 10:29:12.000000000 +0400
@@ -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;	/* repeat display output */
 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 */
@@ -55,6 +56,7 @@
 extern int	zflag;	/* zero stats */
 
 extern int	interval; /* repeat interval for i/f stats */
+extern int	count;	  /* repeat display output */
 
 extern char	*interface; /* desired i/f for stats, or NULL for all i/fs */
 extern int	unit;	/* unit number for above */


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004220650.o3M6oI5A027519>