From: Vadim Kochan <[email protected]>

Print flow bytes amount in human readable format units (G,M,K).

Signed-off-by: Vadim Kochan <[email protected]>
---
 flowtop.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/flowtop.c b/flowtop.c
index 866a062..79e7a7b 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -749,6 +749,20 @@ static uint16_t presenter_get_port(uint16_t src, uint16_t 
dst, int tcp)
        }
 }
 
+char *bandw2str(double bytes, char *buf, int len)
+{
+       if (bytes > 1000000000.)
+               snprintf(buf, len, "%.1fG", bytes / 1000000000.);
+       if (bytes > 1000000.)
+               snprintf(buf, len, "%.1fM", bytes / 1000000.);
+       else if (bytes > 1000.)
+               snprintf(buf, len, "%.1fK", bytes / 1000.);
+       else
+               snprintf(buf, len, "%g", bytes);
+
+       return buf;
+}
+
 static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n,
                                     unsigned int *line)
 {
@@ -813,9 +827,13 @@ static void presenter_screen_do_line(WINDOW *screen, 
struct flow_entry *n,
        printw(" ->");
 
        /* Number packets, bytes */
-       if (n->counter_pkts > 0 && n->counter_bytes > 0)
-               printw(" (%"PRIu64" pkts, %"PRIu64" bytes) ->",
-                      n->counter_pkts, n->counter_bytes);
+       if (n->counter_pkts > 0 && n->counter_bytes > 0) {
+               char bytes_str[64];
+
+               printw(" (%"PRIu64" pkts, %s bytes) ->",
+                      n->counter_pkts, bandw2str(n->counter_bytes, bytes_str,
+                              array_size(bytes_str) - 1));
+       }
 
        /* Show source information: reverse DNS, port, country, city */
        if (show_src) {
-- 
2.4.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to