2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009 - 2012 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 CSV\n"
122 " E.g. post-processing with Gnuplot et al.\n"
123 " -l|--loop Continuous CSV output\n"
124 " -v|--version Print version\n"
125 " -h|--help Print this help\n\n"
129 " ifpps -lpcd wlan0 > plot.dat\n\n"
130 "Please report bugs to <bugs@netsniff-ng.org>\n"
131 "Copyright (C) 2009-2012 Daniel Borkmann <daniel@netsniff-ng.org>\n"
132 "License: GNU GPL version 2.0\n"
133 "This is free software: you are free to change and redistribute it.\n"
134 "There is NO WARRANTY, to the extent permitted by law.\n");
138 static void version(void)
140 printf("\nifpps %s, top-like kernel networking and system statistics\n",
142 puts("http://www.netsniff-ng.org\n\n"
143 "Please report bugs to <bugs@netsniff-ng.org>\n"
144 "Copyright (C) 2009-2012 Daniel Borkmann <daniel@netsniff-ng.org>\n"
145 "License: GNU GPL version 2.0\n"
146 "This is free software: you are free to change and redistribute it.\n"
147 "There is NO WARRANTY, to the extent permitted by law.\n");
151 static int stats_proc_net_dev(const char *ifname
, struct ifstat
*stats
)
157 fp
= fopen("/proc/net/dev", "r");
159 panic("Cannot open /proc/net/dev!\n");
161 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
162 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
164 memset(buff
, 0, sizeof(buff
));
166 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
167 buff
[sizeof(buff
) -1] = 0;
169 if (strstr(buff
, ifname
) == NULL
)
172 if (sscanf(buff
, "%*[a-z0-9 .-]:%llu%llu%llu%llu%llu%llu"
173 "%llu%*u%llu%llu%llu%llu%llu%llu%llu",
174 &stats
->rx_bytes
, &stats
->rx_packets
,
175 &stats
->rx_errors
, &stats
->rx_drops
,
176 &stats
->rx_fifo
, &stats
->rx_frame
,
177 &stats
->rx_multi
, &stats
->tx_bytes
,
178 &stats
->tx_packets
, &stats
->tx_errors
,
179 &stats
->tx_drops
, &stats
->tx_fifo
,
180 &stats
->tx_colls
, &stats
->tx_carrier
) == 14) {
185 memset(buff
, 0, sizeof(buff
));
192 static int stats_proc_interrupts(char *ifname
, struct ifstat
*stats
)
194 int ret
= -EINVAL
, i
, cpus
, try = 0;
195 char *ptr
, buff
[256];
196 struct ethtool_drvinfo drvinf
;
199 fp
= fopen("/proc/interrupts", "r");
201 panic("Cannot open /proc/interrupts!\n");
203 cpus
= get_number_cpus();
204 bug_on(cpus
> MAX_CPUS
);
206 fseek(fp
, 0, SEEK_SET
);
207 memset(buff
, 0, sizeof(buff
));
209 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
210 buff
[sizeof(buff
) - 1] = 0;
213 if (strstr(buff
, ifname
) == NULL
)
216 stats
->irq_nr
= strtol(ptr
, &ptr
, 10);
217 bug_on(stats
->irq_nr
== 0);
221 for (i
= 0; i
< cpus
&& ptr
; ++i
) {
222 stats
->irqs
[i
] = strtol(ptr
, &ptr
, 10);
229 memset(buff
, 0, sizeof(buff
));
232 if (ret
== -EINVAL
&& try == 0) {
233 memset(&drvinf
, 0, sizeof(drvinf
));
234 if (ethtool_drvinf(ifname
, &drvinf
) < 0)
237 ifname
= drvinf
.driver
;
247 static int stats_proc_softirqs(struct ifstat
*stats
)
250 char *ptr
, buff
[256];
256 } net_type
= softirqs_net_none
;
258 fp
= fopen("/proc/softirqs", "r");
260 panic("Cannot open /proc/softirqs!\n");
262 cpus
= get_number_cpus();
263 bug_on(cpus
> MAX_CPUS
);
265 memset(buff
, 0, sizeof(buff
));
267 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
268 buff
[sizeof(buff
) - 1] = 0;
270 if ((ptr
= strstr(buff
, "NET_TX:")))
271 net_type
= softirqs_net_tx
;
272 else if ((ptr
= strstr(buff
, "NET_RX:")))
273 net_type
= softirqs_net_rx
;
277 for (ptr
+= strlen("NET_xX:"), i
= 0; i
< cpus
; ++i
) {
279 case softirqs_net_tx
:
280 stats
->irqs_stx
[i
] = strtol(ptr
, &ptr
, 10);
282 case softirqs_net_rx
:
283 stats
->irqs_srx
[i
] = strtol(ptr
, &ptr
, 10);
290 memset(buff
, 0, sizeof(buff
));
297 static int stats_proc_memory(struct ifstat
*stats
)
299 char *ptr
, buff
[256];
302 fp
= fopen("/proc/meminfo", "r");
304 panic("Cannot open /proc/meminfo!\n");
306 memset(buff
, 0, sizeof(buff
));
308 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
309 buff
[sizeof(buff
) - 1] = 0;
311 if ((ptr
= strstr(buff
, "MemTotal:"))) {
312 ptr
+= strlen("MemTotal:");
313 stats
->mem_total
= strtol(ptr
, &ptr
, 10);
314 } else if ((ptr
= strstr(buff
, "MemFree:"))) {
315 ptr
+= strlen("MemFree:");
316 stats
->mem_free
= strtol(ptr
, &ptr
, 10);
319 memset(buff
, 0, sizeof(buff
));
326 static int stats_proc_system(struct ifstat
*stats
)
329 char *ptr
, buff
[256];
332 fp
= fopen("/proc/stat", "r");
334 panic("Cannot open /proc/stat!\n");
336 cpus
= get_number_cpus();
337 bug_on(cpus
> MAX_CPUS
);
339 memset(buff
, 0, sizeof(buff
));
341 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
342 buff
[sizeof(buff
) - 1] = 0;
344 if ((ptr
= strstr(buff
, "cpu"))) {
345 ptr
+= strlen("cpu");
349 cpu
= strtol(ptr
, &ptr
, 10);
352 if (sscanf(ptr
, "%lu%lu%lu%lu%lu",
353 &stats
->cpu_user
[cpu
],
354 &stats
->cpu_nice
[cpu
],
355 &stats
->cpu_sys
[cpu
],
356 &stats
->cpu_idle
[cpu
],
357 &stats
->cpu_iow
[cpu
]) != 5)
359 } else if ((ptr
= strstr(buff
, "ctxt"))) {
360 ptr
+= strlen("ctxt");
361 stats
->cswitch
= strtoul(ptr
, &ptr
, 10);
362 } else if ((ptr
= strstr(buff
, "processes"))) {
363 ptr
+= strlen("processes");
364 stats
->forks
= strtoul(ptr
, &ptr
, 10);
365 } else if ((ptr
= strstr(buff
, "procs_running"))) {
366 ptr
+= strlen("procs_running");
367 stats
->procs_run
= strtoul(ptr
, &ptr
, 10);
368 } else if ((ptr
= strstr(buff
, "procs_blocked"))) {
369 ptr
+= strlen("procs_blocked");
370 stats
->procs_iow
= strtoul(ptr
, &ptr
, 10);
373 memset(buff
, 0, sizeof(buff
));
380 static int stats_wireless(const char *ifname
, struct ifstat
*stats
)
383 struct iw_statistics ws
;
385 ret
= wireless_sigqual(ifname
, &ws
);
387 stats
->wifi
.bitrate
= 0;
391 stats
->wifi
.bitrate
= wireless_bitrate(ifname
);
393 stats
->wifi
.signal_level
=
394 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.level
);
396 stats
->wifi
.link_qual
= ws
.qual
.qual
;
397 stats
->wifi
.link_qual_max
= wireless_rangemax_sigqual(ifname
);
402 #define DIFF1(member) do { diff->member = new->member - old->member; } while (0)
403 #define DIFF(member) do { \
404 if (sizeof(diff->member) != sizeof(new->member) || \
405 sizeof(diff->member) != sizeof(old->member)) \
407 bug_on((new->member - old->member) > (new->member)); \
411 static void stats_diff(struct ifstat
*old
, struct ifstat
*new,
436 DIFF1(wifi
.signal_level
);
437 DIFF1(wifi
.link_qual
);
442 cpus
= get_number_cpus();
443 bug_on(cpus
> MAX_CPUS
);
445 for (i
= 0; i
< cpus
; ++i
) {
458 static void stats_fetch(const char *ifname
, struct ifstat
*stats
)
460 if (stats_proc_net_dev(ifname
, stats
) < 0)
461 panic("Cannot fetch device stats!\n");
462 if (stats_proc_softirqs(stats
) < 0)
463 panic("Cannot fetch software interrupts!\n");
464 if (stats_proc_memory(stats
) < 0)
465 panic("Cannot fetch memory stats!\n");
466 if (stats_proc_system(stats
) < 0)
467 panic("Cannot fetch system stats!\n");
469 stats_proc_interrupts((char *) ifname
, stats
);
471 stats_wireless(ifname
, stats
);
474 static void stats_sample_generic(const char *ifname
, uint64_t ms_interval
)
476 memset(&stats_old
, 0, sizeof(stats_old
));
477 memset(&stats_new
, 0, sizeof(stats_new
));
478 memset(&stats_delta
, 0, sizeof(stats_delta
));
480 stats_fetch(ifname
, &stats_old
);
481 usleep(ms_interval
* 1000);
482 stats_fetch(ifname
, &stats_new
);
484 stats_diff(&stats_old
, &stats_new
, &stats_delta
);
487 static void screen_init(WINDOW
**screen
)
489 (*screen
) = initscr();
494 nodelay((*screen
), TRUE
);
496 keypad(stdscr
, TRUE
);
502 static void screen_header(WINDOW
*screen
, const char *ifname
, int *voff
,
503 uint64_t ms_interval
)
507 struct ethtool_drvinfo drvinf
;
508 u32 rate
= device_bitrate(ifname
);
509 int link
= ethtool_link(ifname
);
511 memset(&drvinf
, 0, sizeof(drvinf
));
512 ethtool_drvinf(ifname
, &drvinf
);
514 memset(buff
, 0, sizeof(buff
));
516 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " %uMbit/s", rate
);
518 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " link:%s",
519 link
== 0 ? "no" : "yes");
521 mvwprintw(screen
, (*voff
)++, 2,
522 "Kernel net/sys statistics for %s (%s%s), t=%lums"
524 ifname
, drvinf
.driver
, buff
, ms_interval
);
527 static void screen_net_dev_rel(WINDOW
*screen
, const struct ifstat
*rel
,
532 mvwprintw(screen
, (*voff
)++, 0,
533 " RX: %16.3llf MiB/t "
537 ((long double) rel
->rx_bytes
) / (1LLU << 20),
538 rel
->rx_packets
, rel
->rx_drops
, rel
->rx_errors
);
540 mvwprintw(screen
, (*voff
)++, 0,
541 " TX: %16.3llf MiB/t "
545 ((long double) rel
->tx_bytes
) / (1LLU << 20),
546 rel
->tx_packets
, rel
->tx_drops
, rel
->tx_errors
);
551 static void screen_net_dev_abs(WINDOW
*screen
, const struct ifstat
*abs
,
554 mvwprintw(screen
, (*voff
)++, 2,
559 ((long double) abs
->rx_bytes
) / (1LLU << 20),
560 abs
->rx_packets
, abs
->rx_drops
, abs
->rx_errors
);
562 mvwprintw(screen
, (*voff
)++, 2,
567 ((long double) abs
->tx_bytes
) / (1LLU << 20),
568 abs
->tx_packets
, abs
->tx_drops
, abs
->tx_errors
);
571 static void screen_sys_mem(WINDOW
*screen
, const struct ifstat
*rel
,
572 const struct ifstat
*abs
, int *voff
)
574 mvwprintw(screen
, (*voff
)++, 2,
580 (100.0 * (abs
->mem_total
- abs
->mem_free
)) / abs
->mem_total
,
581 abs
->procs_run
, abs
->procs_iow
);
584 static void screen_percpu_states(WINDOW
*screen
, const struct ifstat
*rel
,
590 for (i
= 0; i
< cpus
; ++i
) {
591 all
= rel
->cpu_user
[i
] + rel
->cpu_nice
[i
] + rel
->cpu_sys
[i
] +
592 rel
->cpu_idle
[i
] + rel
->cpu_iow
[i
];
594 mvwprintw(screen
, (*voff
)++, 2,
595 "CPU%d: %13.1lf%% usr/t "
598 "%11.1lf%% iow/t ", i
,
599 100.0 * (rel
->cpu_user
[i
] + rel
->cpu_nice
[i
]) / all
,
600 100.0 * rel
->cpu_sys
[i
] / all
,
601 100.0 * rel
->cpu_idle
[i
] / all
,
602 100.0 * rel
->cpu_iow
[i
] / all
);
606 static void screen_percpu_irqs_rel(WINDOW
*screen
, const struct ifstat
*rel
,
611 for (i
= 0; i
< cpus
; ++i
) {
612 mvwprintw(screen
, (*voff
)++, 2,
613 "CPU%d: %14llu irqs/t "
615 "%15llu soirq TX/t ", i
,
622 static void screen_percpu_irqs_abs(WINDOW
*screen
, const struct ifstat
*abs
,
627 for (i
= 0; i
< cpus
; ++i
) {
628 mvwprintw(screen
, (*voff
)++, 2,
629 "CPU%d: %14llu irqs", i
,
634 static void screen_wireless(WINDOW
*screen
, const struct ifstat
*rel
,
635 const struct ifstat
*abs
, int *voff
)
637 if (iswireless(abs
)) {
638 mvwprintw(screen
, (*voff
)++, 2,
639 "LinkQual: %7d/%d (%d/t) ",
641 abs
->wifi
.link_qual_max
,
642 rel
->wifi
.link_qual
);
644 mvwprintw(screen
, (*voff
)++, 2,
645 "Signal: %8d dBm (%d dBm/t) ",
646 abs
->wifi
.signal_level
,
647 rel
->wifi
.signal_level
);
651 static void screen_update(WINDOW
*screen
, const char *ifname
, const struct ifstat
*rel
,
652 const struct ifstat
*abs
, int *first
, uint64_t ms_interval
)
654 int cpus
, voff
= 1, cvoff
= 2;
658 cpus
= get_number_cpus();
659 bug_on(cpus
> MAX_CPUS
);
661 screen_header(screen
, ifname
, &voff
, ms_interval
);
664 screen_net_dev_rel(screen
, rel
, &voff
);
667 screen_net_dev_abs(screen
, abs
, &voff
);
670 screen_sys_mem(screen
, rel
, abs
, &voff
);
673 screen_percpu_states(screen
, rel
, cpus
, &voff
);
676 screen_percpu_irqs_rel(screen
, rel
, cpus
, &voff
);
679 screen_percpu_irqs_abs(screen
, abs
, cpus
, &voff
);
682 screen_wireless(screen
, rel
, abs
, &voff
);
685 mvwprintw(screen
, cvoff
, 2, "Collecting data ...");
688 mvwprintw(screen
, cvoff
, 2, " ");
695 static void screen_end(void)
700 static int screen_main(const char *ifname
, uint64_t ms_interval
)
704 screen_init(&stats_screen
);
708 if (key
== 'q' || key
== 0x1b || key
== KEY_F(10))
711 screen_update(stats_screen
, ifname
, &stats_delta
, &stats_new
,
712 &first
, ms_interval
);
714 stats_sample_generic(ifname
, ms_interval
);
722 static void term_csv(const char *ifname
, const struct ifstat
*rel
,
723 const struct ifstat
*abs
, uint64_t ms_interval
)
727 printf("%ld ", time(0));
729 printf("%llu ", rel
->rx_bytes
);
730 printf("%llu ", rel
->rx_packets
);
731 printf("%llu ", rel
->rx_drops
);
732 printf("%llu ", rel
->rx_errors
);
734 printf("%llu ", abs
->rx_bytes
);
735 printf("%llu ", abs
->rx_packets
);
736 printf("%llu ", abs
->rx_drops
);
737 printf("%llu ", abs
->rx_errors
);
739 printf("%llu ", rel
->tx_bytes
);
740 printf("%llu ", rel
->tx_packets
);
741 printf("%llu ", rel
->tx_drops
);
742 printf("%llu ", rel
->tx_errors
);
744 printf("%llu ", abs
->tx_bytes
);
745 printf("%llu ", abs
->tx_packets
);
746 printf("%llu ", abs
->tx_drops
);
747 printf("%llu ", abs
->tx_errors
);
749 printf("%u ", rel
->cswitch
);
750 printf("%lu ", abs
->mem_free
);
751 printf("%lu ", abs
->mem_total
- abs
->mem_free
);
752 printf("%lu ", abs
->mem_total
);
753 printf("%u ", abs
->procs_run
);
754 printf("%u ", abs
->procs_iow
);
756 cpus
= get_number_cpus();
757 bug_on(cpus
> MAX_CPUS
);
759 for (i
= 0; i
< cpus
; ++i
) {
760 printf("%lu ", rel
->cpu_user
[i
]);
761 printf("%lu ", rel
->cpu_nice
[i
]);
762 printf("%lu ", rel
->cpu_sys
[i
]);
763 printf("%lu ", rel
->cpu_idle
[i
]);
764 printf("%lu ", rel
->cpu_iow
[i
]);
766 printf("%llu ", rel
->irqs
[i
]);
767 printf("%llu ", abs
->irqs
[i
]);
769 printf("%llu ", rel
->irqs_srx
[i
]);
770 printf("%llu ", abs
->irqs_srx
[i
]);
772 printf("%llu ", rel
->irqs_stx
[i
]);
773 printf("%llu ", abs
->irqs_stx
[i
]);
776 if (iswireless(abs
)) {
777 printf("%u ", rel
->wifi
.link_qual
);
778 printf("%u ", abs
->wifi
.link_qual
);
779 printf("%u ", abs
->wifi
.link_qual_max
);
781 printf("%d ", rel
->wifi
.signal_level
);
782 printf("%d ", abs
->wifi
.signal_level
);
789 static void term_csv_header(const char *ifname
, const struct ifstat
*abs
,
790 uint64_t ms_interval
)
794 printf("# gnuplot dump (#col:description)\n");
795 printf("# networking interface: %s\n", ifname
);
796 printf("# sampling interval (t): %lu ms\n", ms_interval
);
797 printf("# %d:unixtime ", j
++);
799 printf("%d:rx-bytes-per-t ", j
++);
800 printf("%d:rx-pkts-per-t ", j
++);
801 printf("%d:rx-drops-per-t ", j
++);
802 printf("%d:rx-errors-per-t ", j
++);
804 printf("%d:rx-bytes ", j
++);
805 printf("%d:rx-pkts ", j
++);
806 printf("%d:rx-drops ", j
++);
807 printf("%d:rx-errors ", j
++);
809 printf("%d:tx-bytes-per-t ", j
++);
810 printf("%d:tx-pkts-per-t ", j
++);
811 printf("%d:tx-drops-per-t ", j
++);
812 printf("%d:tx-errors-per-t ", j
++);
814 printf("%d:tx-bytes ", j
++);
815 printf("%d:tx-pkts ", j
++);
816 printf("%d:tx-drops ", j
++);
817 printf("%d:tx-errors ", j
++);
819 printf("%d:context-switches-per-t ", j
++);
820 printf("%d:mem-free ", j
++);
821 printf("%d:mem-used ", j
++);
822 printf("%d:mem-total ", j
++);
823 printf("%d:procs-in-run ", j
++);
824 printf("%d:procs-in-iow ", j
++);
826 cpus
= get_number_cpus();
827 bug_on(cpus
> MAX_CPUS
);
829 for (i
= 0, j
= 22; i
< cpus
; ++i
) {
830 printf("%d:cpu%i-usr-per-t ", j
++, i
);
831 printf("%d:cpu%i-nice-per-t ", j
++, i
);
832 printf("%d:cpu%i-sys-per-t ", j
++, i
);
833 printf("%d:cpu%i-idle-per-t ", j
++, i
);
834 printf("%d:cpu%i-iow-per-t ", j
++, i
);
836 printf("%d:cpu%i-net-irqs-per-t ", j
++, i
);
837 printf("%d:cpu%i-net-irqs ", j
++, i
);
839 printf("%d:cpu%i-net-rx-soft-irqs-per-t ", j
++, i
);
840 printf("%d:cpu%i-net-rx-soft-irqs ", j
++, i
);
841 printf("%d:cpu%i-net-tx-soft-irqs-per-t ", j
++, i
);
842 printf("%d:cpu%i-net-tx-soft-irqs ", j
++, i
);
845 if (iswireless(abs
)) {
846 printf("%d:wifi-link-qual-per-t ", j
++);
847 printf("%d:wifi-link-qual ", j
++);
848 printf("%d:wifi-link-qual-max ", j
++);
850 printf("%d:wifi-signal-dbm-per-t ", j
++);
851 printf("%d:wifi-signal-dbm ", j
++);
859 static int term_main(const char *ifname
, uint64_t ms_interval
)
864 stats_sample_generic(ifname
, ms_interval
);
868 term_csv_header(ifname
, &stats_new
, ms_interval
);
871 term_csv(ifname
, &stats_delta
, &stats_new
, ms_interval
);
872 } while (stats_loop
&& !sigint
);
877 int main(int argc
, char **argv
)
880 int c
, opt_index
, ret
, promisc
= 0;
881 uint64_t interval
= 1000;
883 int (*func_main
)(const char *ifname
, uint64_t ms_interval
) = screen_main
;
888 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
889 &opt_index
)) != EOF
) {
898 ifname
= xstrndup(optarg
, IFNAMSIZ
);
901 interval
= strtol(optarg
, NULL
, 10);
910 func_main
= term_main
;
916 panic("Option -%c requires an argument!\n",
920 whine("Unknown option character "
921 "`0x%X\'!\n", optopt
);
933 ifname
= xstrndup(argv
[1], IFNAMSIZ
);
935 panic("No networking device given!\n");
937 if (!strncmp("lo", ifname
, IFNAMSIZ
))
938 panic("lo is not supported!\n");
939 if (device_mtu(ifname
) == 0)
940 panic("This is no networking device!\n");
942 register_signal(SIGINT
, signal_handler
);
943 register_signal(SIGHUP
, signal_handler
);
946 ifflags
= enter_promiscuous_mode(ifname
);
947 ret
= func_main(ifname
, interval
);
949 leave_promiscuous_mode(ifname
, ifflags
);