]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/ss.c
Merge branch 'master' into next
[mirror_iproute2.git] / misc / ss.c
index 712242182da918d94a0bb2016f770db31c3ead65..f3d01812cb06d040e0ecdfd8fae9d8dd2872607f 100644 (file)
--- 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);