2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009 - 2013 Daniel Borkmann.
4 * Subject to the GPL, version 2.
12 #include <sys/socket.h>
13 #include <sys/fsuid.h>
27 int16_t link_qual
, link_qual_max
;
28 int signal_level
/*, noise_level*/;
32 long long unsigned int rx_bytes
, rx_packets
, rx_drops
, rx_errors
;
33 long long unsigned int rx_fifo
, rx_frame
, rx_multi
;
34 long long unsigned int tx_bytes
, tx_packets
, tx_drops
, tx_errors
;
35 long long unsigned int tx_fifo
, tx_colls
, tx_carrier
;
36 long long unsigned int irqs
[MAX_CPUS
], irqs_srx
[MAX_CPUS
], irqs_stx
[MAX_CPUS
];
37 int64_t cpu_user
[MAX_CPUS
], cpu_nice
[MAX_CPUS
], cpu_sys
[MAX_CPUS
];
38 int64_t cpu_idle
[MAX_CPUS
], cpu_iow
[MAX_CPUS
], mem_free
, mem_total
;
39 uint32_t irq_nr
, procs_run
, procs_iow
, cswitch
, forks
;
40 struct wifi_stat wifi
;
43 volatile sig_atomic_t sigint
= 0;
45 static struct ifstat stats_old
, stats_new
, stats_delta
;
47 static int stats_loop
= 0;
49 static WINDOW
*stats_screen
= NULL
;
51 static const char *short_options
= "d:t:vhclp";
52 static const struct option long_options
[] = {
53 {"dev", required_argument
, NULL
, 'd'},
54 {"interval", required_argument
, NULL
, 't'},
55 {"promisc", no_argument
, NULL
, 'p'},
56 {"csv", no_argument
, NULL
, 'c'},
57 {"loop", no_argument
, NULL
, 'l'},
58 {"version", no_argument
, NULL
, 'v'},
59 {"help", no_argument
, NULL
, 'h'},
63 static void signal_handler(int number
)
75 static inline char *snr_to_str(int level
)
78 return "very good signal";
79 if (level
> 25 && level
<= 40)
81 if (level
> 15 && level
<= 25)
83 if (level
> 10 && level
<= 15)
84 return "very poor signal";
91 static inline int iswireless(const struct ifstat
*stats
)
93 return stats
->wifi
.bitrate
> 0;
96 static void help(void)
98 printf("\nifpps %s, top-like kernel networking and system statistics\n",
100 puts("http://www.netsniff-ng.org\n\n"
101 "Usage: ifpps [options] || ifpps <netdev>\n"
103 " -d|--dev <netdev> Device to fetch statistics for e.g., eth0\n"
104 " -t|--interval <time> Refresh time in ms (default 1000 ms)\n"
105 " -p|--promisc Promiscuous mode\n"
106 " -c|--csv Output to terminal as Gnuplot-ready data\n"
107 " -l|--loop Continuous CSV output\n"
108 " -v|--version Print version\n"
109 " -h|--help Print this help\n\n"
113 " ifpps -lpcd wlan0 > plot.dat\n\n"
115 " On 10G cards, RX/TX statistics are usually accumulated each > 1sec.\n"
116 " Thus, in those situations, it's good to use a -t of 10sec.\n\n"
117 "Please report bugs to <bugs@netsniff-ng.org>\n"
118 "Copyright (C) 2009-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
119 "Swiss federal institute of technology (ETH Zurich)\n"
120 "License: GNU GPL version 2.0\n"
121 "This is free software: you are free to change and redistribute it.\n"
122 "There is NO WARRANTY, to the extent permitted by law.\n");
126 static void version(void)
128 printf("\nifpps %s, top-like kernel networking and system statistics\n",
130 puts("http://www.netsniff-ng.org\n\n"
131 "Please report bugs to <bugs@netsniff-ng.org>\n"
132 "Copyright (C) 2009-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
133 "Swiss federal institute of technology (ETH Zurich)\n"
134 "License: GNU GPL version 2.0\n"
135 "This is free software: you are free to change and redistribute it.\n"
136 "There is NO WARRANTY, to the extent permitted by law.\n");
140 static int stats_proc_net_dev(const char *ifname
, struct ifstat
*stats
)
146 fp
= fopen("/proc/net/dev", "r");
148 panic("Cannot open /proc/net/dev!\n");
150 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
151 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
153 memset(buff
, 0, sizeof(buff
));
155 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
156 buff
[sizeof(buff
) -1] = 0;
158 if (strstr(buff
, ifname
) == NULL
)
161 if (sscanf(buff
, "%*[a-z0-9 .-]:%llu%llu%llu%llu%llu%llu"
162 "%llu%*u%llu%llu%llu%llu%llu%llu%llu",
163 &stats
->rx_bytes
, &stats
->rx_packets
,
164 &stats
->rx_errors
, &stats
->rx_drops
,
165 &stats
->rx_fifo
, &stats
->rx_frame
,
166 &stats
->rx_multi
, &stats
->tx_bytes
,
167 &stats
->tx_packets
, &stats
->tx_errors
,
168 &stats
->tx_drops
, &stats
->tx_fifo
,
169 &stats
->tx_colls
, &stats
->tx_carrier
) == 14) {
174 memset(buff
, 0, sizeof(buff
));
181 static int stats_proc_interrupts(char *ifname
, struct ifstat
*stats
)
183 int ret
= -EINVAL
, i
, cpus
, try = 0;
184 char *ptr
, buff
[256];
185 struct ethtool_drvinfo drvinf
;
188 fp
= fopen("/proc/interrupts", "r");
190 panic("Cannot open /proc/interrupts!\n");
192 cpus
= get_number_cpus();
193 bug_on(cpus
> MAX_CPUS
);
195 fseek(fp
, 0, SEEK_SET
);
196 memset(buff
, 0, sizeof(buff
));
198 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
199 buff
[sizeof(buff
) - 1] = 0;
202 if (strstr(buff
, ifname
) == NULL
)
205 stats
->irq_nr
= strtol(ptr
, &ptr
, 10);
206 bug_on(stats
->irq_nr
== 0);
210 for (i
= 0; i
< cpus
&& ptr
; ++i
) {
211 stats
->irqs
[i
] = strtol(ptr
, &ptr
, 10);
218 memset(buff
, 0, sizeof(buff
));
221 if (ret
== -EINVAL
&& try == 0) {
222 memset(&drvinf
, 0, sizeof(drvinf
));
223 if (ethtool_drvinf(ifname
, &drvinf
) < 0)
226 ifname
= drvinf
.driver
;
236 static int stats_proc_softirqs(struct ifstat
*stats
)
239 char *ptr
, buff
[256];
246 fp
= fopen("/proc/softirqs", "r");
248 panic("Cannot open /proc/softirqs!\n");
250 cpus
= get_number_cpus();
251 bug_on(cpus
> MAX_CPUS
);
253 memset(buff
, 0, sizeof(buff
));
255 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
256 buff
[sizeof(buff
) - 1] = 0;
258 if ((ptr
= strstr(buff
, "NET_TX:")))
259 net_type
= softirqs_net_tx
;
260 else if ((ptr
= strstr(buff
, "NET_RX:")))
261 net_type
= softirqs_net_rx
;
265 for (ptr
+= strlen("NET_xX:"), i
= 0; i
< cpus
; ++i
) {
267 case softirqs_net_tx
:
268 stats
->irqs_stx
[i
] = strtol(ptr
, &ptr
, 10);
270 case softirqs_net_rx
:
271 stats
->irqs_srx
[i
] = strtol(ptr
, &ptr
, 10);
276 memset(buff
, 0, sizeof(buff
));
283 static int stats_proc_memory(struct ifstat
*stats
)
285 char *ptr
, buff
[256];
288 fp
= fopen("/proc/meminfo", "r");
290 panic("Cannot open /proc/meminfo!\n");
292 memset(buff
, 0, sizeof(buff
));
294 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
295 buff
[sizeof(buff
) - 1] = 0;
297 if ((ptr
= strstr(buff
, "MemTotal:"))) {
298 ptr
+= strlen("MemTotal:");
299 stats
->mem_total
= strtol(ptr
, &ptr
, 10);
300 } else if ((ptr
= strstr(buff
, "MemFree:"))) {
301 ptr
+= strlen("MemFree:");
302 stats
->mem_free
= strtol(ptr
, &ptr
, 10);
305 memset(buff
, 0, sizeof(buff
));
312 static int stats_proc_system(struct ifstat
*stats
)
315 char *ptr
, buff
[256];
318 fp
= fopen("/proc/stat", "r");
320 panic("Cannot open /proc/stat!\n");
322 cpus
= get_number_cpus();
323 bug_on(cpus
> MAX_CPUS
);
325 memset(buff
, 0, sizeof(buff
));
327 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
328 buff
[sizeof(buff
) - 1] = 0;
330 if ((ptr
= strstr(buff
, "cpu"))) {
331 ptr
+= strlen("cpu");
335 cpu
= strtol(ptr
, &ptr
, 10);
338 if (sscanf(ptr
, "%lu%lu%lu%lu%lu",
339 &stats
->cpu_user
[cpu
],
340 &stats
->cpu_nice
[cpu
],
341 &stats
->cpu_sys
[cpu
],
342 &stats
->cpu_idle
[cpu
],
343 &stats
->cpu_iow
[cpu
]) != 5)
345 } else if ((ptr
= strstr(buff
, "ctxt"))) {
346 ptr
+= strlen("ctxt");
347 stats
->cswitch
= strtoul(ptr
, &ptr
, 10);
348 } else if ((ptr
= strstr(buff
, "processes"))) {
349 ptr
+= strlen("processes");
350 stats
->forks
= strtoul(ptr
, &ptr
, 10);
351 } else if ((ptr
= strstr(buff
, "procs_running"))) {
352 ptr
+= strlen("procs_running");
353 stats
->procs_run
= strtoul(ptr
, &ptr
, 10);
354 } else if ((ptr
= strstr(buff
, "procs_blocked"))) {
355 ptr
+= strlen("procs_blocked");
356 stats
->procs_iow
= strtoul(ptr
, &ptr
, 10);
359 memset(buff
, 0, sizeof(buff
));
366 static int adjust_dbm_level(int in_dbm
, int dbm_val
)
371 return dbm_val
- 0x100;
374 static int stats_wireless(const char *ifname
, struct ifstat
*stats
)
377 struct iw_statistics ws
;
379 ret
= wireless_sigqual(ifname
, &ws
);
381 stats
->wifi
.bitrate
= 0;
385 stats
->wifi
.bitrate
= wireless_bitrate(ifname
);
387 stats
->wifi
.signal_level
=
388 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.level
);
390 stats
->wifi
.link_qual
= ws
.qual
.qual
;
391 stats
->wifi
.link_qual_max
= wireless_rangemax_sigqual(ifname
);
396 #define DIFF1(member) do { diff->member = new->member - old->member; } while (0)
397 #define DIFF(member) do { \
398 if (sizeof(diff->member) != sizeof(new->member) || \
399 sizeof(diff->member) != sizeof(old->member)) \
401 bug_on((new->member - old->member) > (new->member)); \
405 static void stats_diff(struct ifstat
*old
, struct ifstat
*new,
430 DIFF1(wifi
.signal_level
);
431 DIFF1(wifi
.link_qual
);
436 cpus
= get_number_cpus();
437 bug_on(cpus
> MAX_CPUS
);
439 for (i
= 0; i
< cpus
; ++i
) {
452 static void stats_fetch(const char *ifname
, struct ifstat
*stats
)
454 if (stats_proc_net_dev(ifname
, stats
) < 0)
455 panic("Cannot fetch device stats!\n");
456 if (stats_proc_softirqs(stats
) < 0)
457 panic("Cannot fetch software interrupts!\n");
458 if (stats_proc_memory(stats
) < 0)
459 panic("Cannot fetch memory stats!\n");
460 if (stats_proc_system(stats
) < 0)
461 panic("Cannot fetch system stats!\n");
463 stats_proc_interrupts((char *) ifname
, stats
);
465 stats_wireless(ifname
, stats
);
468 static void stats_sample_generic(const char *ifname
, uint64_t ms_interval
)
470 memset(&stats_old
, 0, sizeof(stats_old
));
471 memset(&stats_new
, 0, sizeof(stats_new
));
472 memset(&stats_delta
, 0, sizeof(stats_delta
));
474 stats_fetch(ifname
, &stats_old
);
475 usleep(ms_interval
* 1000);
476 stats_fetch(ifname
, &stats_new
);
478 stats_diff(&stats_old
, &stats_new
, &stats_delta
);
481 static void screen_init(WINDOW
**screen
)
483 (*screen
) = initscr();
488 nodelay((*screen
), TRUE
);
490 keypad(stdscr
, TRUE
);
496 static void screen_header(WINDOW
*screen
, const char *ifname
, int *voff
,
497 uint64_t ms_interval
)
501 struct ethtool_drvinfo drvinf
;
502 u32 rate
= device_bitrate(ifname
);
503 int link
= ethtool_link(ifname
);
505 memset(&drvinf
, 0, sizeof(drvinf
));
506 ethtool_drvinf(ifname
, &drvinf
);
508 memset(buff
, 0, sizeof(buff
));
510 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " %uMbit/s", rate
);
512 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " link:%s",
513 link
== 0 ? "no" : "yes");
515 mvwprintw(screen
, (*voff
)++, 2,
516 "Kernel net/sys statistics for %s (%s%s), t=%lums"
518 ifname
, drvinf
.driver
, buff
, ms_interval
);
521 static void screen_net_dev_rel(WINDOW
*screen
, const struct ifstat
*rel
,
526 mvwprintw(screen
, (*voff
)++, 0,
527 " RX: %16.3llf MiB/t "
531 ((long double) rel
->rx_bytes
) / (1LLU << 20),
532 rel
->rx_packets
, rel
->rx_drops
, rel
->rx_errors
);
534 mvwprintw(screen
, (*voff
)++, 0,
535 " TX: %16.3llf MiB/t "
539 ((long double) rel
->tx_bytes
) / (1LLU << 20),
540 rel
->tx_packets
, rel
->tx_drops
, rel
->tx_errors
);
545 static void screen_net_dev_abs(WINDOW
*screen
, const struct ifstat
*abs
,
548 mvwprintw(screen
, (*voff
)++, 2,
553 ((long double) abs
->rx_bytes
) / (1LLU << 20),
554 abs
->rx_packets
, abs
->rx_drops
, abs
->rx_errors
);
556 mvwprintw(screen
, (*voff
)++, 2,
561 ((long double) abs
->tx_bytes
) / (1LLU << 20),
562 abs
->tx_packets
, abs
->tx_drops
, abs
->tx_errors
);
565 static void screen_sys_mem(WINDOW
*screen
, const struct ifstat
*rel
,
566 const struct ifstat
*abs
, int *voff
)
568 mvwprintw(screen
, (*voff
)++, 2,
574 (100.0 * (abs
->mem_total
- abs
->mem_free
)) / abs
->mem_total
,
575 abs
->procs_run
, abs
->procs_iow
);
578 static void screen_percpu_states(WINDOW
*screen
, const struct ifstat
*rel
,
584 for (i
= 0; i
< cpus
; ++i
) {
585 all
= rel
->cpu_user
[i
] + rel
->cpu_nice
[i
] + rel
->cpu_sys
[i
] +
586 rel
->cpu_idle
[i
] + rel
->cpu_iow
[i
];
588 mvwprintw(screen
, (*voff
)++, 2,
589 "CPU%d: %13.1lf%% usr/t "
592 "%11.1lf%% iow/t ", i
,
593 100.0 * (rel
->cpu_user
[i
] + rel
->cpu_nice
[i
]) / all
,
594 100.0 * rel
->cpu_sys
[i
] / all
,
595 100.0 * rel
->cpu_idle
[i
] / all
,
596 100.0 * rel
->cpu_iow
[i
] / all
);
600 static void screen_percpu_irqs_rel(WINDOW
*screen
, const struct ifstat
*rel
,
605 for (i
= 0; i
< cpus
; ++i
) {
606 mvwprintw(screen
, (*voff
)++, 2,
607 "CPU%d: %14llu irqs/t "
609 "%15llu soirq TX/t ", i
,
616 static void screen_percpu_irqs_abs(WINDOW
*screen
, const struct ifstat
*abs
,
621 for (i
= 0; i
< cpus
; ++i
) {
622 mvwprintw(screen
, (*voff
)++, 2,
623 "CPU%d: %14llu irqs", i
,
628 static void screen_wireless(WINDOW
*screen
, const struct ifstat
*rel
,
629 const struct ifstat
*abs
, int *voff
)
631 if (iswireless(abs
)) {
632 mvwprintw(screen
, (*voff
)++, 2,
633 "LinkQual: %7d/%d (%d/t) ",
635 abs
->wifi
.link_qual_max
,
636 rel
->wifi
.link_qual
);
638 mvwprintw(screen
, (*voff
)++, 2,
639 "Signal: %8d dBm (%d dBm/t) ",
640 abs
->wifi
.signal_level
,
641 rel
->wifi
.signal_level
);
645 static void screen_update(WINDOW
*screen
, const char *ifname
, const struct ifstat
*rel
,
646 const struct ifstat
*abs
, int *first
, uint64_t ms_interval
)
648 int cpus
, voff
= 1, cvoff
= 2;
652 cpus
= get_number_cpus();
653 bug_on(cpus
> MAX_CPUS
);
655 screen_header(screen
, ifname
, &voff
, ms_interval
);
658 screen_net_dev_rel(screen
, rel
, &voff
);
661 screen_net_dev_abs(screen
, abs
, &voff
);
664 screen_sys_mem(screen
, rel
, abs
, &voff
);
667 screen_percpu_states(screen
, rel
, cpus
, &voff
);
670 screen_percpu_irqs_rel(screen
, rel
, cpus
, &voff
);
673 screen_percpu_irqs_abs(screen
, abs
, cpus
, &voff
);
676 screen_wireless(screen
, rel
, abs
, &voff
);
679 mvwprintw(screen
, cvoff
, 2, "Collecting data ...");
682 mvwprintw(screen
, cvoff
, 2, " ");
689 static void screen_end(void)
694 static int screen_main(const char *ifname
, uint64_t ms_interval
)
698 screen_init(&stats_screen
);
702 if (key
== 'q' || key
== 0x1b || key
== KEY_F(10))
705 screen_update(stats_screen
, ifname
, &stats_delta
, &stats_new
,
706 &first
, ms_interval
);
708 stats_sample_generic(ifname
, ms_interval
);
716 static void term_csv(const char *ifname
, const struct ifstat
*rel
,
717 const struct ifstat
*abs
, uint64_t ms_interval
)
721 printf("%ld ", time(0));
723 printf("%llu ", rel
->rx_bytes
);
724 printf("%llu ", rel
->rx_packets
);
725 printf("%llu ", rel
->rx_drops
);
726 printf("%llu ", rel
->rx_errors
);
728 printf("%llu ", abs
->rx_bytes
);
729 printf("%llu ", abs
->rx_packets
);
730 printf("%llu ", abs
->rx_drops
);
731 printf("%llu ", abs
->rx_errors
);
733 printf("%llu ", rel
->tx_bytes
);
734 printf("%llu ", rel
->tx_packets
);
735 printf("%llu ", rel
->tx_drops
);
736 printf("%llu ", rel
->tx_errors
);
738 printf("%llu ", abs
->tx_bytes
);
739 printf("%llu ", abs
->tx_packets
);
740 printf("%llu ", abs
->tx_drops
);
741 printf("%llu ", abs
->tx_errors
);
743 printf("%u ", rel
->cswitch
);
744 printf("%lu ", abs
->mem_free
);
745 printf("%lu ", abs
->mem_total
- abs
->mem_free
);
746 printf("%lu ", abs
->mem_total
);
747 printf("%u ", abs
->procs_run
);
748 printf("%u ", abs
->procs_iow
);
750 cpus
= get_number_cpus();
751 bug_on(cpus
> MAX_CPUS
);
753 for (i
= 0; i
< cpus
; ++i
) {
754 printf("%lu ", rel
->cpu_user
[i
]);
755 printf("%lu ", rel
->cpu_nice
[i
]);
756 printf("%lu ", rel
->cpu_sys
[i
]);
757 printf("%lu ", rel
->cpu_idle
[i
]);
758 printf("%lu ", rel
->cpu_iow
[i
]);
760 printf("%llu ", rel
->irqs
[i
]);
761 printf("%llu ", abs
->irqs
[i
]);
763 printf("%llu ", rel
->irqs_srx
[i
]);
764 printf("%llu ", abs
->irqs_srx
[i
]);
766 printf("%llu ", rel
->irqs_stx
[i
]);
767 printf("%llu ", abs
->irqs_stx
[i
]);
770 if (iswireless(abs
)) {
771 printf("%u ", rel
->wifi
.link_qual
);
772 printf("%u ", abs
->wifi
.link_qual
);
773 printf("%u ", abs
->wifi
.link_qual_max
);
775 printf("%d ", rel
->wifi
.signal_level
);
776 printf("%d ", abs
->wifi
.signal_level
);
783 static void term_csv_header(const char *ifname
, const struct ifstat
*abs
,
784 uint64_t ms_interval
)
788 printf("# gnuplot dump (#col:description)\n");
789 printf("# networking interface: %s\n", ifname
);
790 printf("# sampling interval (t): %lu ms\n", ms_interval
);
791 printf("# %d:unixtime ", j
++);
793 printf("%d:rx-bytes-per-t ", j
++);
794 printf("%d:rx-pkts-per-t ", j
++);
795 printf("%d:rx-drops-per-t ", j
++);
796 printf("%d:rx-errors-per-t ", j
++);
798 printf("%d:rx-bytes ", j
++);
799 printf("%d:rx-pkts ", j
++);
800 printf("%d:rx-drops ", j
++);
801 printf("%d:rx-errors ", j
++);
803 printf("%d:tx-bytes-per-t ", j
++);
804 printf("%d:tx-pkts-per-t ", j
++);
805 printf("%d:tx-drops-per-t ", j
++);
806 printf("%d:tx-errors-per-t ", j
++);
808 printf("%d:tx-bytes ", j
++);
809 printf("%d:tx-pkts ", j
++);
810 printf("%d:tx-drops ", j
++);
811 printf("%d:tx-errors ", j
++);
813 printf("%d:context-switches-per-t ", j
++);
814 printf("%d:mem-free ", j
++);
815 printf("%d:mem-used ", j
++);
816 printf("%d:mem-total ", j
++);
817 printf("%d:procs-in-run ", j
++);
818 printf("%d:procs-in-iow ", j
++);
820 cpus
= get_number_cpus();
821 bug_on(cpus
> MAX_CPUS
);
823 for (i
= 0, j
= 22; i
< cpus
; ++i
) {
824 printf("%d:cpu%i-usr-per-t ", j
++, i
);
825 printf("%d:cpu%i-nice-per-t ", j
++, i
);
826 printf("%d:cpu%i-sys-per-t ", j
++, i
);
827 printf("%d:cpu%i-idle-per-t ", j
++, i
);
828 printf("%d:cpu%i-iow-per-t ", j
++, i
);
830 printf("%d:cpu%i-net-irqs-per-t ", j
++, i
);
831 printf("%d:cpu%i-net-irqs ", j
++, i
);
833 printf("%d:cpu%i-net-rx-soft-irqs-per-t ", j
++, i
);
834 printf("%d:cpu%i-net-rx-soft-irqs ", j
++, i
);
835 printf("%d:cpu%i-net-tx-soft-irqs-per-t ", j
++, i
);
836 printf("%d:cpu%i-net-tx-soft-irqs ", j
++, i
);
839 if (iswireless(abs
)) {
840 printf("%d:wifi-link-qual-per-t ", j
++);
841 printf("%d:wifi-link-qual ", j
++);
842 printf("%d:wifi-link-qual-max ", j
++);
844 printf("%d:wifi-signal-dbm-per-t ", j
++);
845 printf("%d:wifi-signal-dbm ", j
++);
853 static int term_main(const char *ifname
, uint64_t ms_interval
)
858 stats_sample_generic(ifname
, ms_interval
);
862 term_csv_header(ifname
, &stats_new
, ms_interval
);
865 term_csv(ifname
, &stats_delta
, &stats_new
, ms_interval
);
866 } while (stats_loop
&& !sigint
);
871 int main(int argc
, char **argv
)
874 int c
, opt_index
, ret
, promisc
= 0;
875 uint64_t interval
= 1000;
877 int (*func_main
)(const char *ifname
, uint64_t ms_interval
) = screen_main
;
882 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
883 &opt_index
)) != EOF
) {
892 ifname
= xstrndup(optarg
, IFNAMSIZ
);
895 interval
= strtol(optarg
, NULL
, 10);
904 func_main
= term_main
;
910 panic("Option -%c requires an argument!\n",
914 printf("Unknown option character `0x%X\'!\n", optopt
);
926 ifname
= xstrndup(argv
[1], IFNAMSIZ
);
928 panic("No networking device given!\n");
930 if (!strncmp("lo", ifname
, IFNAMSIZ
))
931 panic("lo is not supported!\n");
932 if (device_mtu(ifname
) == 0)
933 panic("This is no networking device!\n");
935 register_signal(SIGINT
, signal_handler
);
936 register_signal(SIGHUP
, signal_handler
);
939 ifflags
= enter_promiscuous_mode(ifname
);
940 ret
= func_main(ifname
, interval
);
942 leave_promiscuous_mode(ifname
, ifflags
);