From: Vadim Kochan <[email protected]>

Show human readable time since flow was created by Linux

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

diff --git a/flowtop.c b/flowtop.c
index d988590..d073715 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -41,6 +41,10 @@
 #include "proc.h"
 #include "sysctl.h"
 
+#ifndef NSEC_PER_SEC
+#define NSEC_PER_SEC 1000000000L
+#endif
+
 struct flow_entry {
        uint32_t flow_id, use, status;
        uint8_t  l3_proto, l4_proto;
@@ -750,6 +754,37 @@ static void presenter_print_counters(uint64_t bytes, 
uint64_t pkts, int color)
        printw(")");
 }
 
+static void presenter_print_flow_entry_time(struct flow_entry *n)
+{
+       int secs = n->timestamp_start / NSEC_PER_SEC;
+       int mns_sub, sec_sub;
+       int mns, hrs;
+       time_t now;
+
+       time(&now);
+       sec_sub = secs = now - secs;
+
+       if (secs <= 0)
+               return;
+
+       mns_sub = mns = secs / 60;
+       hrs = secs / 3600;
+
+       if (secs > 60)
+               sec_sub = secs - mns * 60;
+       if (mns > 60)
+               mns_sub = mns - hrs * 60;
+
+       printw(" [ time");
+       if (hrs > 0)
+               printw(" %dh", hrs);
+       if (mns_sub > 0)
+               printw(" %dm", mns_sub);
+       if (sec_sub > 0)
+               printw(" %ds", sec_sub);
+       printw(" ]");
+}
+
 static void presenter_screen_do_line(WINDOW *screen, struct flow_entry *n,
                                     unsigned int *line)
 {
@@ -812,6 +847,9 @@ static void presenter_screen_do_line(WINDOW *screen, struct 
flow_entry *n,
                attroff(A_BOLD);
        }
 
+       if (n->timestamp_start > 0)
+               presenter_print_flow_entry_time(n);
+
        /* Show source information: reverse DNS, port, country, city, counters 
*/
        if (show_src) {
                attron(COLOR_PAIR(1));
-- 
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