/* * netsniff-ng - the packet sniffing beast * Copyright 2009 - 2013 Daniel Borkmann. * Copyright 2013 Tobias Klauser * Subject to the GPL, version 2. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "die.h" #include "dev.h" #include "sig.h" #include "str.h" #include "link.h" #include "xmalloc.h" #include "ioops.h" #include "cpus.h" #include "config.h" #include "built_in.h" #include "screen.h" struct wifi_stat { uint32_t bitrate; int16_t link_qual, link_qual_max; int signal_level /*, noise_level*/; }; struct ifstat { long long unsigned int rx_bytes, rx_packets, rx_drops, rx_errors; long long unsigned int rx_fifo, rx_frame, rx_multi; long long unsigned int tx_bytes, tx_packets, tx_drops, tx_errors; long long unsigned int tx_fifo, tx_colls, tx_carrier; uint64_t mem_free, mem_total, mem_active, mem_inactive; uint64_t swap_total, swap_free, swap_cached; uint32_t procs_total, procs_run, procs_iow, cswitch; struct wifi_stat wifi; /* * Pointer members need to be last in order for stats_zero() to work * properly. */ long long unsigned int *irqs, *irqs_srx, *irqs_stx; uint64_t *cpu_user, *cpu_sys, *cpu_nice, *cpu_idle, *cpu_iow; }; struct cpu_hit { unsigned int idx; uint64_t hit; long long unsigned int irqs_rel, irqs_abs; }; struct avg_stat { uint64_t cpu_user, cpu_sys, cpu_nice, cpu_idle, cpu_iow; long double irqs_abs, irqs_rel, irqs_srx_rel, irqs_stx_rel; }; static volatile sig_atomic_t sigint = 0; static struct ifstat stats_old, stats_new, stats_delta; static struct cpu_hit *cpu_hits; static struct avg_stat stats_avg; static int stats_loop = 0; static int show_median = 0, show_percentage = 0; static WINDOW *stats_screen = NULL; static struct utsname uts; static const char *short_options = "d:n:t:clmopPWvh"; static const struct option long_options[] = { {"dev", required_argument, NULL, 'd'}, {"num-cpus", required_argument, NULL, 'n'}, {"interval", required_argument, NULL, 't'}, {"csv", no_argument, NULL, 'c'}, {"loop", no_argument, NULL, 'l'}, {"median", no_argument, NULL, 'm'}, {"omit-header", no_argument, NULL, 'o'}, {"promisc", no_argument, NULL, 'p'}, {"percentage", no_argument, NULL, 'P'}, {"no-warn", no_argument, NULL, 'W'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; static const char *copyright = "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n" "Copyright (C) 2009-2013 Daniel Borkmann \n" "Swiss federal institute of technology (ETH Zurich)\n" "Copyright (C) 2013 Tobias Klauser \n" "License: GNU GPL version 2.0\n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law."; static void signal_handler(int number) { switch (number) { case SIGINT: case SIGQUIT: case SIGTERM: sigint = 1; break; case SIGHUP: default: break; } } static inline int iswireless(const struct ifstat *stats) { return stats->wifi.bitrate > 0; } static void __noreturn help(void) { printf("ifpps %s, top-like kernel networking and system statistics\n", VERSION_STRING); puts("http://www.netsniff-ng.org\n\n" "Usage: ifpps [options] || ifpps \n" "Options:\n" " -d|--dev Device to fetch statistics for e.g., eth0\n" " -n|--num-cpus Number of top hitter CPUs in ncurses mode (def: 5)\n" " -t|--interval