/* * 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 "die.h" #include "xmalloc.h" #include "xutils.h" #include "xio.h" #include "cpus.h" #include "built_in.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; uint32_t irq_nr, procs_run, procs_iow, cswitch, forks; 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; }; static volatile sig_atomic_t sigint = 0; static struct ifstat stats_old, stats_new, stats_delta; static struct cpu_hit *cpu_hits; static int stats_loop = 0; static WINDOW *stats_screen = NULL; static const char *short_options = "d:t:n:vhclp"; static const struct option long_options[] = { {"dev", required_argument, NULL, 'd'}, {"interval", required_argument, NULL, 't'}, {"num-cpus", required_argument, NULL, 'n'}, {"promisc", no_argument, NULL, 'p'}, {"csv", no_argument, NULL, 'c'}, {"loop", no_argument, NULL, 'l'}, {"version", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; static void signal_handler(int number) { switch (number) { case SIGINT: 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("\nifpps %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" " -t|--interval