Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/netstat query the window size and use it instead of ...



details:   https://anonhg.NetBSD.org/src/rev/c9f075392374
branches:  trunk
changeset: 340617:c9f075392374
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Sep 20 00:30:04 2015 +0000

description:
query the window size and use it instead of assuming 24 lines.
now the header isn't re-printed a lot of times in tall windows.

diffstat:

 usr.bin/netstat/if.c |  34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diffs (101 lines):

diff -r f59dfef6175a -r c9f075392374 usr.bin/netstat/if.c
--- a/usr.bin/netstat/if.c      Sat Sep 19 23:00:44 2015 +0000
+++ b/usr.bin/netstat/if.c      Sun Sep 20 00:30:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.81 2015/01/07 22:43:01 christos Exp $ */
+/*     $NetBSD: if.c,v 1.82 2015/09/20 00:30:04 mrg Exp $      */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
 #else
-__RCSID("$NetBSD: if.c,v 1.81 2015/01/07 22:43:01 christos Exp $");
+__RCSID("$NetBSD: if.c,v 1.82 2015/09/20 00:30:04 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -44,6 +44,7 @@
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/sysctl.h>
+#include <sys/ioctl.h>
 
 #include <net/if.h>
 #include <net/if_dl.h>
@@ -82,6 +83,7 @@
        int ift_dr;                     /* drops */
 };
 
+static void set_lines(void);
 static void print_addr(struct sockaddr *, struct sockaddr **, struct if_data *,
     struct ifnet *);
 static void sidewaysintpr(u_int, u_long);
@@ -100,6 +102,22 @@
 struct iftot iftot[MAXIF], ip_cur, ip_old, sum_cur, sum_old;
 bool   signalled;                      /* set if alarm goes off "early" */
 
+static unsigned redraw_lines = 21;
+
+static void
+set_lines(void)
+{
+       static bool first = true;
+       struct ttysize ts;
+
+       if (!first)
+               return;
+       first = false;
+       if (ioctl(STDOUT_FILENO, TIOCGSIZE, &ts) != -1 && ts.ts_lines)
+               redraw_lines = ts.ts_lines - 3;
+}
+
+
 /*
  * Print a description of the network interfaces.
  * NOTE: ifnetaddr is the location of the kernel global "ifnet",
@@ -613,7 +631,9 @@
 sidewaysintpr_sysctl(unsigned interval)
 {
        sigset_t emptyset;
-       int line;
+       unsigned line;
+
+       set_lines();
 
        fetchifs();
        if (ip_cur.ift_name[0] == '\0') {
@@ -652,7 +672,7 @@
                sigsuspend(&emptyset);
        signalled = 0;
        (void)alarm(interval);
-       if (line == 21)
+       if (line == redraw_lines)
                goto banner;
        goto loop;
        /*NOTREACHED*/
@@ -665,11 +685,13 @@
        struct ifnet ifnet;
        u_long firstifnet;
        struct iftot *ip, *total;
-       int line;
+       unsigned line;
        struct iftot *lastif, *sum, *interesting;
        struct ifnet_head ifhead;       /* TAILQ_HEAD */
        int oldmask;
 
+       set_lines();
+
        /*
         * Find the pointer to the first ifnet structure.  Replace
         * the pointer to the TAILQ_HEAD with the actual pointer
@@ -883,7 +905,7 @@
        }
        sigsetmask(oldmask);
        signalled = false;
-       if (line == 21)
+       if (line == redraw_lines)
                goto banner;
        goto loop;
        /*NOTREACHED*/



Home | Main Index | Thread Index | Old Index