Add an -h flag to print human numbers. Easier for me to read. Index: Makefile =================================================================== RCS file: /cvs/src/usr.bin/netstat/Makefile,v retrieving revision 1.20 diff -u -p -r1.20 Makefile --- Makefile 9 Jul 2011 00:45:40 -0000 1.20 +++ Makefile 9 Aug 2012 06:15:38 -0000 @@ -5,7 +5,7 @@ SRCS= if.c inet.c inet6.c main.c mbuf.c unix.c mroute6.c net80211.c show.c BINGRP= kmem BINMODE=2555 -LDADD= -lkvm +LDADD= -lkvm -lutil DPADD= ${LIBKVM} .include <bsd.prog.mk> Index: if.c =================================================================== RCS file: /cvs/src/usr.bin/netstat/if.c,v retrieving revision 1.64 diff -u -p -r1.64 if.c --- if.c 9 Jul 2011 00:45:40 -0000 1.64 +++ if.c 9 Aug 2012 06:24:57 -0000 @@ -53,6 +53,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <util.h> #include "netstat.h" @@ -311,10 +312,17 @@ hexprint: putchar(' '); break; } - if (bflag) - printf("%10llu %10llu", - ifd->ifi_ibytes, ifd->ifi_obytes); - else + if (bflag) { + if (hflag) { + char ibytes[FMT_SCALED_STRSIZE]; + char obytes[FMT_SCALED_STRSIZE]; + fmt_scaled(ifd->ifi_ibytes, ibytes); + fmt_scaled(ifd->ifi_obytes, obytes); + printf("%10s %10s", ibytes, obytes); + } else + printf("x %10llu %10llu", + ifd->ifi_ibytes, ifd->ifi_obytes); + } else printf("%8llu %5llu %8llu %5llu %5llu", ifd->ifi_ipackets, ifd->ifi_ierrors, ifd->ifi_opackets, ifd->ifi_oerrors, @@ -351,6 +359,8 @@ sidewaysintpr(unsigned int interval, int { sigset_t emptyset; int line; + char ibytes[FMT_SCALED_STRSIZE]; + char obytes[FMT_SCALED_STRSIZE]; fetchifs(); if (ip_cur.ift_name[0] == '\0') { @@ -393,7 +403,7 @@ banner: printf(" %5.5s", "drops"); if (bflag) - printf(" %10.10s %8.8s %10.10s %5.5s", + printf("%10.10s %8.8s %10.10s %5.5s", "bytes", " ", "bytes", " "); else printf(" %8.8s %5.5s %8.8s %5.5s %5.5s", @@ -410,11 +420,17 @@ loop: fetchifs(); - if (bflag) - printf("%10llu %8.8s %10llu %5.5s", - ip_cur.ift_ib - ip_old.ift_ib, " ", - ip_cur.ift_ob - ip_old.ift_ob, " "); - else + if (bflag) { + if (hflag) { + fmt_scaled(ip_cur.ift_ib - ip_old.ift_ib, ibytes); + fmt_scaled(ip_cur.ift_ob - ip_old.ift_ob, obytes); + printf("%10s %8.8s %10s %5.5s", + ibytes, " ", obytes, " "); + } else + printf("%10llu %8.8s %10llu %5.5s", + ip_cur.ift_ib - ip_old.ift_ib, " ", + ip_cur.ift_ob - ip_old.ift_ob, " "); + } else printf("%8llu %5llu %8llu %5llu %5llu", ip_cur.ift_ip - ip_old.ift_ip, ip_cur.ift_ie - ip_old.ift_ie, @@ -428,11 +444,17 @@ loop: ip_old = ip_cur; - if (bflag) - printf(" %10llu %8.8s %10llu %5.5s", - sum_cur.ift_ib - sum_old.ift_ib, " ", - sum_cur.ift_ob - sum_old.ift_ob, " "); - else + if (bflag) { + if (hflag) { + fmt_scaled(sum_cur.ift_ib - sum_old.ift_ib, ibytes); + fmt_scaled(sum_cur.ift_ob - sum_old.ift_ob, obytes); + printf(" %10s %8.8s %10s %5.5s", + ibytes, " ", obytes, " "); + } else + printf(" %10llu %8.8s %10llu %5.5s", + sum_cur.ift_ib - sum_old.ift_ib, " ", + sum_cur.ift_ob - sum_old.ift_ob, " "); + } else printf(" %8llu %5llu %8llu %5llu %5llu", sum_cur.ift_ip - sum_old.ift_ip, sum_cur.ift_ie - sum_old.ift_ie, Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/netstat/main.c,v retrieving revision 1.92 diff -u -p -r1.92 main.c --- main.c 1 Nov 2011 17:30:04 -0000 1.92 +++ main.c 9 Aug 2012 06:14:23 -0000 @@ -166,7 +166,7 @@ main(int argc, char *argv[]) tableid = getrtable(); while ((ch = getopt(argc, argv, - "AaBbc:dFf:gI:ilM:mN:np:P:qrsT:tuvW:w:")) != -1) + "AaBbc:dFf:ghI:ilM:mN:np:P:qrsT:tuvW:w:")) != -1) switch (ch) { case 'A': Aflag = 1; @@ -215,6 +215,9 @@ main(int argc, char *argv[]) break; case 'g': gflag = 1; + break; + case 'h': + hflag = 1; break; case 'I': iflag = 1; Index: netstat.h =================================================================== RCS file: /cvs/src/usr.bin/netstat/netstat.h,v retrieving revision 1.62 diff -u -p -r1.62 netstat.h --- netstat.h 1 Nov 2011 17:30:04 -0000 1.62 +++ netstat.h 9 Aug 2012 06:14:50 -0000 @@ -44,6 +44,7 @@ int bflag; /* show bytes instead of pac int dflag; /* show i/f dropped packets */ int Fflag; /* show routes whose gateways are in specified AF */ int gflag; /* show group (multicast) routing or stats */ +int hflag; /* print human numbers */ int iflag; /* show interfaces */ int lflag; /* show routing table with use and ref */ int mflag; /* show memory stats */