Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/netstat Add -h, which makes output of bytes counts "...
details: https://anonhg.NetBSD.org/src/rev/785431fd2ecc
branches: trunk
changeset: 752357:785431fd2ecc
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Feb 24 11:00:27 2010 +0000
description:
Add -h, which makes output of bytes counts "humanized" (e.g. -bih)
(netstat had -h some 15 years ago, but since then it has been just
a fancy way of calling usage())
diffstat:
usr.bin/netstat/if.c | 72 +++++++++++++++++++++++++++++++++++++---------
usr.bin/netstat/main.c | 7 +++-
usr.bin/netstat/netstat.1 | 14 +++++++-
usr.bin/netstat/netstat.h | 3 +-
4 files changed, 75 insertions(+), 21 deletions(-)
diffs (201 lines):
diff -r bf269e834bc9 -r 785431fd2ecc usr.bin/netstat/if.c
--- a/usr.bin/netstat/if.c Wed Feb 24 10:18:19 2010 +0000
+++ b/usr.bin/netstat/if.c Wed Feb 24 11:00:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if.c,v 1.67 2009/09/27 18:19:18 plunky Exp $ */
+/* $NetBSD: if.c,v 1.68 2010/02/24 11:00:27 pooka 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.67 2009/09/27 18:19:18 plunky Exp $");
+__RCSID("$NetBSD: if.c,v 1.68 2010/02/24 11:00:27 pooka Exp $");
#endif
#endif /* not lint */
@@ -68,6 +68,8 @@
#define MAXIF 100
+#define HUMBUF_SIZE 7
+
struct iftot {
char ift_name[IFNAMSIZ]; /* interface name */
u_quad_t ift_ip; /* input packets */
@@ -523,9 +525,19 @@
}
if (bflag) {
- printf("%10llu %10llu",
- (unsigned long long)ifd->ifi_ibytes,
- (unsigned long long)ifd->ifi_obytes);
+ char humbuf[HUMBUF_SIZE];
+
+ if (hflag && humanize_number(humbuf, sizeof(humbuf),
+ ifd->ifi_ibytes, "", HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
+ printf("%10s ", humbuf);
+ else
+ printf("%10llu ", (unsigned long long)ifd->ifi_ibytes);
+
+ if (hflag && humanize_number(humbuf, sizeof(humbuf),
+ ifd->ifi_obytes, "", HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
+ printf("%10s", humbuf);
+ else
+ printf("%10llu", (unsigned long long)ifd->ifi_obytes);
} else {
printf("%8llu %5llu %8llu %5llu %5llu",
(unsigned long long)ifd->ifi_ipackets,
@@ -793,11 +805,27 @@
}
if (ip == interesting) {
if (bflag) {
- printf("%10llu %8.8s %10llu %5.5s",
- (unsigned long long)(ifnet.if_ibytes -
- ip->ift_ib), " ",
- (unsigned long long)(ifnet.if_obytes -
- ip->ift_ob), " ");
+ char humbuf[HUMBUF_SIZE];
+
+ if (hflag && humanize_number(humbuf,
+ sizeof(humbuf),
+ ifnet.if_ibytes - ip->ift_ib, "",
+ HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
+ printf("%10s %8.8s ", humbuf, " ");
+ else
+ printf("%10llu %8.8s ",
+ (unsigned long long)
+ (ifnet.if_ibytes-ip->ift_ib), " ");
+
+ if (hflag && humanize_number(humbuf,
+ sizeof(humbuf),
+ ifnet.if_obytes - ip->ift_ob, "",
+ HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
+ printf("%10s %5.5s", humbuf, " ");
+ else
+ printf("%10llu %5.5s",
+ (unsigned long long)
+ (ifnet.if_obytes-ip->ift_ob), " ");
} else {
printf("%8llu %5llu %8llu %5llu %5llu",
(unsigned long long)
@@ -836,11 +864,25 @@
}
if (lastif - iftot > 0) {
if (bflag) {
- printf(" %10llu %8.8s %10llu %5.5s",
- (unsigned long long)
- (sum->ift_ib - total->ift_ib), " ",
- (unsigned long long)
- (sum->ift_ob - total->ift_ob), " ");
+ char humbuf[HUMBUF_SIZE];
+
+ if (hflag && humanize_number(humbuf,
+ sizeof(humbuf), sum->ift_ib - total->ift_ib, "",
+ HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
+ printf("%10s %8.8s ", humbuf, " ");
+ else
+ printf("%10llu %8.8s ",
+ (unsigned long long)
+ (sum->ift_ib - total->ift_ib), " ");
+
+ if (hflag && humanize_number(humbuf,
+ sizeof(humbuf), sum->ift_ob - total->ift_ob, "",
+ HN_AUTOSCALE, HN_NOSPACE | HN_B) > 0)
+ printf("%10s %5.5s", humbuf, " ");
+ else
+ printf("%10llu %5.5s",
+ (unsigned long long)
+ (sum->ift_ob - total->ift_ob), " ");
} else {
printf(" %8llu %5llu %8llu %5llu %5llu",
(unsigned long long)
diff -r bf269e834bc9 -r 785431fd2ecc usr.bin/netstat/main.c
--- a/usr.bin/netstat/main.c Wed Feb 24 10:18:19 2010 +0000
+++ b/usr.bin/netstat/main.c Wed Feb 24 11:00:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.73 2009/09/14 10:36:51 degroote Exp $ */
+/* $NetBSD: main.c,v 1.74 2010/02/24 11:00:27 pooka Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "from: @(#)main.c 8.4 (Berkeley) 3/1/94";
#else
-__RCSID("$NetBSD: main.c,v 1.73 2009/09/14 10:36:51 degroote Exp $");
+__RCSID("$NetBSD: main.c,v 1.74 2010/02/24 11:00:27 pooka Exp $");
#endif
#endif /* not lint */
@@ -471,6 +471,9 @@
gflag = 1;
break;
#endif
+ case 'h':
+ hflag = 1;
+ break;
case 'I':
iflag = 1;
interface = optarg;
diff -r bf269e834bc9 -r 785431fd2ecc usr.bin/netstat/netstat.1
--- a/usr.bin/netstat/netstat.1 Wed Feb 24 10:18:19 2010 +0000
+++ b/usr.bin/netstat/netstat.1 Wed Feb 24 11:00:27 2010 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: netstat.1,v 1.54 2009/09/13 09:17:26 wiz Exp $
+.\" $NetBSD: netstat.1,v 1.55 2010/02/24 11:00:27 pooka Exp $
.\"
.\" Copyright (c) 1983, 1990, 1992, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)netstat.1 8.8 (Berkeley) 4/18/94
.\"
-.Dd September 12, 2009
+.Dd February 24, 2009
.Dt NETSTAT 1
.Os
.Sh NAME
@@ -42,7 +42,7 @@
.Op Fl M Ar core
.Op Fl N Ar system
.Nm
-.Op Fl bdgiLmnqrSsv
+.Op Fl bdghiLmnqrSsv
.Op Fl f Ar address_family
.Op Fl M Ar core
.Op Fl N Ar system
@@ -181,6 +181,14 @@
or
.Ar protocol ,
respectively.
+.It Fl h
+When used with
+.Fl b
+in combination with either
+.Fl i
+or
+.Fl I ,
+output "human-readable" byte counts.
.It Fl i
Show the state of interfaces which have been auto-configured
(interfaces statically configured into a system, but not
diff -r bf269e834bc9 -r 785431fd2ecc usr.bin/netstat/netstat.h
--- a/usr.bin/netstat/netstat.h Wed Feb 24 10:18:19 2010 +0000
+++ b/usr.bin/netstat/netstat.h Wed Feb 24 11:00:27 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netstat.h,v 1.39 2009/09/14 10:36:51 degroote Exp $ */
+/* $NetBSD: netstat.h,v 1.40 2010/02/24 11:00:27 pooka Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -41,6 +41,7 @@
#ifndef SMALL
int gflag; /* show group (multicast) routing or stats */
#endif
+int hflag; /* humanize byte counts */
int iflag; /* show interfaces */
int Lflag; /* don't show LLINFO entries */
int lflag; /* show routing table with use and ref */
Home |
Main Index |
Thread Index |
Old Index