2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009 - 2013 Daniel Borkmann.
4 * Subject to the GPL, version 2.
6 * He had all the injured air of a liar suspected when for once he
7 * has told the truth, or part of it.
9 * -- The Lord of the Rings, On Gollum,
10 * Chapter 'The Black Gate is Closed'.
18 #include <sys/socket.h>
19 #include <sys/fsuid.h>
33 int16_t link_qual
, link_qual_max
;
34 int signal_level
/*, noise_level*/;
38 long long unsigned int rx_bytes
, rx_packets
, rx_drops
, rx_errors
;
39 long long unsigned int rx_fifo
, rx_frame
, rx_multi
;
40 long long unsigned int tx_bytes
, tx_packets
, tx_drops
, tx_errors
;
41 long long unsigned int tx_fifo
, tx_colls
, tx_carrier
;
42 long long unsigned int irqs
[MAX_CPUS
], irqs_srx
[MAX_CPUS
], irqs_stx
[MAX_CPUS
];
43 int64_t cpu_user
[MAX_CPUS
], cpu_nice
[MAX_CPUS
], cpu_sys
[MAX_CPUS
];
44 int64_t cpu_idle
[MAX_CPUS
], cpu_iow
[MAX_CPUS
], mem_free
, mem_total
;
45 uint32_t irq_nr
, procs_run
, procs_iow
, cswitch
, forks
;
46 struct wifi_stat wifi
;
49 volatile sig_atomic_t sigint
= 0;
51 static struct ifstat stats_old
, stats_new
, stats_delta
;
53 static int stats_loop
= 0;
55 static WINDOW
*stats_screen
= NULL
;
57 static const char *short_options
= "d:t:vhclp";
58 static const struct option long_options
[] = {
59 {"dev", required_argument
, NULL
, 'd'},
60 {"interval", required_argument
, NULL
, 't'},
61 {"promisc", no_argument
, NULL
, 'p'},
62 {"csv", no_argument
, NULL
, 'c'},
63 {"loop", no_argument
, NULL
, 'l'},
64 {"version", no_argument
, NULL
, 'v'},
65 {"help", no_argument
, NULL
, 'h'},
69 static void signal_handler(int number
)
81 static inline char *snr_to_str(int level
)
84 return "very good signal";
85 if (level
> 25 && level
<= 40)
87 if (level
> 15 && level
<= 25)
89 if (level
> 10 && level
<= 15)
90 return "very poor signal";
97 static inline int iswireless(const struct ifstat
*stats
)
99 return stats
->wifi
.bitrate
> 0;
102 static void help(void)
104 printf("\nifpps %s, top-like kernel networking and system statistics\n",
106 puts("http://www.netsniff-ng.org\n\n"
107 "Usage: ifpps [options] || ifpps <netdev>\n"
109 " -d|--dev <netdev> Device to fetch statistics for e.g., eth0\n"
110 " -t|--interval <time> Refresh time in ms (default 1000 ms)\n"
111 " -p|--promisc Promiscuous mode\n"
112 " -c|--csv Output to terminal as Gnuplot-ready data\n"
113 " -l|--loop Continuous CSV output\n"
114 " -v|--version Print version\n"
115 " -h|--help Print this help\n\n"
119 " ifpps -lpcd wlan0 > plot.dat\n\n"
121 " On 10G cards, RX/TX statistics are usually accumulated each > 1sec.\n"
122 " Thus, in those situations, it's good to use a -t of 10sec.\n\n"
123 "Please report bugs to <bugs@netsniff-ng.org>\n"
124 "Copyright (C) 2009-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
125 "Swiss federal institute of technology (ETH Zurich)\n"
126 "License: GNU GPL version 2.0\n"
127 "This is free software: you are free to change and redistribute it.\n"
128 "There is NO WARRANTY, to the extent permitted by law.\n");
132 static void version(void)
134 printf("\nifpps %s, top-like kernel networking and system statistics\n",
136 puts("http://www.netsniff-ng.org\n\n"
137 "Please report bugs to <bugs@netsniff-ng.org>\n"
138 "Copyright (C) 2009-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
139 "Swiss federal institute of technology (ETH Zurich)\n"
140 "License: GNU GPL version 2.0\n"
141 "This is free software: you are free to change and redistribute it.\n"
142 "There is NO WARRANTY, to the extent permitted by law.\n");
146 static int stats_proc_net_dev(const char *ifname
, struct ifstat
*stats
)
152 fp
= fopen("/proc/net/dev", "r");
154 panic("Cannot open /proc/net/dev!\n");
156 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
157 if (fgets(buff
, sizeof(buff
), fp
)) { ; }
159 memset(buff
, 0, sizeof(buff
));
161 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
162 buff
[sizeof(buff
) -1] = 0;
164 if (strstr(buff
, ifname
) == NULL
)
167 if (sscanf(buff
, "%*[a-z0-9 .-]:%llu%llu%llu%llu%llu%llu"
168 "%llu%*u%llu%llu%llu%llu%llu%llu%llu",
169 &stats
->rx_bytes
, &stats
->rx_packets
,
170 &stats
->rx_errors
, &stats
->rx_drops
,
171 &stats
->rx_fifo
, &stats
->rx_frame
,
172 &stats
->rx_multi
, &stats
->tx_bytes
,
173 &stats
->tx_packets
, &stats
->tx_errors
,
174 &stats
->tx_drops
, &stats
->tx_fifo
,
175 &stats
->tx_colls
, &stats
->tx_carrier
) == 14) {
180 memset(buff
, 0, sizeof(buff
));
187 static int stats_proc_interrupts(char *ifname
, struct ifstat
*stats
)
189 int ret
= -EINVAL
, i
, cpus
, try = 0;
190 char *ptr
, buff
[256];
191 struct ethtool_drvinfo drvinf
;
194 fp
= fopen("/proc/interrupts", "r");
196 panic("Cannot open /proc/interrupts!\n");
198 cpus
= get_number_cpus();
199 bug_on(cpus
> MAX_CPUS
);
201 fseek(fp
, 0, SEEK_SET
);
202 memset(buff
, 0, sizeof(buff
));
204 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
205 buff
[sizeof(buff
) - 1] = 0;
208 if (strstr(buff
, ifname
) == NULL
)
211 stats
->irq_nr
= strtol(ptr
, &ptr
, 10);
212 bug_on(stats
->irq_nr
== 0);
216 for (i
= 0; i
< cpus
&& ptr
; ++i
) {
217 stats
->irqs
[i
] = strtol(ptr
, &ptr
, 10);
224 memset(buff
, 0, sizeof(buff
));
227 if (ret
== -EINVAL
&& try == 0) {
228 memset(&drvinf
, 0, sizeof(drvinf
));
229 if (ethtool_drvinf(ifname
, &drvinf
) < 0)
232 ifname
= drvinf
.driver
;
242 static int stats_proc_softirqs(struct ifstat
*stats
)
245 char *ptr
, buff
[256];
251 } net_type
= softirqs_net_none
;
253 fp
= fopen("/proc/softirqs", "r");
255 panic("Cannot open /proc/softirqs!\n");
257 cpus
= get_number_cpus();
258 bug_on(cpus
> MAX_CPUS
);
260 memset(buff
, 0, sizeof(buff
));
262 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
263 buff
[sizeof(buff
) - 1] = 0;
265 if ((ptr
= strstr(buff
, "NET_TX:")))
266 net_type
= softirqs_net_tx
;
267 else if ((ptr
= strstr(buff
, "NET_RX:")))
268 net_type
= softirqs_net_rx
;
272 for (ptr
+= strlen("NET_xX:"), i
= 0; i
< cpus
; ++i
) {
274 case softirqs_net_tx
:
275 stats
->irqs_stx
[i
] = strtol(ptr
, &ptr
, 10);
277 case softirqs_net_rx
:
278 stats
->irqs_srx
[i
] = strtol(ptr
, &ptr
, 10);
285 memset(buff
, 0, sizeof(buff
));
292 static int stats_proc_memory(struct ifstat
*stats
)
294 char *ptr
, buff
[256];
297 fp
= fopen("/proc/meminfo", "r");
299 panic("Cannot open /proc/meminfo!\n");
301 memset(buff
, 0, sizeof(buff
));
303 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
304 buff
[sizeof(buff
) - 1] = 0;
306 if ((ptr
= strstr(buff
, "MemTotal:"))) {
307 ptr
+= strlen("MemTotal:");
308 stats
->mem_total
= strtol(ptr
, &ptr
, 10);
309 } else if ((ptr
= strstr(buff
, "MemFree:"))) {
310 ptr
+= strlen("MemFree:");
311 stats
->mem_free
= strtol(ptr
, &ptr
, 10);
314 memset(buff
, 0, sizeof(buff
));
321 static int stats_proc_system(struct ifstat
*stats
)
324 char *ptr
, buff
[256];
327 fp
= fopen("/proc/stat", "r");
329 panic("Cannot open /proc/stat!\n");
331 cpus
= get_number_cpus();
332 bug_on(cpus
> MAX_CPUS
);
334 memset(buff
, 0, sizeof(buff
));
336 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
337 buff
[sizeof(buff
) - 1] = 0;
339 if ((ptr
= strstr(buff
, "cpu"))) {
340 ptr
+= strlen("cpu");
344 cpu
= strtol(ptr
, &ptr
, 10);
347 if (sscanf(ptr
, "%lu%lu%lu%lu%lu",
348 &stats
->cpu_user
[cpu
],
349 &stats
->cpu_nice
[cpu
],
350 &stats
->cpu_sys
[cpu
],
351 &stats
->cpu_idle
[cpu
],
352 &stats
->cpu_iow
[cpu
]) != 5)
354 } else if ((ptr
= strstr(buff
, "ctxt"))) {
355 ptr
+= strlen("ctxt");
356 stats
->cswitch
= strtoul(ptr
, &ptr
, 10);
357 } else if ((ptr
= strstr(buff
, "processes"))) {
358 ptr
+= strlen("processes");
359 stats
->forks
= strtoul(ptr
, &ptr
, 10);
360 } else if ((ptr
= strstr(buff
, "procs_running"))) {
361 ptr
+= strlen("procs_running");
362 stats
->procs_run
= strtoul(ptr
, &ptr
, 10);
363 } else if ((ptr
= strstr(buff
, "procs_blocked"))) {
364 ptr
+= strlen("procs_blocked");
365 stats
->procs_iow
= strtoul(ptr
, &ptr
, 10);
368 memset(buff
, 0, sizeof(buff
));
375 static int adjust_dbm_level(int in_dbm
, int dbm_val
)
380 return dbm_val
- 0x100;
383 static int stats_wireless(const char *ifname
, struct ifstat
*stats
)
386 struct iw_statistics ws
;
388 ret
= wireless_sigqual(ifname
, &ws
);
390 stats
->wifi
.bitrate
= 0;
394 stats
->wifi
.bitrate
= wireless_bitrate(ifname
);
396 stats
->wifi
.signal_level
=
397 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.level
);
399 stats
->wifi
.link_qual
= ws
.qual
.qual
;
400 stats
->wifi
.link_qual_max
= wireless_rangemax_sigqual(ifname
);
405 #define DIFF1(member) do { diff->member = new->member - old->member; } while (0)
406 #define DIFF(member) do { \
407 if (sizeof(diff->member) != sizeof(new->member) || \
408 sizeof(diff->member) != sizeof(old->member)) \
410 bug_on((new->member - old->member) > (new->member)); \
414 static void stats_diff(struct ifstat
*old
, struct ifstat
*new,
439 DIFF1(wifi
.signal_level
);
440 DIFF1(wifi
.link_qual
);
445 cpus
= get_number_cpus();
446 bug_on(cpus
> MAX_CPUS
);
448 for (i
= 0; i
< cpus
; ++i
) {
461 static void stats_fetch(const char *ifname
, struct ifstat
*stats
)
463 if (stats_proc_net_dev(ifname
, stats
) < 0)
464 panic("Cannot fetch device stats!\n");
465 if (stats_proc_softirqs(stats
) < 0)
466 panic("Cannot fetch software interrupts!\n");
467 if (stats_proc_memory(stats
) < 0)
468 panic("Cannot fetch memory stats!\n");
469 if (stats_proc_system(stats
) < 0)
470 panic("Cannot fetch system stats!\n");
472 stats_proc_interrupts((char *) ifname
, stats
);
474 stats_wireless(ifname
, stats
);
477 static void stats_sample_generic(const char *ifname
, uint64_t ms_interval
)
479 memset(&stats_old
, 0, sizeof(stats_old
));
480 memset(&stats_new
, 0, sizeof(stats_new
));
481 memset(&stats_delta
, 0, sizeof(stats_delta
));
483 stats_fetch(ifname
, &stats_old
);
484 usleep(ms_interval
* 1000);
485 stats_fetch(ifname
, &stats_new
);
487 stats_diff(&stats_old
, &stats_new
, &stats_delta
);
490 static void screen_init(WINDOW
**screen
)
492 (*screen
) = initscr();
497 nodelay((*screen
), TRUE
);
499 keypad(stdscr
, TRUE
);
505 static void screen_header(WINDOW
*screen
, const char *ifname
, int *voff
,
506 uint64_t ms_interval
)
510 struct ethtool_drvinfo drvinf
;
511 u32 rate
= device_bitrate(ifname
);
512 int link
= ethtool_link(ifname
);
514 memset(&drvinf
, 0, sizeof(drvinf
));
515 ethtool_drvinf(ifname
, &drvinf
);
517 memset(buff
, 0, sizeof(buff
));
519 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " %uMbit/s", rate
);
521 len
+= snprintf(buff
+ len
, sizeof(buff
) - len
, " link:%s",
522 link
== 0 ? "no" : "yes");
524 mvwprintw(screen
, (*voff
)++, 2,
525 "Kernel net/sys statistics for %s (%s%s), t=%lums"
527 ifname
, drvinf
.driver
, buff
, ms_interval
);
530 static void screen_net_dev_rel(WINDOW
*screen
, const struct ifstat
*rel
,
535 mvwprintw(screen
, (*voff
)++, 0,
536 " RX: %16.3llf MiB/t "
540 ((long double) rel
->rx_bytes
) / (1LLU << 20),
541 rel
->rx_packets
, rel
->rx_drops
, rel
->rx_errors
);
543 mvwprintw(screen
, (*voff
)++, 0,
544 " TX: %16.3llf MiB/t "
548 ((long double) rel
->tx_bytes
) / (1LLU << 20),
549 rel
->tx_packets
, rel
->tx_drops
, rel
->tx_errors
);
554 static void screen_net_dev_abs(WINDOW
*screen
, const struct ifstat
*abs
,
557 mvwprintw(screen
, (*voff
)++, 2,
562 ((long double) abs
->rx_bytes
) / (1LLU << 20),
563 abs
->rx_packets
, abs
->rx_drops
, abs
->rx_errors
);
565 mvwprintw(screen
, (*voff
)++, 2,
570 ((long double) abs
->tx_bytes
) / (1LLU << 20),
571 abs
->tx_packets
, abs
->tx_drops
, abs
->tx_errors
);
574 static void screen_sys_mem(WINDOW
*screen
, const struct ifstat
*rel
,
575 const struct ifstat
*abs
, int *voff
)
577 mvwprintw(screen
, (*voff
)++, 2,
583 (100.0 * (abs
->mem_total
- abs
->mem_free
)) / abs
->mem_total
,
584 abs
->procs_run
, abs
->procs_iow
);
587 static void screen_percpu_states(WINDOW
*screen
, const struct ifstat
*rel
,
593 for (i
= 0; i
< cpus
; ++i
) {
594 all
= rel
->cpu_user
[i
] + rel
->cpu_nice
[i
] + rel
->cpu_sys
[i
] +
595 rel
->cpu_idle
[i
] + rel
->cpu_iow
[i
];
597 mvwprintw(screen
, (*voff
)++, 2,
598 "CPU%d: %13.1lf%% usr/t "
601 "%11.1lf%% iow/t ", i
,
602 100.0 * (rel
->cpu_user
[i
] + rel
->cpu_nice
[i
]) / all
,
603 100.0 * rel
->cpu_sys
[i
] / all
,
604 100.0 * rel
->cpu_idle
[i
] / all
,
605 100.0 * rel
->cpu_iow
[i
] / all
);
609 static void screen_percpu_irqs_rel(WINDOW
*screen
, const struct ifstat
*rel
,
614 for (i
= 0; i
< cpus
; ++i
) {
615 mvwprintw(screen
, (*voff
)++, 2,
616 "CPU%d: %14llu irqs/t "
618 "%15llu soirq TX/t ", i
,
625 static void screen_percpu_irqs_abs(WINDOW
*screen
, const struct ifstat
*abs
,
630 for (i
= 0; i
< cpus
; ++i
) {
631 mvwprintw(screen
, (*voff
)++, 2,
632 "CPU%d: %14llu irqs", i
,
637 static void screen_wireless(WINDOW
*screen
, const struct ifstat
*rel
,
638 const struct ifstat
*abs
, int *voff
)
640 if (iswireless(abs
)) {
641 mvwprintw(screen
, (*voff
)++, 2,
642 "LinkQual: %7d/%d (%d/t) ",
644 abs
->wifi
.link_qual_max
,
645 rel
->wifi
.link_qual
);
647 mvwprintw(screen
, (*voff
)++, 2,
648 "Signal: %8d dBm (%d dBm/t) ",
649 abs
->wifi
.signal_level
,
650 rel
->wifi
.signal_level
);
654 static void screen_update(WINDOW
*screen
, const char *ifname
, const struct ifstat
*rel
,
655 const struct ifstat
*abs
, int *first
, uint64_t ms_interval
)
657 int cpus
, voff
= 1, cvoff
= 2;
661 cpus
= get_number_cpus();
662 bug_on(cpus
> MAX_CPUS
);
664 screen_header(screen
, ifname
, &voff
, ms_interval
);
667 screen_net_dev_rel(screen
, rel
, &voff
);
670 screen_net_dev_abs(screen
, abs
, &voff
);
673 screen_sys_mem(screen
, rel
, abs
, &voff
);
676 screen_percpu_states(screen
, rel
, cpus
, &voff
);
679 screen_percpu_irqs_rel(screen
, rel
, cpus
, &voff
);
682 screen_percpu_irqs_abs(screen
, abs
, cpus
, &voff
);
685 screen_wireless(screen
, rel
, abs
, &voff
);
688 mvwprintw(screen
, cvoff
, 2, "Collecting data ...");
691 mvwprintw(screen
, cvoff
, 2, " ");
698 static void screen_end(void)
703 static int screen_main(const char *ifname
, uint64_t ms_interval
)
707 screen_init(&stats_screen
);
711 if (key
== 'q' || key
== 0x1b || key
== KEY_F(10))
714 screen_update(stats_screen
, ifname
, &stats_delta
, &stats_new
,
715 &first
, ms_interval
);
717 stats_sample_generic(ifname
, ms_interval
);
725 static void term_csv(const char *ifname
, const struct ifstat
*rel
,
726 const struct ifstat
*abs
, uint64_t ms_interval
)
730 printf("%ld ", time(0));
732 printf("%llu ", rel
->rx_bytes
);
733 printf("%llu ", rel
->rx_packets
);
734 printf("%llu ", rel
->rx_drops
);
735 printf("%llu ", rel
->rx_errors
);
737 printf("%llu ", abs
->rx_bytes
);
738 printf("%llu ", abs
->rx_packets
);
739 printf("%llu ", abs
->rx_drops
);
740 printf("%llu ", abs
->rx_errors
);
742 printf("%llu ", rel
->tx_bytes
);
743 printf("%llu ", rel
->tx_packets
);
744 printf("%llu ", rel
->tx_drops
);
745 printf("%llu ", rel
->tx_errors
);
747 printf("%llu ", abs
->tx_bytes
);
748 printf("%llu ", abs
->tx_packets
);
749 printf("%llu ", abs
->tx_drops
);
750 printf("%llu ", abs
->tx_errors
);
752 printf("%u ", rel
->cswitch
);
753 printf("%lu ", abs
->mem_free
);
754 printf("%lu ", abs
->mem_total
- abs
->mem_free
);
755 printf("%lu ", abs
->mem_total
);
756 printf("%u ", abs
->procs_run
);
757 printf("%u ", abs
->procs_iow
);
759 cpus
= get_number_cpus();
760 bug_on(cpus
> MAX_CPUS
);
762 for (i
= 0; i
< cpus
; ++i
) {
763 printf("%lu ", rel
->cpu_user
[i
]);
764 printf("%lu ", rel
->cpu_nice
[i
]);
765 printf("%lu ", rel
->cpu_sys
[i
]);
766 printf("%lu ", rel
->cpu_idle
[i
]);
767 printf("%lu ", rel
->cpu_iow
[i
]);
769 printf("%llu ", rel
->irqs
[i
]);
770 printf("%llu ", abs
->irqs
[i
]);
772 printf("%llu ", rel
->irqs_srx
[i
]);
773 printf("%llu ", abs
->irqs_srx
[i
]);
775 printf("%llu ", rel
->irqs_stx
[i
]);
776 printf("%llu ", abs
->irqs_stx
[i
]);
779 if (iswireless(abs
)) {
780 printf("%u ", rel
->wifi
.link_qual
);
781 printf("%u ", abs
->wifi
.link_qual
);
782 printf("%u ", abs
->wifi
.link_qual_max
);
784 printf("%d ", rel
->wifi
.signal_level
);
785 printf("%d ", abs
->wifi
.signal_level
);
792 static void term_csv_header(const char *ifname
, const struct ifstat
*abs
,
793 uint64_t ms_interval
)
797 printf("# gnuplot dump (#col:description)\n");
798 printf("# networking interface: %s\n", ifname
);
799 printf("# sampling interval (t): %lu ms\n", ms_interval
);
800 printf("# %d:unixtime ", j
++);
802 printf("%d:rx-bytes-per-t ", j
++);
803 printf("%d:rx-pkts-per-t ", j
++);
804 printf("%d:rx-drops-per-t ", j
++);
805 printf("%d:rx-errors-per-t ", j
++);
807 printf("%d:rx-bytes ", j
++);
808 printf("%d:rx-pkts ", j
++);
809 printf("%d:rx-drops ", j
++);
810 printf("%d:rx-errors ", j
++);
812 printf("%d:tx-bytes-per-t ", j
++);
813 printf("%d:tx-pkts-per-t ", j
++);
814 printf("%d:tx-drops-per-t ", j
++);
815 printf("%d:tx-errors-per-t ", j
++);
817 printf("%d:tx-bytes ", j
++);
818 printf("%d:tx-pkts ", j
++);
819 printf("%d:tx-drops ", j
++);
820 printf("%d:tx-errors ", j
++);
822 printf("%d:context-switches-per-t ", j
++);
823 printf("%d:mem-free ", j
++);
824 printf("%d:mem-used ", j
++);
825 printf("%d:mem-total ", j
++);
826 printf("%d:procs-in-run ", j
++);
827 printf("%d:procs-in-iow ", j
++);
829 cpus
= get_number_cpus();
830 bug_on(cpus
> MAX_CPUS
);
832 for (i
= 0, j
= 22; i
< cpus
; ++i
) {
833 printf("%d:cpu%i-usr-per-t ", j
++, i
);
834 printf("%d:cpu%i-nice-per-t ", j
++, i
);
835 printf("%d:cpu%i-sys-per-t ", j
++, i
);
836 printf("%d:cpu%i-idle-per-t ", j
++, i
);
837 printf("%d:cpu%i-iow-per-t ", j
++, i
);
839 printf("%d:cpu%i-net-irqs-per-t ", j
++, i
);
840 printf("%d:cpu%i-net-irqs ", j
++, i
);
842 printf("%d:cpu%i-net-rx-soft-irqs-per-t ", j
++, i
);
843 printf("%d:cpu%i-net-rx-soft-irqs ", j
++, i
);
844 printf("%d:cpu%i-net-tx-soft-irqs-per-t ", j
++, i
);
845 printf("%d:cpu%i-net-tx-soft-irqs ", j
++, i
);
848 if (iswireless(abs
)) {
849 printf("%d:wifi-link-qual-per-t ", j
++);
850 printf("%d:wifi-link-qual ", j
++);
851 printf("%d:wifi-link-qual-max ", j
++);
853 printf("%d:wifi-signal-dbm-per-t ", j
++);
854 printf("%d:wifi-signal-dbm ", j
++);
862 static int term_main(const char *ifname
, uint64_t ms_interval
)
867 stats_sample_generic(ifname
, ms_interval
);
871 term_csv_header(ifname
, &stats_new
, ms_interval
);
874 term_csv(ifname
, &stats_delta
, &stats_new
, ms_interval
);
875 } while (stats_loop
&& !sigint
);
880 int main(int argc
, char **argv
)
883 int c
, opt_index
, ret
, promisc
= 0;
884 uint64_t interval
= 1000;
886 int (*func_main
)(const char *ifname
, uint64_t ms_interval
) = screen_main
;
891 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
892 &opt_index
)) != EOF
) {
901 ifname
= xstrndup(optarg
, IFNAMSIZ
);
904 interval
= strtol(optarg
, NULL
, 10);
913 func_main
= term_main
;
919 panic("Option -%c requires an argument!\n",
923 printf("Unknown option character `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
);