Subject: bin/33120: ifconfig -h pullup request
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <krille@users.sf.net>
List: netbsd-bugs
Date: 03/21/2006 22:50:00
>Number:         33120
>Category:       bin
>Synopsis:       ifconfig -h pullup request
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 21 22:50:00 +0000 2006
>Originator:     Christian Hattemer
>Release:        3.0
>Organization:
>Environment:
NetBSD webster 3.0_STABLE NetBSD 3.0_STABLE (WEBSTER-TMP) #0: Tue Mar 21 21:03:33 CET 2006  krille@webster:/usr/src/sys/arch/i386/compile/WEBSTER-TMP i386
>Description:
Please pull up
http://mail-index.netbsd.org/source-changes/2005/08/11/0013.html
and
http://mail-index.netbsd.org/source-changes/2005/08/11/0014.html

It will add the "human readable" option to ifconfig. Patches that
apply cleanly to 3.0 are provided below.
>How-To-Repeat:

>Fix:
===================================================================
RCS file: /etc/cvsup/prefixes/NetBSD.cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.168
retrieving revision 1.169
diff -u -r1.168 -r1.169
--- src/sbin/ifconfig/ifconfig.c	2005/05/02 15:35:16	1.168
+++ src/sbin/ifconfig/ifconfig.c	2005/08/11 20:56:05	1.169
@@ -1,4 +1,4 @@
-/*	$NetBSD: ifconfig.c,v 1.168 2005/05/02 15:35:16 yamt Exp $	*/
+/*	$NetBSD: ifconfig.c,v 1.169 2005/08/11 20:56:05 rpaulo Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)ifconfig.c	8.2 (Berkeley) 2/16/94";
 #else
-__RCSID("$NetBSD: ifconfig.c,v 1.168 2005/05/02 15:35:16 yamt Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.169 2005/08/11 20:56:05 rpaulo Exp $");
 #endif
 #endif /* not lint */
 
@@ -135,6 +135,7 @@
 int	conflicting = 0;
 int	af;
 int	aflag, bflag, Cflag, dflag, lflag, mflag, sflag, uflag, vflag, zflag;
+int	hflag;
 #ifdef INET6
 int	Lflag;
 #endif
@@ -361,7 +362,7 @@
 
 	/* Parse command-line options */
 	aflag = mflag = vflag = zflag = 0;
