From owner-freebsd-net@FreeBSD.ORG Sun Feb 18 13:54:32 2007 Return-Path: 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 C450616A401 for ; Sun, 18 Feb 2007 13:54:32 +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 2AB8C13C428 for ; Sun, 18 Feb 2007 13:54:32 +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 F138CEB4B59; Sun, 18 Feb 2007 21:54:30 +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 UqE3SrPSRfcr; Sun, 18 Feb 2007 21:54:23 +0800 (CST) Received: from [192.168.1.32] (unknown [61.49.185.129]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by tarsier.geekcn.org (Postfix) with ESMTP id AE3ACEB4939; Sun, 18 Feb 2007 21:54:23 +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: subject:x-enigmail-version:content-type; b=REJ740gXuuax0Ujdc07maPC9Z3m7xtC82vKFwA1UR+yMIQHDxp0ImxJV4YiGoW7b6 fh2mPEjkBrLSNrohCjvVw== Message-ID: <45D85A88.4040402@delphij.net> Date: Sun, 18 Feb 2007 21:54:16 +0800 From: LI Xin Organization: The FreeBSD Project User-Agent: Thunderbird 1.5.0.9 (Macintosh/20061207) MIME-Version: 1.0 To: freebsd-net@freebsd.org X-Enigmail-Version: 0.94.1.0 Content-Type: multipart/signed; micalg=pgp-ripemd160; protocol="application/pgp-signature"; boundary="------------enig1579E7B082DB1FE636B8A914" Subject: [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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Feb 2007 13:54:32 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig1579E7B082DB1FE636B8A914 Content-Type: multipart/mixed; boundary="------------090407050304000506020605" This is a multi-part message in MIME format. --------------090407050304000506020605 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi, This is a patch that I have backported to -CURRENT, which is originally made against RELENG_6_2. 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 monitoring scripts. So here is the patchset that adds a '-q' option, which accepts a numerical argument meaning how many outputs are going out before we exit.= Comments? (I think 'q' is arguable, but netstat(1) has too many options = :-) Cheers, --=20 Xin LI http://www.delphij.net/ FreeBSD - The Power to Serve! --------------090407050304000506020605 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="patch-netstat" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="patch-netstat" 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 */ --------------090407050304000506020605-- --------------enig1579E7B082DB1FE636B8A914 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 iD8DBQFF2FqIOfuToMruuMARA7PNAJ91skYOhGG/ogn9vUbZ3jtXZCatZgCdFWAi hiBKc/YafSMUMyepEfdNQUA= =1oWX -----END PGP SIGNATURE----- --------------enig1579E7B082DB1FE636B8A914--