Commit b68d9837 authored by Christian Hesse's avatar Christian Hesse Committed by Stephen Hemminger

ip-link: add switch to show human readable output

Byte and packet count can increase to really big numbers. This adds a
switch to show human readable output.

4: wl: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 00:de:ad:be:ee:ef brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    1523846973 3969051  0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    8710088361 6077735  0       0       0       0
4: wl: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 00:de:ad:be:ee:ef brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    1.5G       3.9M     0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    8.7G       6.0M     0       0       0       0
parent a0638e18
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "rtm_map.h" #include "rtm_map.h"
extern int preferred_family; extern int preferred_family;
extern int human_readable;
extern int show_stats; extern int show_stats;
extern int show_details; extern int show_details;
extern int show_raw; extern int show_raw;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ip_common.h" #include "ip_common.h"
int preferred_family = AF_UNSPEC; int preferred_family = AF_UNSPEC;
int human_readable = 0;
int show_stats = 0; int show_stats = 0;
int show_details = 0; int show_details = 0;
int resolve_hosts = 0; int resolve_hosts = 0;
...@@ -47,6 +48,7 @@ static void usage(void) ...@@ -47,6 +48,7 @@ static void usage(void)
" tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |\n" " tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |\n"
" netns | l2tp | tcp_metrics | token | netconf }\n" " netns | l2tp | tcp_metrics | token | netconf }\n"
" OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n"
" -h[uman-readable] |\n"
" -f[amily] { inet | inet6 | ipx | dnet | bridge | link } |\n" " -f[amily] { inet | inet6 | ipx | dnet | bridge | link } |\n"
" -4 | -6 | -I | -D | -B | -0 |\n" " -4 | -6 | -I | -D | -B | -0 |\n"
" -l[oops] { maximum-addr-flush-attempts } |\n" " -l[oops] { maximum-addr-flush-attempts } |\n"
...@@ -212,6 +214,9 @@ int main(int argc, char **argv) ...@@ -212,6 +214,9 @@ int main(int argc, char **argv)
preferred_family = AF_DECnet; preferred_family = AF_DECnet;
} else if (strcmp(opt, "-B") == 0) { } else if (strcmp(opt, "-B") == 0) {
preferred_family = AF_BRIDGE; preferred_family = AF_BRIDGE;
} else if (matches(opt, "-human") == 0 ||
matches(opt, "-human-readable") == 0) {
++human_readable;
} else if (matches(opt, "-stats") == 0 || } else if (matches(opt, "-stats") == 0 ||
matches(opt, "-statistics") == 0) { matches(opt, "-statistics") == 0) {
++show_stats; ++show_stats;
......
This diff is collapsed.
...@@ -16,6 +16,7 @@ ip-link \- network device configuration ...@@ -16,6 +16,7 @@ ip-link \- network device configuration
.ti -8 .ti -8
.IR OPTIONS " := { " .IR OPTIONS " := { "
\fB\-V\fR[\fIersion\fR] | \fB\-V\fR[\fIersion\fR] |
\fB\-h\fR[\fIuman-readable\fR] |
\fB\-s\fR[\fItatistics\fR] | \fB\-s\fR[\fItatistics\fR] |
\fB\-r\fR[\fIesolve\fR] | \fB\-r\fR[\fIesolve\fR] |
\fB\-f\fR[\fIamily\fR] { \fB\-f\fR[\fIamily\fR] {
...@@ -660,6 +661,12 @@ specifies what group of devices to show. ...@@ -660,6 +661,12 @@ specifies what group of devices to show.
.B up .B up
only display running interfaces. only display running interfaces.
.SH "NOTES"
Human readable values are calculated with SI prefixes, so with a decimal
base, not binary. (This is unlike
.BR ifconfig (8)
, with uses binary prefix.) 1,000 bytes are 1 kB, 1,000 kB are 1 MB, ...
.SH "EXAMPLES" .SH "EXAMPLES"
.PP .PP
ip link show ip link show
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment