misc/183598: netstat and wrong display of humanized packets counter

Olivier Cochard-Labbé olivier at cochard.me
Sun Nov 3 04:20:01 UTC 2013


The following reply was made to PR misc/183598; it has been noted by GNATS.

From: =?ISO-8859-1?Q?Olivier_Cochard=2DLabb=E9?= <olivier at cochard.me>
To: bug-followup at freebsd.org, olivier at cochard.me
Cc:  
Subject: Re: misc/183598: netstat and wrong display of humanized packets counter
Date: Sun, 3 Nov 2013 05:16:35 +0100

 --047d7b5d45d0e19a1004ea3e1120
 Content-Type: multipart/alternative; boundary=047d7b5d45d0e19a0104ea3e111e
 
 --047d7b5d45d0e19a0104ea3e111e
 Content-Type: text/plain; charset=ISO-8859-1
 
 Here is a proposed patch:
 - Byte counters use default 1024 divisor
 - non-byte counters (packet, errors, drop, collisions, etc...) use 1000
 divisor
 
 New counters are more "human", here is an example with the old and new
 netstat:
 
 root at orange# netstat -ihw 1
             input        (Total)           output
    packets  errs idrops      bytes    packets  errs      bytes colls
       956K     0     0        86M       956K     0        86M     0
       975K     0     0        88M       975K     0        88M     0
       938K     0     0        84M       938K     0        84M     0
       961K     0     0        86M       961K     0        86M     0
       984K     0     0        88M       984K     0        88M     0
       970K     0     0        87M       970K     0        87M     0
       941K     0     0        85M       941K     0        85M     0
 ^C
 root at orange#
 /usr/obj/usr/local/BSDRP/BSDRP/FreeBSD/src/usr.bin/netstat/netstat -ihw 1
 
             input        (Total)           output
    packets  errs idrops      bytes    packets  errs      bytes colls
       1.0M     0     0        89M       1.0M     0        89M     0
       953k     0     0        84M       953k     0        84M     0
       986k     0     0        86M       986k     0        86M     0
       991k     0     0        87M       991k     0        87M     0
       994k     0     0        87M       994k     0        87M     0
       976k     0     0        86M       976k     0        86M     0
 ^C
 
 Regards,
 
 Olivier
 
 --047d7b5d45d0e19a0104ea3e111e
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: base64
 
 PGRpdiBkaXI9Imx0ciI+SGVyZSBpcyBhIHByb3Bvc2VkIHBhdGNoOjxicj4tIEJ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oCCgIKAgoDg2TSCgIKAgMDxi
 cj4NCg0KXkM8YnI+PGJyPlJlZ2FyZHMsPGJyPjxicj5PbGl2aWVyPC9kaXY+DQo=
 --047d7b5d45d0e19a0104ea3e111e--
 --047d7b5d45d0e19a1004ea3e1120
 Content-Type: text/plain; charset=US-ASCII; name="netstat.patch.txt"
 Content-Disposition: attachment; filename="netstat.patch.txt"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_hnjrll3g0
 
 SW5kZXg6IHVzci5iaW4vbmV0c3RhdC9pZi5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIHVzci5iaW4vbmV0c3Rh
 dC9pZi5jCShyZXZpc2lvbiAyNTc1MDQpCisrKyB1c3IuYmluL25ldHN0YXQvaWYuYwkod29ya2lu
 ZyBjb3B5KQpAQCAtMTYwLDcgKzE2MCw3IEBACiAgKiBEaXNwbGF5IGEgZm9ybWF0dGVkIHZhbHVl
 LCBvciBhICctJyBpbiB0aGUgc2FtZSBzcGFjZS4KICAqLwogc3RhdGljIHZvaWQKLXNob3dfc3Rh
 dChjb25zdCBjaGFyICpmbXQsIGludCB3aWR0aCwgdV9sb25nIHZhbHVlLCBzaG9ydCBzaG93dmFs
 dWUpCitzaG93X3N0YXQoY29uc3QgY2hhciAqZm10LCBpbnQgd2lkdGgsIHVfbG9uZyB2YWx1ZSwg
 c2hvcnQgc2hvd3ZhbHVlLCBzaG9ydCBub3RieXRlKQogewogCWNvbnN0IGNoYXIgKmxzZXAsICpy
 c2VwOwogCWNoYXIgbmV3Zm10WzMyXTsKQEAgLTE4Niw4ICsxODYsMTQgQEAKIAkJY2hhciBidWZb
 NV07CiAKIAkJLyogRm9ybWF0IGluIGh1bWFuIHJlYWRhYmxlIGZvcm0uICovCi0JCWh1bWFuaXpl
 X251bWJlcihidWYsIHNpemVvZihidWYpLCAoaW50NjRfdCl2YWx1ZSwgIiIsCi0JCSAgIC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