From owner-freebsd-net@FreeBSD.ORG Wed Feb 28 16:45:01 2007 Return-Path: <owner-freebsd-net@FreeBSD.ORG> X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CDA2516A404 for <freebsd-net@freebsd.org>; Wed, 28 Feb 2007 16:45:01 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from tarsier.geekcn.org (tarsier.geekcn.org [210.51.165.229]) by mx1.freebsd.org (Postfix) with ESMTP id 17A2E13C491 for <freebsd-net@freebsd.org>; Wed, 28 Feb 2007 16:44:58 +0000 (UTC) (envelope-from delphij@delphij.net) Received: from localhost (tarsier.geekcn.org [210.51.165.229]) by tarsier.geekcn.org (Postfix) with ESMTP id 13B7AEB70F6; Thu, 1 Mar 2007 00:44:58 +0800 (CST) X-Virus-Scanned: amavisd-new at geekcn.org Received: from tarsier.geekcn.org ([210.51.165.229]) by localhost (mail.geekcn.org [210.51.165.229]) (amavisd-new, port 10024) with ESMTP id 0A56Bgs5fBXk; Thu, 1 Mar 2007 00:44:47 +0800 (CST) Received: from [192.168.1.32] (unknown [221.219.159.7]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTP id BC54FEB3534; Thu, 1 Mar 2007 00:44:46 +0800 (CST) DomainKey-Signature: a=rsa-sha1; s=default; d=delphij.net; c=nofws; q=dns; h=message-id:date:from:organization:user-agent:mime-version:to:cc: subject:references:in-reply-to:x-enigmail-version:content-type; b=E61vSF1s6DpLUzqOWuAoq4Ng2roSPDfK4DekUCWll6fU95ZEl/BcMro9hHR+GgcnT k/K69dwhVa4djMgIbLTKQ== Message-ID: <45E5B176.1010303@delphij.net> Date: Thu, 01 Mar 2007 00:44:38 +0800 From: LI Xin <delphij@delphij.net> Organization: The FreeBSD Project User-Agent: Thunderbird 1.5.0.9 (Macintosh/20061207) MIME-Version: 1.0 To: LI Xin <delphij@delphij.net> References: <45D85A88.4040402@delphij.net> In-Reply-To: <45D85A88.4040402@delphij.net> X-Enigmail-Version: 0.94.1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig9FF510FAE24CDAF5DB54513C" Cc: freebsd-net@freebsd.org Subject: Re: [PATCH] Feature request: exit netstat(1) after user specified outputs X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD <freebsd-net.freebsd.org> List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-net>, <mailto:freebsd-net-request@freebsd.org?subject=unsubscribe> List-Archive: <http://lists.freebsd.org/pipermail/freebsd-net> List-Post: <mailto:freebsd-net@freebsd.org> List-Help: <mailto:freebsd-net-request@freebsd.org?subject=help> List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-net>, <mailto:freebsd-net-request@freebsd.org?subject=subscribe> X-List-Received-Date: Wed, 28 Feb 2007 16:45:01 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9FF510FAE24CDAF5DB54513C Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, If no one objects this change, I will commit it? LI Xin wrote: > Hi, >=20 > This is a patch that I have backported to -CURRENT, which is originally= > made against RELENG_6_2. >=20 > I have received several feature requests from our local community which= > they wanted to have a top(1)'s '-d' alike feature for netstat, so they > will be able to use netstat(1) as a handy brick when building monitorin= g > scripts. >=20 > So here is the patchset that adds a '-q' option, which accepts a > numerical argument meaning how many outputs are going out before we exi= t. >=20 > Comments? (I think 'q' is arguable, but netstat(1) has too many option= s :-) >=20 > Cheers, >=20 >=20 > -----------------------------------------------------------------------= - >=20 > Index: if.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /home/ncvs/src/usr.bin/netstat/if.c,v > retrieving revision 1.66 > diff -u -p -r1.66 if.c > --- if.c 8 Nov 2006 15:15:05 -0000 1.66 > +++ if.c 18 Feb 2007 13:37:32 -0000 > @@ -676,6 +676,8 @@ loop: > (void)alarm(interval1); > line++; > first =3D 0; > + if (qflag && (qval-- =3D=3D 0)) > + exit(0); > if (line =3D=3D 21) > goto banner; > else > Index: main.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /home/ncvs/src/usr.bin/netstat/main.c,v > retrieving revision 1.83 > diff -u -p -r1.83 main.c > --- main.c 28 Jul 2006 16:16:40 -0000 1.83 > +++ main.c 18 Feb 2007 13:29:11 -0000 > @@ -295,6 +295,8 @@ int mflag; /* show memory stats */ > int numeric_addr; /* show addresses numerically */ > int numeric_port; /* show ports numerically */ > static int pflag; /* show given protocol */ > +int qflag; /* whether to quit after specified outputs */ > +int qval; /* how much outputs before we exit */ > int rflag; /* show routing tables (or routing stats) */ > int sflag; /* show protocol statistics */ > int tflag; /* show i/f watchdog timers */ > @@ -316,7 +318,7 @@ main(int argc, char *argv[]) > =20 > af =3D AF_UNSPEC; > =20 > - while ((ch =3D getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:rSstuWw:z"))= !=3D -1) > + while ((ch =3D getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:q:rSstuWw:z"= )) !=3D -1) > switch(ch) { > case 'A': > Aflag =3D 1; > @@ -400,6 +402,10 @@ main(int argc, char *argv[]) > } > pflag =3D 1; > break; > + case 'q': > + qval =3D atoi(optarg); > + qflag =3D 1; > + break; > case 'r': > rflag =3D 1; > break; > Index: netstat.1 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /home/ncvs/src/usr.bin/netstat/netstat.1,v > retrieving revision 1.57 > diff -u -p -r1.57 netstat.1 > --- netstat.1 29 Sep 2006 15:20:46 -0000 1.57 > +++ netstat.1 18 Feb 2007 13:40:17 -0000 > @@ -130,6 +130,7 @@ is also present, print interface names u > .Nm > .Fl w Ar wait > .Op Fl I Ar interface > +.Op Fl q Ar howmany > .Op Fl d > .Op Fl M Ar core > .Op Fl N Ar system > @@ -143,6 +144,11 @@ traffic on all configured network interf > or a single > .Ar interface . > If > +.Fl q > +is also present, exit after > +.Ar howmany > +outputs. > +If > .Fl d > is also present, show the number of dropped packets. > .It Xo > Index: netstat.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /home/ncvs/src/usr.bin/netstat/netstat.h,v > retrieving revision 1.48 > diff -u -p -r1.48 netstat.h > --- netstat.h 28 Jul 2006 16:09:18 -0000 1.48 > +++ netstat.h 18 Feb 2007 13:19:41 -0000 > @@ -47,6 +47,8 @@ extern int Lflag; /* show size of listen > extern int mflag; /* show memory stats */ > extern int numeric_addr; /* show addresses numerically */ > extern int numeric_port; /* show ports numerically */ > +extern int qflag; /* whether to quit after specified outputs */ > +extern int qval; /* how much outputs before we exit */ > extern int rflag; /* show routing tables (or routing stats) */ > extern int sflag; /* show protocol statistics */ > extern int tflag; /* show i/f watchdog timers */ Cheers, --=20 Xin LI <delphij@delphij.net> http://www.delphij.net/ FreeBSD - The Power to Serve! --------------enig9FF510FAE24CDAF5DB54513C Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFF5bF2OfuToMruuMARCnxeAJ9o/+p1LfdVwNhVfLzzzk8dl86ChgCeOLd9 dYK8PsvqREy3xq/ttMCM94s= =FSzP -----END PGP SIGNATURE----- --------------enig9FF510FAE24CDAF5DB54513C--