summaryrefslogtreecommitdiff
path: root/misc/ss.c
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2020-05-27 02:08:27 +0000
committerDavid Ahern <dsahern@gmail.com>2020-05-27 02:08:27 +0000
commite50290e6871fd77da62380a782e7d4c4120efd9f (patch)
treeb010285315bada248ff58f8d85e3748f304072bb /misc/ss.c
parent9a25abde3aa67844d3c77a7e6b68ccf8d99def43 (diff)
parentdb35e411ec17bf9da67f22f995fe1e8d5edcda98 (diff)
downloadiproute2-e50290e6871fd77da62380a782e7d4c4120efd9f.tar.gz
Merge branch 'master' into next
Signed-off-by: David Ahern <dsahern@gmail.com>
Diffstat (limited to 'misc/ss.c')
-rw-r--r--misc/ss.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/misc/ss.c b/misc/ss.c
index 71224218..f3d01812 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2410,14 +2410,23 @@ static int proc_inet_split_line(char *line, char **loc, char **rem, char **data)
return 0;
}
+/*
+ * Display bandwidth in standard units
+ * See: https://en.wikipedia.org/wiki/Data-rate_units
+ * bw is in bits per second
+ */
static char *sprint_bw(char *buf, double bw)
{
if (numeric)
sprintf(buf, "%.0f", bw);
- else if (bw > 1000000.)
- sprintf(buf, "%.1fM", bw / 1000000.);
- else if (bw > 1000.)
- sprintf(buf, "%.1fK", bw / 1000.);
+ else if (bw >= 1e12)
+ sprintf(buf, "%.3gT", bw / 1e12);
+ else if (bw >= 1e9)
+ sprintf(buf, "%.3gG", bw / 1e9);
+ else if (bw >= 1e6)
+ sprintf(buf, "%.3gM", bw / 1e6);
+ else if (bw >= 1e3)
+ sprintf(buf, "%.3gk", bw / 1e3);
else
sprintf(buf, "%g", bw);