From c3b1504c716b7a91d8d1563aed6b9f766dc27e3f Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Wed, 28 Oct 2015 07:39:26 +0200 Subject: flowtop: Add command-line option to show rates in bits Add -b,--bits command line option to show rates in bits/s instead of bytes/s. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- flowtop.8 | 3 +++ flowtop.c | 29 ++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/flowtop.8 b/flowtop.8 index d85284a..1367e6e 100644 --- a/flowtop.8 +++ b/flowtop.8 @@ -114,6 +114,9 @@ endpoints. .SS -s, --show-src Also show source information of the flow, not only destination information. .PP +.SS -b, --bits +Show flow rates in bits per second instead of bytes per second. +.PP .SS -u, --update The built-in database update mechanism will be invoked to get Maxmind's latest database. To configure search locations for databases, the file diff --git a/flowtop.c b/flowtop.c index 7573780..79e130c 100644 --- a/flowtop.c +++ b/flowtop.c @@ -104,6 +104,11 @@ struct sysctl_params_ctx { int nfct_tstamp; }; +enum rate_units { + RATE_BITS, + RATE_BYTES +}; + static volatile bool is_flow_collecting; static volatile sig_atomic_t sigint = 0; static int what = INCLUDE_IPV4 | INCLUDE_IPV6 | INCLUDE_TCP; @@ -114,8 +119,9 @@ static unsigned int interval = 1; static bool show_src = false; static bool resolve_dns = true; static bool resolve_geoip = true; +static enum rate_units rate_type = RATE_BYTES; -static const char *short_options = "vhTUsDIS46ut:nG"; +static const char *short_options = "vhTUsDIS46ut:nGb"; static const struct option long_options[] = { {"ipv4", no_argument, NULL, '4'}, {"ipv6", no_argument, NULL, '6'}, @@ -127,6 +133,7 @@ static const struct option long_options[] = { {"no-dns", no_argument, NULL, 'n'}, {"no-geoip", no_argument, NULL, 'G'}, {"show-src", no_argument, NULL, 's'}, + {"bits", no_argument, NULL, 'b'}, {"update", no_argument, NULL, 'u'}, {"interval", required_argument, NULL, 't'}, {"version", no_argument, NULL, 'v'}, @@ -261,6 +268,7 @@ static void help(void) " -S|--sctp Show only SCTP flows\n" " -n|--no-dns Don't perform hostname lookup\n" " -s|--show-src Also show source, not only dest\n" + " -b|--bits Show rates in bits/s instead of bytes/s\n" " -u|--update Update GeoIP databases\n" " -t|--interval