-	while ((ch = getopt(argc, argv, "AabCdlmsuvz"
+	while ((ch = getopt(argc, argv, "AabCdhlmsuvz"
 #ifdef INET6
 					"L"
 #endif
@@ -386,7 +387,9 @@
 		case 'd':
 			dflag = 1;
 			break;
-
+		case 'h':
+			hflag = 1;
+			break;
 #ifdef INET6
 		case 'L':
 			Lflag = 1;
@@ -1414,12 +1417,23 @@
 		err(EXIT_FAILURE, zflag ? "SIOCZIFDATA" : "SIOCGIFDATA");
 	} else {
 		struct if_data * const ifi = &ifdr.ifdr_data;
+		char buf[5];
+
 #define	PLURAL(n)	((n) == 1 ? "" : "s")
-		printf("\tinput: %llu packet%s, %llu byte%s",
+#define PLURALSTR(s)	((atof(s)) == 1.0 ? "" : "s")
+		printf("\tinput: %llu packet%s, ", 
 		    (unsigned long long) ifi->ifi_ipackets,
-		    PLURAL(ifi->ifi_ipackets),
-		    (unsigned long long) ifi->ifi_ibytes,
-		    PLURAL(ifi->ifi_ibytes));
+		    PLURAL(ifi->ifi_ipackets));
+		if (hflag) {
+			(void) humanize_number(buf, sizeof(buf),
+			    (int64_t) ifi->ifi_ibytes, "", HN_AUTOSCALE, 
+			    HN_NOSPACE | HN_DECIMAL);
+			printf("%s byte%s", buf,
+			    PLURALSTR(buf));
+		} else
+			printf("%llu byte%s",
+			    (unsigned long long) ifi->ifi_ibytes,
+		            PLURAL(ifi->ifi_ibytes));
 		if (ifi->ifi_imcasts)
 			printf(", %llu multicast%s",
 			    (unsigned long long) ifi->ifi_imcasts,
@@ -1435,11 +1449,19 @@
 		if (ifi->ifi_noproto)
 			printf(", %llu unknown protocol",
 			    (unsigned long long) ifi->ifi_noproto);
-		printf("\n\toutput: %llu packet%s, %llu byte%s",
+		printf("\n\toutput: %llu packet%s, ",
 		    (unsigned long long) ifi->ifi_opackets,
-		    PLURAL(ifi->ifi_opackets),
-		    (unsigned long long) ifi->ifi_obytes,
-		    PLURAL(ifi->ifi_obytes));
+		    PLURAL(ifi->ifi_opackets));
+		if (hflag) {
+			(void) humanize_number(buf, sizeof(buf),
+			    (int64_t) ifi->ifi_obytes, "", HN_AUTOSCALE,
+			    HN_NOSPACE | HN_DECIMAL);
+			printf("%s byte%s", buf,
+			    PLURALSTR(buf));
+		} else
+			printf("%llu byte%s",
+			    (unsigned long long) ifi->ifi_obytes,
+			    PLURAL(ifi->ifi_obytes));
 		if (ifi->ifi_omcasts)
 			printf(", %llu multicast%s",
 			    (unsigned long long) ifi->ifi_omcasts,
@@ -1454,6 +1476,7 @@
 			    PLURAL(ifi->ifi_collisions));
 		printf("\n");
 #undef PLURAL
+#undef PLURALSTR
 	}
 
 	ieee80211_statistics();
@@ -1481,7 +1504,7 @@
 	const char *progname = getprogname();
 
 	fprintf(stderr,
-	    "usage: %s [-m] [-v] [-z] "
+	    "usage: %s [-h] [-m] [-v] [-z] "
 #ifdef INET6
 		"[-L] "
 #endif
@@ -1500,7 +1523,7 @@
 		"\t[ anycast | -anycast ] [ deprecated | -deprecated ]\n"
 		"\t[ tentative | -tentative ] [ pltime n ] [ vltime n ] [ eui64 ]\n"
 		"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
-		"       %s -a [-b] [-m] [-d] [-u] [-v] [-z] [ af ]\n"
+		"       %s -a [-b] [-h] [-m] [-d] [-u] [-v] [-z] [ af ]\n"
 		"       %s -l [-b] [-d] [-u] [-s]\n"
 		"       %s -C\n"
 		"       %s interface create\n"



===================================================================
RCS file: /etc/cvsup/prefixes/NetBSD.cvs/src/sbin/ifconfig/ifconfig.8,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- src/sbin/ifconfig/ifconfig.8	2005/05/02 15:37:06	1.78
+++ src/sbin/ifconfig/ifconfig.8	2005/08/11 20:56:57	1.79
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ifconfig.8,v 1.78 2005/05/02 15:37:06 yamt Exp $
+.\"	$NetBSD: ifconfig.8,v 1.79 2005/08/11 20:56:57 rpaulo Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)ifconfig.8	8.4 (Berkeley) 6/1/94
 .\"
-.Dd May 3, 2005
+.Dd August 11, 2005
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -44,12 +44,12 @@
 .Oc
 .Op Ar parameters
 .Nm
-.Op Fl Lmvz
+.Op Fl hLmvz
 .Ar interface
 .Op Ar protocol_family
 .Nm
 .Fl a
-.Op Fl bdLmsuvz
+.Op Fl bdhLmsuvz
 .Op Ar protocol_family
 .Nm
 .Fl l
@@ -667,6 +667,11 @@
 .Fl v
 flag prints statistics on packets sent and received on the given
 interface.
+If
+.Fl h
+is used in conjunction with
+.Fl v ,
+the byte statistics will be printed in "human-readable" format.
 The
 .Fl z
 flag is identical to the