On 2015-09-02 at 01:31:16 +0200, Vadim Kochan <[email protected]> wrote:
> 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(" ]");
> +}
This could be done a bit easier, using less variables and more straight
forward to read:
static void presenter_print_flow_entry_time(struct flow_entry *n)
{
int h, m, s;
time_t now;
time(&now);
s = now - (n->timestamp_start / NSEC_PER_SEC);
if (s <= 0)
return;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
printw(" [ time");
if (h > 0)
printw(" %dh", h);
if (m > 0)
printw(" %dm", m);
if (s > 0)
printw(" %ds", s);
printw(" ]");
}
I applied the patch with this version instead.
--
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.