From: Dirk Koopman Date: Tue, 21 Sep 2010 11:27:47 +0000 (+0100) Subject: allow sort on "last seen" X-Git-Tag: 3.0.714~81 X-Git-Url: https://unix4lyfe.org/gitweb/darkstat/commitdiff_plain/5aa0ef03ed296a2c4f29d4dbb589523737c2b86b allow sort on "last seen" This is very useful for those "who was doing that just now" moments --- diff --git a/hosts_db.c b/hosts_db.c index d0d0b85..d72fe47 100644 --- a/hosts_db.c +++ b/hosts_db.c @@ -318,7 +318,7 @@ format_cols_host(struct str *buf) " Out\n" " Total\n"); if (want_lastseen) str_append(buf, - " Last seen\n"); + " Last seen\n"); str_append(buf, "\n"); } @@ -956,6 +956,7 @@ html_hosts_main(const char *qs) else if (strcmp(qs_sort, "total") == 0) sort = TOTAL; else if (strcmp(qs_sort, "in") == 0) sort = IN; else if (strcmp(qs_sort, "out") == 0) sort = OUT; + else if (strcmp(qs_sort, "lastseen") == 0) sort = LASTSEEN; else { str_append(buf, "Error: invalid value for \"sort\".\n"); goto done; diff --git a/hosts_db.h b/hosts_db.h index 3db28fb..47aaa9c 100644 --- a/hosts_db.h +++ b/hosts_db.h @@ -57,7 +57,7 @@ struct bucket { } u; }; -enum sort_dir { IN, OUT, TOTAL }; +enum sort_dir { IN, OUT, TOTAL, LASTSEEN }; extern int show_mac_addrs; diff --git a/hosts_sort.c b/hosts_sort.c index 15dd213..655c331 100644 --- a/hosts_sort.c +++ b/hosts_sort.c @@ -33,6 +33,10 @@ cmp(const struct bucket * const *x, const struct bucket * const *y, a = (*x)->total; b = (*y)->total; break; + case LASTSEEN: + a = (*x)->u.host.last_seen; + b = (*y)->u.host.last_seen; + break; default: errx(1, "cmp: unknown direction: %d", dir); }