Page MenuHomeFreeBSD

netstat -i: compute most field widths dynamically
ClosedPublic

Authored by karels on Jul 24 2023, 2:13 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 5, 3:45 PM
Unknown Object (File)
Oct 16 2024, 9:57 AM
Unknown Object (File)
Oct 15 2024, 5:40 PM
Unknown Object (File)
Oct 12 2024, 3:33 AM
Unknown Object (File)
Oct 10 2024, 8:19 PM
Unknown Object (File)
Oct 10 2024, 3:04 AM
Unknown Object (File)
Oct 9 2024, 11:09 AM
Unknown Object (File)
Oct 8 2024, 9:10 AM
Subscribers

Details

Summary

The network and address fields were sometimes truncated for netstat -i
without -W, and often much too wide for netstat -i with the -W option.
Fields such as normal packet counts often overflowed. As a result,
columns didn't line up, and large white spaces made it harder to
follow a line across the display. Change the code to compute the
required field sizes for network, address, and various packet counts.
Hoist the code to format network and address into a subroutine that
can be called twice, once to measure the required field widths,
and once to emit the values. Use separate field widths for input
and output packets, byte counts, and error and drop counters.
These are left at defaults (the preceding values) with the -h
option, in which case the fields have a limited total width.
Change the mention of -W with -i in the man page to say that most
field widths are computed dynamically in this case.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Great improvement, thanks! I think the calculation gives too much whitespace sometimes (to my opinion). Not sure, maybe this is intented. Example:

Name    Mtu Network                   Address                                                Ipkts Ierrs Idrop           Opkts Oerrs  Coll
ixl0*  1500 <Link#1>                  ac:1f:6b:4d:99:be                                          0     0     0               0     0     0
ixl1*  1500 <Link#2>                  ac:1f:6b:4d:99:bf                                          0     0     0               0     0     0
lo0   16384 <Link#3>                  lo0                                               9411449303     0     0      9411449303     0     0
lo0       - localhost                 localhost                                                  0     -     -             417     -     -
lo0       - fe80::%lo0/64             fe80::1%lo0                                                0     -     -               0     -     -
lo0       - your-net                  localhost                                          123619322     -     -       123654586     -     -
lo0       - 127.0.0.2/32              localhost                                         9199596183     -     -      9287794717     -     -
lo0       - 127.0.90.1/32             localhost                                                  0     -     -               0     -     -
cc0    1500 <Link#4>                  00:07:43:49:da:10                               169233845329     0     0   1090416006182     0     0
cc0       - xx.xxx.xx.128/25          ipv4-xxxx-xxxxxx-dev-ix.1.oca.nflxvideo.net        363625537     -     -    629202541532     -     -
cc0       - fe80::%cc0/64             fe80::207:43ff:fe49:da10%cc0                             152     -     -             152     -     -
cc0       - xxxx:xxxx:xxxx:xxxx::/64  ipv6-xxxx-xxxxxx-dev-ix.1.oca.nflxvideo.net        313230771     -     -     27276647768     -     -
cc1*   1500 <Link#5>                  00:07:43:49:da:18                                          0     0     0               0     0     0
cc2*   1500 <Link#6>                  00:07:43:4a:7a:70                                          0     0     0               0     0     0
cc3*   1500 <Link#7>                  00:07:43:4a:7a:78                                          0     0     0               0     0     0
ipfw0     - <Link#8>                  ipfw0                                                      0     0     0               0     0     0

IMHO, there should be less than 5 spaces between longest Address and longest Ipkts.

This revision is now accepted and ready to land.Jul 25 2023, 11:49 PM

IMHO, there should be less than 5 spaces between longest Address and longest Ipkts.

I agree. I'm not sure why it would be more than 2 (space-padded on the right for Address and the left for Ipkts). I see 4 on one of my servers. I'll look into it tomorrow.

Fix general off-by-one error; field widths included a space, but
the space is output separately. Fix an off-by-one with most numeric
fields, double-counting the last digit unless it was 0. Leave space
in count of numeric fields, or they seem tight.

This revision now requires review to proceed.Jul 26 2023, 1:02 PM

IMHO, there should be less than 5 spaces between longest Address and longest Ipkts.

I agree. I'm not sure why it would be more than 2 (space-padded on the right for Address and the left for Ipkts). I see 4 on one of my servers. I'll look into it tomorrow.

Fixed two off-by-one errors, and compensated for one of them (Network) by adding a space. The reason you had one more space than I did is that the output packet count is one digit longer than input.

This revision is now accepted and ready to land.Jul 26 2023, 3:52 PM