From nobody@FreeBSD.org  Thu Apr 22 06:50:19 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 484A7106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 22 Apr 2010 06:50:19 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 3606E8FC22
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 22 Apr 2010 06:50:19 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o3M6oIFi027520
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 22 Apr 2010 06:50:18 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o3M6oI5A027519;
	Thu, 22 Apr 2010 06:50:18 GMT
	(envelope-from nobody)
Message-Id: <201004220650.o3M6oI5A027519@www.freebsd.org>
Date: Thu, 22 Apr 2010 06:50:18 GMT
From: Dmitry Banshchikov <me@ubique.spb.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] add count option to netstat
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         145934
>Category:       bin
>Synopsis:       [patch] add count option to netstat(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 22 07:00:12 UTC 2010
>Closed-Date:    Thu Jan 26 13:57:07 UTC 2012
>Last-Modified:  Thu Jan 26 13:57:07 UTC 2012
>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:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Tue Aug 10 07:32:12 UTC 2010 
Responsible-Changed-Why:  
Over to freebsd-net.  The patch attached has been tested by 
Sterling "Chip" Camden <sterling camdensoftware.com> , but I'm not 
sure if this extra functionality is worth usin one of the remaining 
command line options on - although as the submitter says, it would bring 
it in line with several other base system utilities. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145934 

From: Dmitry Banschikov <me@ubique.spb.ru>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/145934: [patch] add count option to netstat(1)
Date: Thu, 26 Jan 2012 16:09:45 +0300

 --001636ed74f71f7ceb04b76e18c4
 Content-Type: text/plain; charset=ISO-8859-1
 
 It seems, that this PR can be closed, as r202060 introduced similiar
 changes.
 
 -- 
 
 Dmitry Banshchikov
 
 --001636ed74f71f7ceb04b76e18c4
 Content-Type: text/html; charset=ISO-8859-1
 
 It seems, that this PR can be closed, as r202060 introduced similiar changes.<br clear="all"><br>-- <br><br>Dmitry Banshchikov<br>
 
 --001636ed74f71f7ceb04b76e18c4--
State-Changed-From-To: open->closed 
State-Changed-By: pluknet 
State-Changed-When: Thu Jan 26 13:54:57 UTC 2012 
State-Changed-Why:  
Close per submitter request. 
Similar functionality is available since 8.1 using the -q option. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=145934 
>Unformatted:
