From owner-freebsd-bugs@FreeBSD.ORG Thu Apr 22 07:00:14 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2C598106567D for ; Thu, 22 Apr 2010 07:00:14 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B0A608FC0A for ; Thu, 22 Apr 2010 07:00:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o3M70CK7068847 for ; Thu, 22 Apr 2010 07:00:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o3M70Cdb068846; Thu, 22 Apr 2010 07:00:12 GMT (envelope-from gnats) Resent-Date: Thu, 22 Apr 2010 07:00:12 GMT Resent-Message-Id: <201004220700.o3M70Cdb068846@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dmitry Banshchikov Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 484A7106564A for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/145934: [patch] add count option to netstat X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2010 07:00:14 -0000 >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: