Subject: bin/24541: ifconfig MB count
To: None <gnats-bugs@gnats.NetBSD.org>
From: M.Negovanovic <milosn@xtra.co.nz>
List: netbsd-bugs
Date: 02/24/2004 14:43:40
>Number:         24541
>Category:       bin
>Synopsis:       adds MB(megabyte) count to ifconfig
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 24 01:44:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     M.Negovanovic
>Release:        NetBSD 1.6ZJ
>Organization:
>Environment:
System: NetBSD tp 1.6ZJ NetBSD 1.6ZJ (Insomnia) #0: Thu Feb 12 22:13:18 NZDT 2004 milosn@tp:/home/milosn/projects/c/netbsd_src/src/sys/arch/i386/compile/Insomnia i386
Architecture: i386
Machine: i386
>Description:
	This patch adds printing of the MB count to ifconfig stats printout. Also it
	makes ifconfig display stats by default('ifconfig -a' and 'ifconfig <iface>'
	display stats with this patch). The -v flag is not needed any more.
>How-To-Repeat:
>Fix:

diff -ru /usr/src/sbin/ifconfig/ifconfig.8 /home/milosn/projects/c/netbsd_src/src/sbin/ifconfig/ifconfig.8
--- /usr/src/sbin/ifconfig/ifconfig.8	2003-08-08 15:11:49.000000000 +1200
+++ /home/milosn/projects/c/netbsd_src/src/sbin/ifconfig/ifconfig.8	2004-02-24 10:51:18.000000000 +1300
@@ -44,12 +44,12 @@
 .Oc
 .Op Ar parameters
 .Nm
-.Op Fl Lmvz
+.Op Fl Lmz
 .Ar interface
 .Op Ar protocol_family
 .Nm
 .Fl a
-.Op Fl bdLmsuvz
+.Op Fl bdLmsuz
 .Op Ar protocol_family
 .Nm
 .Fl l
@@ -598,15 +598,8 @@
 mutually exclusive with all other flags and commands.
 .Pp
 The
-.Fl v
-flag prints statistics on packets sent and received on the given
-interface.
-The
 .Fl z
-flag is identical to the
-.Fl v
-flag except that it zeros the interface input and output statistics
-after printing them. 
+flag zeros the interface input and output statistics.
 .Pp
 Only the super-user may modify the configuration of a network interface.
 .Sh DIAGNOSTICS
diff -ru /usr/src/sbin/ifconfig/ifconfig.c /home/milosn/projects/c/netbsd_src/src/sbin/ifconfig/ifconfig.c
--- /usr/src/sbin/ifconfig/ifconfig.c	2004-02-24 10:42:17.000000000 +1300
+++ /home/milosn/projects/c/netbsd_src/src/sbin/ifconfig/ifconfig.c	2004-02-24 14:01:16.000000000 +1300
@@ -143,7 +143,7 @@
 int	conflicting = 0;
 int	nsellength = 1;
 int	af;
-int	aflag, bflag, Cflag, dflag, lflag, mflag, sflag, uflag, vflag, zflag;
+int	aflag, bflag, Cflag, dflag, lflag, mflag, sflag, uflag, zflag;
 #ifdef INET6
 int	Lflag;
 #endif
@@ -420,7 +420,7 @@
 	int ch;
 
 	/* Parse command-line options */
-	aflag = mflag = vflag = zflag = 0;
+	aflag = mflag = zflag = 0;
 	while ((ch = getopt(argc, argv, "AabCdlmsuvz"
 #ifdef INET6
 					"L"
@@ -469,10 +469,6 @@
 			uflag = 1;
 			break;
 
-		case 'v':
-			vflag = 1;
-			break;
-
 		case 'z':
 			zflag = 1;
 			break;
@@ -495,7 +491,7 @@
 	 *
 	 * -a means "print status of all interfaces".
 	 */
-	if ((lflag || Cflag) && (aflag || mflag || vflag || argc || zflag))
+	if ((lflag || Cflag) && (aflag || mflag || argc || zflag))
 		usage();
 #ifdef INET6
 	if ((lflag || Cflag) && Lflag)
@@ -2061,6 +2057,7 @@
 	struct afswtch *p = afp;
 	struct ifmediareq ifmr;
 	struct ifdatareq ifdr;
+	lldiv_t mb_calc;
 	int *media_list, i;
 	char hbuf[NI_MAXHOST];
 	char fbuf[BUFSIZ];
@@ -2178,9 +2175,6 @@
 	free(media_list);
 
  iface_stats:
-	if (!vflag && !zflag)
-		goto proto_status;
-
 	(void) strncpy(ifdr.ifdr_name, name, sizeof(ifdr.ifdr_name));
 
 	if (ioctl(s, zflag ? SIOCZIFDATA:SIOCGIFDATA, (caddr_t)&ifdr) == -1) {
@@ -2188,11 +2182,13 @@
 	} else {
 		struct if_data * const ifi = &ifdr.ifdr_data;
 #define	PLURAL(n)	((n) == 1 ? "" : "s")
-		printf("\tinput: %llu packet%s, %llu byte%s",
+		mb_calc = lldiv((long long)ifi->ifi_ibytes, 1024*1024);
+		printf("\tin: %llu packet%s, %llu byte%s (%lld MB)",
 		    (unsigned long long) ifi->ifi_ipackets,
 		    PLURAL(ifi->ifi_ipackets),
 		    (unsigned long long) ifi->ifi_ibytes,
-		    PLURAL(ifi->ifi_ibytes));
+		    PLURAL(ifi->ifi_ibytes),
+		    mb_calc.quot);
 		if (ifi->ifi_imcasts)
 			printf(", %llu multicast%s",
 			    (unsigned long long) ifi->ifi_imcasts,
@@ -2208,11 +2204,13 @@
 		if (ifi->ifi_noproto)
 			printf(", %llu unknown protocol",
 			    (unsigned long long) ifi->ifi_noproto);
-		printf("\n\toutput: %llu packet%s, %llu byte%s",
+		mb_calc = lldiv((long long)ifi->ifi_obytes, 1024*1024);
+		printf("\n\tout: %llu packet%s, %llu byte%s (%lld MB)",
 		    (unsigned long long) ifi->ifi_opackets,
 		    PLURAL(ifi->ifi_opackets),
 		    (unsigned long long) ifi->ifi_obytes,
-		    PLURAL(ifi->ifi_obytes));
+		    PLURAL(ifi->ifi_obytes),
+		    mb_calc.quot);
 		if (ifi->ifi_omcasts)
 			printf(", %llu multicast%s",
 			    (unsigned long long) ifi->ifi_omcasts,
@@ -2228,8 +2226,7 @@
 		printf("\n");
 #undef PLURAL
 	}
-
- proto_status:
+	
 	if ((p = afp) != NULL) {
 		(*p->af_status)(1);
 	} else for (p = afs; p->af_name; p++) {
@@ -3045,7 +3042,7 @@
 	const char *progname = getprogname();
 
 	fprintf(stderr,
-	    "usage: %s [-m] [-v] [-z] "
+	    "usage: %s [-m] [-z] "
 #ifdef INET6
 		"[-L] "
 #endif
@@ -3063,7 +3060,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] [-m] [-d] [-u] [-z] [ af ]\n"
 		"       %s -l [-b] [-d] [-u] [-s]\n"
 		"       %s -C\n"
 		"       %s interface create\n"

>Release-Note:
>Audit-Trail:
>Unformatted: