diff options
author | Calvin Morrison <calvin@fastmailteam.com> | 2019-05-28 13:16:22 -0400 |
---|---|---|
committer | Calvin Morrison <calvin@fastmailteam.com> | 2019-05-28 13:16:22 -0400 |
commit | 9384d9225dfde9f0feeee9c17fc88acebefb88f3 (patch) | |
tree | 0e761bbee09e85bb035991892f732084d1022053 /fsbm.c | |
parent | 67d67ff739e4aebcca94d3c1f2676ac2a598dcca (diff) |
allow different source files, since processes might have their own network namespace
Diffstat (limited to 'fsbm.c')
-rw-r--r-- | fsbm.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -12,8 +12,6 @@ #include <string.h> #include <stddef.h> -#define PROC_NET_DEV "/proc/net/dev" - struct iface { char interface[IFNAMSIZ]; struct timeval timestamp; @@ -27,6 +25,7 @@ bool request_name_enabled = false; volatile bool q = false; bool use_bits = false; char *request_name; +char *netdev_path = "/proc/net/dev"; struct iface *interfaces = NULL; size_t no_iface = 0; @@ -71,9 +70,9 @@ void print_bps(double bytesPerSecond) { void print_stats() { // Open /proc/net/dev - FILE *dev = fopen(PROC_NET_DEV, "r"); + FILE *dev = fopen(netdev_path, "r"); if (!dev) { - fprintf(stderr, "cannot open %s - %s\n", PROC_NET_DEV, strerror(errno)); + fprintf(stderr, "cannot open %s - %s\n", netdev_path, strerror(errno)); exit(EXIT_FAILURE); } @@ -174,7 +173,7 @@ int main(int argc, char **argv) { int c; unsigned long long interval = 10 * 100000; - while ((c = getopt (argc, argv, "rbi:d:hv")) != -1) + while ((c = getopt (argc, argv, "rbi:d:f:hv")) != -1) switch (c) { case 'b': @@ -186,9 +185,12 @@ int main(int argc, char **argv) { interval = interval * 100000; break; case 'h': - printf("USAGE: fsbm, -i shows only matching interface, -r gives raw counts, -b specifies bits, -d sets interval in 10ths of seconds, 1 sec default\n"); + printf("USAGE: fsbm, \n\t-f use a different /net/dev file, like /proc/123/net/dev\n\t-i shows only matching interface, \n\t-r gives raw counts, \n\t-b specifies bits, \n\t-d sets interval in 10ths of seconds, 1 sec default\n"); exit(EXIT_SUCCESS); break; + case 'f': + netdev_path = strdup(optarg); + break; case 'i': request_name_enabled = true; request_name = strdup(optarg); |