From: Emil Mikulic Date: Sat, 25 Apr 2009 13:57:23 +0000 (+1000) Subject: Implement --no-lastseen X-Git-Tag: 3.0.713~16 X-Git-Url: https://unix4lyfe.org/gitweb/darkstat/commitdiff_plain/adc7c051a9fa39418caf05182e0e65cf4824c1e0 Implement --no-lastseen --- diff --git a/darkstat.8 b/darkstat.8 index 65071c2..2a7c4b4 100644 --- a/darkstat.8 +++ b/darkstat.8 @@ -28,6 +28,8 @@ darkstat \- network statistics gatherer ] [ .BI \-\-no\-macs ] [ +.BI \-\-no\-lastseen +] [ .BI \-p " port" ] [ .BI \-b " bindaddr" @@ -129,7 +131,11 @@ as an extra process is created for DNS resolving. .\" .TP .BI \-\-no\-macs -Do not display MAC addresses in hosts table. +Do not display MAC addresses in the hosts table. +.\" +.TP +.BI \-\-no\-lastseen +Do not display the last seen time in the hosts table. .\" .TP .BI \-p " port" diff --git a/darkstat.c b/darkstat.c index e974d52..14f4568 100644 --- a/darkstat.c +++ b/darkstat.c @@ -86,6 +86,9 @@ static void cb_no_dns(const char *arg _unused_) { want_dns = 0; } int want_macs = 1; static void cb_no_macs(const char *arg _unused_) { want_macs = 0; } +int want_lastseen = 1; +static void cb_no_lastseen(const char *arg _unused_) { want_lastseen = 0; } + unsigned short bindport = 667; static void cb_port(const char *arg) { bindport = parsenum(arg, 65536); } @@ -188,6 +191,7 @@ static struct cmdline_arg cmdline_args[] = { {"--no-promisc", NULL, cb_no_promisc, 0}, {"--no-dns", NULL, cb_no_dns, 0}, {"--no-macs", NULL, cb_no_macs, 0}, + {"--no-lastseen", NULL, cb_no_lastseen, 0}, {"-p", "port", cb_port, 0}, {"-b", "bindaddr", cb_bindaddr, 0}, {"-f", "filter", cb_filter, 0}, diff --git a/hosts_db.c b/hosts_db.c index 9b8e15c..afa85ea 100644 --- a/hosts_db.c +++ b/hosts_db.c @@ -1,5 +1,5 @@ /* darkstat 3 - * copyright (c) 2001-2008 Emil Mikulic. + * copyright (c) 2001-2009 Emil Mikulic. * * hosts_db.c: database of hosts, ports, protocols. * @@ -26,6 +26,7 @@ #include /* memset(), strcmp() */ #include +extern int want_lastseen; int show_mac_addrs = 0; extern const char *interface; @@ -273,8 +274,10 @@ format_cols_host(struct str *buf) str_append(buf, " In\n" " Out\n" - " Total\n" - " Last seen\n" + " Total\n"); + if (want_lastseen) str_append(buf, + " Last seen\n"); + str_append(buf, "\n"); } @@ -283,8 +286,6 @@ format_row_host(struct str *buf, const struct bucket *b, const char *css_class) { const char *ip = ip_to_str( b->u.host.ip ); - struct str *lastseen = NULL; - time_t last_t; str_appendf(buf, "\n" @@ -304,26 +305,33 @@ format_row_host(struct str *buf, const struct bucket *b, b->u.host.mac_addr[4], b->u.host.mac_addr[5]); - last_t = b->u.host.last_seen; - if (now >= last_t) - lastseen = length_of_time(now - last_t); - str_appendf(buf, " %'qu\n" " %'qu\n" - " %'qu\n" - " ", + " %'qu\n", b->in, b->out, b->total); - if (lastseen == NULL) - str_append(buf, "(clock error)"); - else { - str_appendstr(buf, lastseen); - str_free(lastseen); + if (want_lastseen) { + time_t last_t = b->u.host.last_seen; + struct str *lastseen = NULL; + + last_t = b->u.host.last_seen; + if (now >= last_t) + lastseen = length_of_time(now - last_t); + + str_append(buf, + " "); + if (lastseen == NULL) + str_append(buf, "(clock error)"); + else { + str_appendstr(buf, lastseen); + str_free(lastseen); + } + str_append(buf, + ""); } str_appendf(buf, - "\n" "\n"); /* Only resolve hosts "on demand" */