Re: [2.1.113] NIC stats are mis-displayed

Tomasz Przygoda (Tomasz.Przygoda@securities.com)
Tue, 04 Aug 1998 00:49:45 -0400


Steve Snyder wrote:

> The output of ifconfig is inaccurate when used with the v2.1.113 kernel. As you
> can see below, the number of transmitted packets is displayed as the number of
> transmission errors. (The number of "dropped" packets is a little suspicious
> too.)

The number of errors is actually number of bytes, and then the number of dropped is
actually the number of packets :). There's shift in the /proc/net/dev and the below
fixes it. If you happen to have sources of ifconfig(net-tools?) (I made this patch
against net-tools-1.432) then you can recompile it and it will work with both 2.0
and 2.1.

--- net-tools/ifconfig.c.orig Tue Sep 23 16:05:24 1997
+++ net-tools/ifconfig.c Tue Aug 4 00:48:33 1998
@@ -100,6 +100,9 @@
unsigned long tx_fifo_errors;
unsigned long tx_heartbeat_errors;
unsigned long tx_window_errors;
+ /* for cslip etc */
+ unsigned long rx_compressed;
+ unsigned long tx_compressed;
};

struct interface {
@@ -387,12 +390,16 @@
FILE *f = fopen(_PATH_PROCNET_DEV, "r");
char buf[256];
int have_byte_counters = 0;
+ int have_multicast = 0;
+ int have_compression = 0;
char *bp;
if (f==NULL)
return;
fgets(buf, 255, f); /* throw away first line of header */
fgets(buf, 255, f);
if (strstr(buf, "bytes")) have_byte_counters=1;
+ if (strstr(buf, "multicast")) have_multicast=1;
+ if (strstr(buf, "compressed")) have_compression=1;
while(fgets(buf,255,f)) {
bp=buf;
while(*bp&&isspace(*bp))
@@ -400,43 +407,62 @@
if(strncmp(bp,ifname,strlen(ifname))==0 && bp[strlen(ifname)]==':') {
bp=strchr(bp,':');
bp++;
+ while(*bp&&isspace(*bp)) bp++;
if (have_byte_counters) {
- sscanf(bp,"%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
- &ife->stats.rx_bytes,
- &ife->stats.rx_packets,
- &ife->stats.rx_errors,
- &ife->stats.rx_dropped,
- &ife->stats.rx_fifo_errors,
- &ife->stats.rx_frame_errors,
-
- &ife->stats.tx_bytes,
- &ife->stats.tx_packets,
- &ife->stats.tx_errors,
- &ife->stats.tx_dropped,
- &ife->stats.tx_fifo_errors,
- &ife->stats.collisions,
-
- &ife->stats.tx_carrier_errors
- );
- } else {
- sscanf(bp,"%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld",
- &ife->stats.rx_packets,
- &ife->stats.rx_errors,
- &ife->stats.rx_dropped,
- &ife->stats.rx_fifo_errors,
- &ife->stats.rx_frame_errors,
-
- &ife->stats.tx_packets,
- &ife->stats.tx_errors,
- &ife->stats.tx_dropped,
- &ife->stats.tx_fifo_errors,
- &ife->stats.collisions,
-
- &ife->stats.tx_carrier_errors
- );
- ife->stats.rx_bytes = 0;
- ife->stats.tx_bytes = 0;
+ sscanf(bp,"%ld", &ife->stats.rx_bytes);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
}
+ sscanf(bp,"%ld", &ife->stats.rx_packets);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.rx_errors);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.rx_dropped);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.rx_fifo_errors);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.rx_frame_errors);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ if (have_compression) {
+ sscanf(bp,"%ld", &ife->stats.rx_compressed);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ }
+ if (have_multicast) {
+ sscanf(bp,"%ld", &ife->stats.multicast);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ }
+ if (have_byte_counters) {
+ sscanf(bp,"%ld", &ife->stats.tx_bytes);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ }
+ sscanf(bp,"%ld", &ife->stats.tx_packets);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.tx_errors);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.tx_dropped);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.tx_fifo_errors);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.collisions);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ sscanf(bp,"%ld", &ife->stats.tx_carrier_errors);
+ bp=strchr(bp,' ');
+ while(*bp&&isspace(*bp)) bp++;
+ if (have_compression)
+ sscanf(bp,"%ld", &ife->stats.tx_compressed);
break;
}
}

-- Tomek,
"Linux, WinNT and MS-DOS - the Good, the Bad and the Ugly"

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html