2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009 - 2013 Daniel Borkmann.
5 * Subject to the GPL, version 2.
7 * A tiny tool to provide top-like reliable networking statistics.
8 * Why? Well, some time ago I used iptraf to display network traffic
9 * statistics. During that time and probably also today, they are
10 * using libpcap to collect statistics. Well, bad idea since this
11 * will give you false statistics on high I/O load. Therefore, ifpps
12 * reads out the 'real' kernel statistics, so things your NIC sees
13 * and not some userland library.
15 * He had all the injured air of a liar suspected when for once he
16 * has told the truth, or part of it.
18 * -- The Lord of the Rings, On Gollum,
19 * Chapter 'The Black Gate is Closed'.
27 #include <sys/socket.h>
28 #include <sys/fsuid.h>
42 int16_t link_qual
, link_qual_max
;
43 int signal_level
/*, noise_level*/;
47 long long unsigned int rx_bytes
, rx_packets
, rx_drops
, rx_errors
;
48 long long unsigned int rx_fifo
, rx_frame
, rx_multi
;
49 long long unsigned int tx_bytes
, tx_packets
, tx_drops
, tx_errors
;
50 long long unsigned int tx_fifo
, tx_colls
, tx_carrier
;
51 long long unsigned int irqs
[MAX_CPUS
], irqs_srx
[MAX_CPUS
], irqs_stx
[MAX_CPUS
];
52 int64_t cpu_user
[MAX_CPUS
], cpu_nice
[MAX_CPUS
], cpu_sys
[MAX_CPUS
];
53 int64_t cpu_idle
[MAX_CPUS
], cpu_iow
[MAX_CPUS
], mem_free
, mem_total
;
54 uint32_t irq_nr
, procs_run
, procs_iow
, cswitch
, forks
;
55 struct wifi_stat wifi
;
58 volatile sig_atomic_t sigint
= 0;
60 static struct ifstat stats_old
, stats_new
, stats_delta
;
62 static int stats_loop
= 0;
64 static WINDOW
*stats_screen
= NULL
;
66 static const char *short_options
= "d:t:vhclp";
67 static const struct option long_options
[] = {
68 {"dev", required_argument
, NULL
, 'd'},
69 {"interval", required_argument
, NULL
, 't'},
70 {"promisc", no_argument
, NULL
, 'p'},
71 {"csv", no_argument
, NULL
, 'c'},
72 {"loop", no_argument
, NULL
, 'l'},
73 {"version", no_argument
, NULL
, 'v'},
74 {"help", no_argument
, NULL
, 'h'},
78 static void signal_handler(int number
)
90 static inline char *snr_to_str(int level
)
93 return "very good signal";
94 if (level
> 25 && level
<= 40)
96 if (level
> 15 && level
<= 25)
98 if (level
> 10 && level
<= 15)
99 return "very poor signal";
106 static inline int iswireless(const struct ifstat
*stats
)
108 return stats
->wifi
.bitrate
> 0;
111 static void help(void)
113 printf("\nifpps %s, top-like kernel networking and system statistics\n",
115 puts("http://www.netsniff-ng.org\n\n"
116 "Usage: ifpps [options] || ifpps <netdev>\n"
118 " -d|--dev <netdev> Device to fetch statistics for e.g., eth0\n"
119 " -t|--interval <time> Refresh time in ms (default 1000 ms)\n"
120 " -p|--promisc Promiscuous mode\n"
121 " -c|--csv Output to terminal as Gnuplot-ready data\n"
122 " -l|--loop Continuous CSV output\n"
123 " -v|--version Print version\n"
124 " -h|--help Print this help\n\n"
128 " ifpps -lpcd wlan0 > plot.dat\n\n"
130 " On 10G cards, RX/TX statistics are usually accumulated each > 1sec.\n"
131 " Thus, in those situations, it's could be to use a -t of 10sec.\n\n"
132 "Please report bugs to <bugs@netsniff-ng.org>\n"
133 "Copyright (C) 2009-2013 Daniel Borkmann <daniel@netsniff-ng.org>\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 void version(void)
142 printf("\nifpps %s, top-like kernel networking and system statistics\n",
144 puts("http://www.netsniff-ng.org\n\n"
145 "Please report bugs to <bugs@netsniff-ng.org>\n"
146 "Copyright (C) 2009-2013 Daniel Borkmann <daniel@netsniff-ng.org>\n"
147 "License: GNU GPL version 2.0\n"
148 "This is free software: you are free to change and redistribute it.\n"
149 "There is NO WARRANTY, to the extent permitted by law.\n");
153 static int stats_proc_net_dev(const char *ifname
, struct ifstat
*stats
)
159 fp
= fopen("/proc/net/dev", "r");
161 panic("Cannot open /proc/net/dev!\n");
163 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
164 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
166 memset(buff
, 0, sizeof(buff
));
168 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
169 buff
[sizeof(buff
) -1] = 0;
171 if (strstr(buff
, ifname
) == NULL
)
174 if (sscanf(buff
, "%*[a-z0-9 .-]:%llu%llu%llu%llu%llu%llu"
175 "%llu%*u%llu%llu%llu%llu%llu%llu%llu",
176 &stats
->rx_bytes
, &stats
->rx_packets
,
177 &stats
->rx_errors
, &stats
->rx_drops
,
178 &stats
->rx_fifo
, &stats
->rx_frame
,
179 &stats
->rx_multi
, &stats
->tx_bytes
,
180 &stats
->tx_packets
, &stats
->tx_errors
,
181 &stats
->tx_drops
, &stats
->tx_fifo
,
182 &stats
->tx_colls
, &stats
->tx_carrier
) == 14) {
187 memset(buff
, 0, sizeof(buff
));
194 static int stats_proc_interrupts(char *ifname
, struct ifstat
*stats
)
196 int ret
= -EINVAL
, i
, cpus
, try = 0;
197 char *ptr
, buff
[256];
198 struct ethtool_drvinfo drvinf
;
201 fp
= fopen("/proc/interrupts", "r");
203 panic("Cannot open /proc/interrupts!\n");
205 cpus
= get_number_cpus();
206 bug_on(cpus
> MAX_CPUS
);
208 fseek(fp
, 0, SEEK_SET
);
209 memset(buff
, 0, sizeof(buff
));
211 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
212 buff
[sizeof(buff
) - 1] = 0;
215 if (strstr(buff
, ifname
) == NULL
)
218 stats
->irq_nr
= strtol(ptr
, &ptr
, 10);
219 bug_on(stats
->irq_nr
== 0);
223 for (i
= 0; i
< cpus
&& ptr
; ++i
) {
224 stats
->irqs
[i
] = strtol(ptr
, &ptr
, 10);
231 memset(buff
, 0, sizeof(buff
));
234 if (ret
== -EINVAL
&& try == 0) {
235 memset(&drvinf
, 0, sizeof(drvinf
));
236 if (ethtool_drvinf(ifname
, &drvinf
) < 0)
239 ifname
= drvinf
.driver
;
249 static int stats_proc_softirqs(struct ifstat
*stats
)
252 char *ptr
, buff
[256];
258 } net_type
= softirqs_net_none
;
260 fp
= fopen("/proc/softirqs", "r");
262 panic("Cannot open /proc/softirqs!\n");
264 cpus
= get_number_cpus();
265 bug_on(cpus
> MAX_CPUS
);
267 memset(buff
, 0, sizeof(buff
));
269 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
270 buff
[sizeof(buff
) - 1] = 0;
272 if ((ptr
= strstr(buff
, "NET_TX:")))
273 net_type
= softirqs_net_tx
;
274 else if ((ptr
= strstr(buff
, "NET_RX:")))
275 net_type
= softirqs_net_rx
;
279 for (ptr
+= strlen("NET_xX:"), i
= 0; i
< cpus
; ++i
) {
281 case softirqs_net_tx
:
282 stats
->irqs_stx
[i
] = strtol(ptr
, &ptr
, 10);
284 case softirqs_net_rx
:
285 stats
->irqs_srx
[i
] = strtol(ptr
, &ptr
, 10);
292 memset(buff
, 0, sizeof(buff
));
299 static int stats_proc_memory(struct ifstat
*stats
)
301 char *ptr
, buff
[256];
304 fp
= fopen("/proc/meminfo", "r");
306 panic("Cannot open /proc/meminfo!\n");
308 memset(buff
, 0, sizeof(buff
));
310 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
311 buff
[sizeof(buff
) - 1] = 0;
313 if ((ptr
= strstr(buff
, "MemTotal:"))) {
314 ptr
+= strlen("MemTotal:");
315 stats
->mem_total
= strtol(ptr
, &ptr
, 10);
316 } else if ((ptr
= strstr(buff
, "MemFree:"))) {
317 ptr
+= strlen("MemFree:");
318 stats
->mem_free
= strtol(ptr
, &ptr
, 10);
321 memset(buff
, 0, sizeof(buff
));
328 static int stats_proc_system(struct ifstat
*stats
)
331 char *ptr
, buff
[256];
334 fp
= fopen("/proc/stat", "r");
336 panic("Cannot open /proc/stat!\n");
338 cpus
= get_number_cpus();
339 bug_on(cpus
> MAX_CPUS
);
341 memset(buff
, 0, sizeof(buff
));
343 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
344 buff
[sizeof(buff
) - 1] = 0;
346 if ((ptr
= strstr(buff
, "cpu"))) {
347 ptr
+= strlen("cpu");
351 cpu
= strtol(ptr
, &ptr
, 10);
354 if (sscanf(ptr
, "%lu%lu%lu%lu%lu",
355 &stats
->cpu_user
[cpu
],
356 &stats
->cpu_nice
[cpu
],
357 &stats
->cpu_sys
[cpu
],
358 &stats
->cpu_idle
[cpu
],
359 &stats
->cpu_iow
[cpu
]) != 5)
361 } else if ((ptr
= strstr(buff
, "ctxt"))) {
362 ptr
+= strlen("ctxt");
363 stats
->cswitch
= strtoul(ptr
, &ptr
, 10);
364 } else if ((ptr
= strstr(buff
, "processes"))) {
365 ptr
+= strlen("processes");
366 stats
->forks
= strtoul(ptr
, &ptr
, 10);
367 } else if ((ptr
= strstr(buff
, "procs_running"))) {
368 ptr
+= strlen("procs_running");
369 stats
->procs_run
= strtoul(ptr
, &ptr
, 10);
370 } else if ((ptr
= strstr(buff
, "procs_blocked"))) {
371 ptr
+= strlen("procs_blocked");
372 stats
->procs_iow
= strtoul(ptr
, &ptr
, 10);
375 memset(buff
, 0, sizeof(buff
));
382 static int stats_wireless(const char *ifname
, struct ifstat
*stats
)
385 struct iw_statistics ws
;
387 ret
= wireless_sigqual(ifname
, &ws
);
389 stats
->wifi
.bitrate
= 0;
393 stats
->wifi
.bitrate
= wireless_bitrate(ifname
);
395 stats
->wifi
.signal_level
=
396 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.level
);
398 stats
->wifi
.link_qual
= ws
.qual
.qual
;
399 stats
->wifi
.link_qual_max
= wireless_rangemax_sigqual(ifname
);
404 #define DIFF1(member) do { diff->member = new->member - old->member; } while (0)
405 #define DIFF(member) do { \
406 if (sizeof(diff->member) != sizeof(new->member) || \
407 sizeof(diff->member) != sizeof(old->member)) \
409 bug_on((new->member - old->member) > (new->member)); \
413 static void stats_diff(struct ifstat
*old
, struct ifstat
*new,
438 DIFF1(wifi
.signal_level
);
439 DIFF1(wifi
.link_qual
);
444 cpus
= get_number_cpus();
445 bug_on(cpus
> MAX_CPUS
);
447 for (i
= 0; i
< cpus
; ++i
) {
460 static void stats_fetch(const char *ifname
, struct ifstat
*stats
)
462 if (stats_proc_net_dev(ifname
, stats
) < 0)
463 panic("Cannot fetch device stats!\n");
464 if (stats_proc_softirqs(stats
) < 0)
465 panic("Cannot fetch software interrupts!\n");
466 if (stats_proc_memory(stats
) < 0)
467 panic("Cannot fetch memory stats!\n");
468 if (stats_proc_system(stats
) < 0)
469 panic("Cannot fetch system stats!\n");
471 stats_proc_interrupts((char *) ifname
, stats
);
473 stats_wireless(ifname
, stats
);
476 static void stats_sample_generic(const char *ifname
, uint64_t ms_interval
)
478 memset(&stats_old
, 0, sizeof(stats_old
));
479 memset(&stats_new
, 0, sizeof(stats_new
));
480 memset(&stats_delta
, 0, sizeof(stats_delta
));
482 stats_fetch(ifname
, &stats_old
);
483 usleep(ms_interval
* 1000);
484 stats_fetch(ifname
, &stats_new
);
486 stats_diff(&stats_old
, &stats_new
, &stats_delta
);
489 static void screen_init(WINDOW
**screen
)
491 (*screen
) = initscr();
496 nodelay((*screen
), TRUE
);
498 keypad(stdscr
, TRUE
);
504 static void screen_header(WINDOW
*screen
, const char *ifname
, int *voff
,
505 uint64_t ms_interval
)
509 struct ethtool_drvinfo drvinf
;
510 u32 rate
= device_bitrate(ifname
);
511 int link
= ethtool_link(ifname
);
513 memset(&drvinf
, 0, sizeof(drvinf
));
514 ethtool_drvinf(ifname
, &drvinf
);
516 memset(buff
, 0, sizeof(buff
));
518 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " %uMbit/s", rate
);
520 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " link:%s",
521 link
== 0 ? "no" : "yes");
523 mvwprintw(screen
, (*voff
)++, 2,
524 "Kernel net/sys statistics for %s (%s%s), t=%lums"
526 ifname
, drvinf
.driver
, buff
, ms_interval
);
529 static void screen_net_dev_rel(WINDOW
*screen
, const struct ifstat
*rel
,
534 mvwprintw(screen
, (*voff
)++, 0,
535 " RX: %16.3llf MiB/t "
539 ((long double) rel
->rx_bytes
) / (1LLU << 20),
540 rel
->rx_packets
, rel
->rx_drops
, rel
->rx_errors
);
542 mvwprintw(screen
, (*voff
)++, 0,
543 " TX: %16.3llf MiB/t "
547 ((long double) rel
->tx_bytes
) / (1LLU << 20),
548 rel
->tx_packets
, rel
->tx_drops
, rel
->tx_errors
);
553 static void screen_net_dev_abs(WINDOW
*screen
, const struct ifstat
*abs
,
556 mvwprintw(screen
, (*voff
)++, 2,
561 ((long double) abs
->rx_bytes
) / (1LLU << 20),
562 abs
->rx_packets
, abs
->rx_drops
, abs
->rx_errors
);
564 mvwprintw(screen
, (*voff
)++, 2,
569 ((long double) abs
->tx_bytes
) / (1LLU << 20),
570 abs
->tx_packets
, abs
->tx_drops
, abs
->tx_errors
);
573 static void screen_sys_mem(WINDOW
*screen
, const struct ifstat
*rel
,
574 const struct ifstat
*abs
, int *voff
)
576 mvwprintw(screen
, (*voff
)++, 2,
582 (100.0 * (abs
->mem_total
- abs
->mem_free
)) / abs
->mem_total
,
583 abs
->procs_run
, abs
->procs_iow
);
586 static void screen_percpu_states(WINDOW
*screen
, const struct ifstat
*rel
,
592 for (i
= 0; i
< cpus
; ++i
) {
593 all
= rel
->cpu_user
[i
] + rel
->cpu_nice
[i
] + rel
->cpu_sys
[i
] +
594 rel
->cpu_idle
[i
] + rel
->cpu_iow
[i
];
596 mvwprintw(screen
, (*voff
)++, 2,
597 "CPU%d: %13.1lf%% usr/t "
600 "%11.1lf%% iow/t ", i
,
601 100.0 * (rel
->cpu_user
[i
] + rel
->cpu_nice
[i
]) / all
,
602 100.0 * rel
->cpu_sys
[i
] / all
,
603 100.0 * rel
->cpu_idle
[i
] / all
,
604 100.0 * rel
->cpu_iow
[i
] / all
);
608 static void screen_percpu_irqs_rel(WINDOW
*screen
, const struct ifstat
*rel
,
613 for (i
= 0; i
< cpus
; ++i
) {
614 mvwprintw(screen
, (*voff
)++, 2,
615 "CPU%d: %14llu irqs/t "
617 "%15llu soirq TX/t ", i
,
624 static void screen_percpu_irqs_abs(WINDOW
*screen
, const struct ifstat
*abs
,
629 for (i
= 0; i
< cpus
; ++i
) {
630 mvwprintw(screen
, (*voff
)++, 2,
631 "CPU%d: %14llu irqs", i
,
636 static void screen_wireless(WINDOW
*screen
, const struct ifstat
*rel
,
637 const struct ifstat
*abs
, int *voff
)
639 if (iswireless(abs
)) {
640 mvwprintw(screen
, (*voff
)++, 2,
641 "LinkQual: %7d/%d (%d/t) ",
643 abs
->wifi
.link_qual_max
,
644 rel
->wifi
.link_qual
);
646 mvwprintw(screen
, (*voff
)++, 2,
647 "Signal: %8d dBm (%d dBm/t) ",
648 abs
->wifi
.signal_level
,
649 rel
->wifi
.signal_level
);
653 static void screen_update(WINDOW
*screen
, const char *ifname
, const struct ifstat
*rel
,
654 const struct ifstat
*abs
, int *first
, uint64_t ms_interval
)
656 int cpus
, voff
= 1, cvoff
= 2;
660 cpus
= get_number_cpus();
661 bug_on(cpus
> MAX_CPUS
);
663 screen_header(screen
, ifname
, &voff
, ms_interval
);
666 screen_net_dev_rel(screen
, rel
, &voff
);
669 screen_net_dev_abs(screen
, abs
, &voff
);
672 screen_sys_mem(screen
, rel
, abs
, &voff
);
675 screen_percpu_states(screen
, rel
, cpus
, &voff
);
678 screen_percpu_irqs_rel(screen
, rel
, cpus
, &voff
);
681 screen_percpu_irqs_abs(screen
, abs
, cpus
, &voff
);
684 screen_wireless(screen
, rel
, abs
, &voff
);
687 mvwprintw(screen
, cvoff
, 2, "Collecting data ...");
690 mvwprintw(screen
, cvoff
, 2, " ");
697 static void screen_end(void)
702 static int screen_main(const char *ifname
, uint64_t ms_interval
)
706 screen_init(&stats_screen
);
710 if (key
== 'q' || key
== 0x1b || key
== KEY_F(10))
713 screen_update(stats_screen
, ifname
, &stats_delta
, &stats_new
,
714 &first
, ms_interval
);
716 stats_sample_generic(ifname
, ms_interval
);
724 static void term_csv(const char *ifname
, const struct ifstat
*rel
,
725 const struct ifstat
*abs
, uint64_t ms_interval
)
729 printf("%ld ", time(0));
731 printf("%llu ", rel
->rx_bytes
);
732 printf("%llu ", rel
->rx_packets
);
733 printf("%llu ", rel
->rx_drops
);
734 printf("%llu ", rel
->rx_errors
);
736 printf("%llu ", abs
->rx_bytes
);
737 printf("%llu ", abs
->rx_packets
);
738 printf("%llu ", abs
->rx_drops
);
739 printf("%llu ", abs
->rx_errors
);
741 printf("%llu ", rel
->tx_bytes
);
742 printf("%llu ", rel
->tx_packets
);
743 printf("%llu ", rel
->tx_drops
);
744 printf("%llu ", rel
->tx_errors
);
746 printf("%llu ", abs
->tx_bytes
);
747 printf("%llu ", abs
->tx_packets
);
748 printf("%llu ", abs
->tx_drops
);
749 printf("%llu ", abs
->tx_errors
);
751 printf("%u ", rel
->cswitch
);
752 printf("%lu ", abs
->mem_free
);
753 printf("%lu ", abs
->mem_total
- abs
->mem_free
);
754 printf("%lu ", abs
->mem_total
);
755 printf("%u ", abs
->procs_run
);
756 printf("%u ", abs
->procs_iow
);
758 cpus
= get_number_cpus();
759 bug_on(cpus
> MAX_CPUS
);
761 for (i
= 0; i
< cpus
; ++i
) {
762 printf("%lu ", rel
->cpu_user
[i
]);
763 printf("%lu ", rel
->cpu_nice
[i
]);
764 printf("%lu ", rel
->cpu_sys
[i
]);
765 printf("%lu ", rel
->cpu_idle
[i
]);
766 printf("%lu ", rel
->cpu_iow
[i
]);
768 printf("%llu ", rel
->irqs
[i
]);
769 printf("%llu ", abs
->irqs
[i
]);
771 printf("%llu ", rel
->irqs_srx
[i
]);
772 printf("%llu ", abs
->irqs_srx
[i
]);
774 printf("%llu ", rel
->irqs_stx
[i
]);
775 printf("%llu ", abs
->irqs_stx
[i
]);
778 if (iswireless(abs
)) {
779 printf("%u ", rel
->wifi
.link_qual
);
780 printf("%u ", abs
->wifi
.link_qual
);
781 printf("%u ", abs
->wifi
.link_qual_max
);
783 printf("%d ", rel
->wifi
.signal_level
);
784 printf("%d ", abs
->wifi
.signal_level
);
791 static void term_csv_header(const char *ifname
, const struct ifstat
*abs
,
792 uint64_t ms_interval
)
796 printf("# gnuplot dump (#col:description)\n");
797 printf("# networking interface: %s\n", ifname
);
798 printf("# sampling interval (t): %lu ms\n", ms_interval
);
799 printf("# %d:unixtime ", j
++);
801 printf("%d:rx-bytes-per-t ", j
++);
802 printf("%d:rx-pkts-per-t ", j
++);
803 printf("%d:rx-drops-per-t ", j
++);
804 printf("%d:rx-errors-per-t ", j
++);
806 printf("%d:rx-bytes ", j
++);
807 printf("%d:rx-pkts ", j
++);
808 printf("%d:rx-drops ", j
++);
809 printf("%d:rx-errors ", j
++);
811 printf("%d:tx-bytes-per-t ", j
++);
812 printf("%d:tx-pkts-per-t ", j
++);
813 printf("%d:tx-drops-per-t ", j
++);
814 printf("%d:tx-errors-per-t ", j
++);
816 printf("%d:tx-bytes ", j
++);
817 printf("%d:tx-pkts ", j
++);
818 printf("%d:tx-drops ", j
++);
819 printf("%d:tx-errors ", j
++);
821 printf("%d:context-switches-per-t ", j
++);
822 printf("%d:mem-free ", j
++);
823 printf("%d:mem-used ", j
++);
824 printf("%d:mem-total ", j
++);
825 printf("%d:procs-in-run ", j
++);
826 printf("%d:procs-in-iow ", j
++);
828 cpus
= get_number_cpus();
829 bug_on(cpus
> MAX_CPUS
);
831 for (i
= 0, j
= 22; i
< cpus
; ++i
) {
832 printf("%d:cpu%i-usr-per-t ", j
++, i
);
833 printf("%d:cpu%i-nice-per-t ", j
++, i
);
834 printf("%d:cpu%i-sys-per-t ", j
++, i
);
835 printf("%d:cpu%i-idle-per-t ", j
++, i
);
836 printf("%d:cpu%i-iow-per-t ", j
++, i
);
838 printf("%d:cpu%i-net-irqs-per-t ", j
++, i
);
839 printf("%d:cpu%i-net-irqs ", j
++, i
);
841 printf("%d:cpu%i-net-rx-soft-irqs-per-t ", j
++, i
);
842 printf("%d:cpu%i-net-rx-soft-irqs ", j
++, i
);
843 printf("%d:cpu%i-net-tx-soft-irqs-per-t ", j
++, i
);
844 printf("%d:cpu%i-net-tx-soft-irqs ", j
++, i
);
847 if (iswireless(abs
)) {
848 printf("%d:wifi-link-qual-per-t ", j
++);
849 printf("%d:wifi-link-qual ", j
++);
850 printf("%d:wifi-link-qual-max ", j
++);
852 printf("%d:wifi-signal-dbm-per-t ", j
++);
853 printf("%d:wifi-signal-dbm ", j
++);
861 static int term_main(const char *ifname
, uint64_t ms_interval
)
866 stats_sample_generic(ifname
, ms_interval
);
870 term_csv_header(ifname
, &stats_new
, ms_interval
);
873 term_csv(ifname
, &stats_delta
, &stats_new
, ms_interval
);
874 } while (stats_loop
&& !sigint
);
879 int main(int argc
, char **argv
)
882 int c
, opt_index
, ret
, promisc
= 0;
883 uint64_t interval
= 1000;
885 int (*func_main
)(const char *ifname
, uint64_t ms_interval
) = screen_main
;
890 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
891 &opt_index
)) != EOF
) {
900 ifname
= xstrndup(optarg
, IFNAMSIZ
);
903 interval
= strtol(optarg
, NULL
, 10);
912 func_main
= term_main
;
918 panic("Option -%c requires an argument!\n",
922 whine("Unknown option character "
923 "`0x%X\'!\n", optopt
);
935 ifname
= xstrndup(argv
[1], IFNAMSIZ
);
937 panic("No networking device given!\n");
939 if (!strncmp("lo", ifname
, IFNAMSIZ
))
940 panic("lo is not supported!\n");
941 if (device_mtu(ifname
) == 0)
942 panic("This is no networking device!\n");
944 register_signal(SIGINT
, signal_handler
);
945 register_signal(SIGHUP
, signal_handler
);
948 ifflags
= enter_promiscuous_mode(ifname
);
949 ret
= func_main(ifname
, interval
);
951 leave_promiscuous_mode(ifname
, ifflags
);