Date: Thu, 01 Mar 2007 00:44:38 +0800 From: LI Xin <delphij@delphij.net> To: LI Xin <delphij@delphij.net> Cc: freebsd-net@freebsd.org Subject: Re: [PATCH] Feature request: exit netstat(1) after user specified outputs Message-ID: <45E5B176.1010303@delphij.net> In-Reply-To: <45D85A88.4040402@delphij.net> References: <45D85A88.4040402@delphij.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45E5B176.1010303>