part1 (the whole diff): add a repeat count, -c, like vmstat has.  A lot of 
change for a little tweak.

part2 (hidden in there): Don't repeat the banner if it's not a terminal.  
Same justification as for prevous vmstat diff.


Index: if.c
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/netstat/if.c,v
retrieving revision 1.61
diff -u -r1.61 if.c
--- if.c        4 Aug 2009 03:45:47 -0000       1.61
+++ if.c        16 Nov 2009 01:21:18 -0000
@@ -56,7 +56,7 @@
 #include "netstat.h"
 
 static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data 
*);
-static void sidewaysintpr(u_int);
+static void sidewaysintpr(u_int, int);
 static void catchalarm(int);
 static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
 static void fetchifs(void);
@@ -67,7 +67,7 @@
  * which is a TAILQ_HEAD.
  */
 void
-intpr(int interval)
+intpr(int interval, int repeatcount)
 {
        struct if_msghdr ifm;
        int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
@@ -82,7 +82,7 @@
        size_t len;
 
        if (interval) {
-               sidewaysintpr((unsigned)interval);
+               sidewaysintpr((unsigned)interval, repeatcount);
                return;
        }
 
@@ -350,7 +350,7 @@
  * First line printed at top of screen is always cumulative.
  */
 static void
-sidewaysintpr(unsigned int interval)
+sidewaysintpr(unsigned int interval, int repeatcount)
 {
        sigset_t emptyset;
        int line;
@@ -449,16 +449,17 @@
 
        putchar('\n');
        fflush(stdout);
+       if (repeatcount && --repeatcount == 0)
+               return;
        line++;
        sigemptyset(&emptyset);
        if (!signalled)
                sigsuspend(&emptyset);
        signalled = 0;
        (void)alarm(interval);
-       if (line == 21)
+       if (line == 21 && isatty(STDOUT_FILENO))
                goto banner;
        goto loop;
-       /*NOTREACHED*/
 }
 
 /*
Index: main.c
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.80
diff -u -r1.80 main.c
--- main.c      4 Oct 2009 16:08:37 -0000       1.80
+++ main.c      30 Oct 2009 22:11:45 -0000
@@ -158,10 +158,11 @@
        gid_t gid;
        u_long pcbaddr = 0;
        u_int tableid = 0;
+       int repeatcount = 0;
 
        af = AF_UNSPEC;
 
-       while ((ch = getopt(argc, argv, "AabdFf:gI:ilM:mN:np:P:qrsT:tuvW:w:")) 
!= -1)
+       while ((ch = getopt(argc, argv, 
"Aabc:dFf:gI:ilM:mN:np:P:qrsT:tuvW:w:")) != -1)
                switch (ch) {
                case 'A':
                        Aflag = 1;
@@ -172,6 +173,9 @@
                case 'b':
                        bflag = 1;
                        break;
+               case 'c':
+                       repeatcount = strtonum(optarg, 1, INT_MAX, &errstr);
+                       break;
                case 'd':
                        dflag = 1;
                        break;
@@ -372,7 +376,7 @@
        setnetent(1);
 
        if (iflag) {
-               intpr(interval);
+               intpr(interval, repeatcount);
                exit(0);
        }
        if (rflag) {
Index: netstat.h
===================================================================
RCS file: /home/tedu/cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.51
diff -u -r1.51 netstat.h
--- netstat.h   4 Oct 2009 16:08:37 -0000       1.51
+++ netstat.h   30 Oct 2009 22:11:45 -0000
@@ -130,7 +130,7 @@
 
 void   nsprotopr(u_long, char *);
 
-void   intpr(int);
+void   intpr(int, int);
 
 void   unixpr(u_long);

Reply via email to