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>
41 int16_t link_qual
, link_qual_max
;
42 int signal_level
, noise_level
;
43 char driver_name
[IFNAMSIZ
];
48 uint64_t rx_bytes
, rx_packets
, rx_drops
, rx_errors
;
49 uint64_t rx_fifo
, rx_frame
, rx_multi
;
50 uint64_t tx_bytes
, tx_packets
, tx_drops
, tx_errors
;
51 uint64_t tx_fifo
, tx_colls
, tx_carrier
;
52 uint64_t irqs
[MAX_CPUS
], irqs_srx
[MAX_CPUS
], irqs_stx
[MAX_CPUS
];
53 int64_t cpu_user
[MAX_CPUS
], cpu_nice
[MAX_CPUS
], cpu_sys
[MAX_CPUS
];
54 int64_t cpu_idle
[MAX_CPUS
], cpu_iow
[MAX_CPUS
];
55 int32_t cswitch
, forks
, procs_run
, procs_iow
;
56 int64_t mem_free
, mem_total
;
57 struct wifi_stat wifi
;
60 volatile sig_atomic_t sigint
= 0;
62 static struct ifstat stats_old
, stats_new
, stats_delta
;
64 static int stats_loop
= 0;
66 static WINDOW
*stats_screen
= NULL
;
68 static const char *short_options
= "d:t:vhclp";
69 static const struct option long_options
[] = {
70 {"dev", required_argument
, NULL
, 'd'},
71 {"interval", required_argument
, NULL
, 't'},
72 {"promisc", no_argument
, NULL
, 'p'},
73 {"csv", no_argument
, NULL
, 'c'},
74 {"loop", no_argument
, NULL
, 'l'},
75 {"version", no_argument
, NULL
, 'v'},
76 {"help", no_argument
, NULL
, 'h'},
80 static void signal_handler(int number
)
92 static inline char *snr_to_str(int level
)
95 return "very good signal";
96 if (level
> 25 && level
<= 40)
98 if (level
> 15 && level
<= 25)
100 if (level
> 10 && level
<= 15)
101 return "very poor signal";
108 static inline int iswireless(const struct ifstat
*stats
)
110 return stats
->wifi
.bitrate
> 0;
113 static void help(void)
115 printf("\nifpps %s, top-like kernel networking and system statistics\n",
117 puts("http://www.netsniff-ng.org\n\n"
118 "Usage: ifpps [options] || ifpps <netdev>\n"
120 " -d|--dev <netdev> Device to fetch statistics for e.g., eth0\n"
121 " -t|--interval <time> Refresh time in ms (default 500 ms)\n"
122 " -p|--promisc Promiscuous mode\n"
123 " -c|--csv Output to terminal as CSV\n"
124 " E.g. post-processing with Gnuplot et al.\n"
125 " -l|--loop Continuous CSV output\n"
126 " -v|--version Print version\n"
127 " -h|--help Print this help\n\n"
131 " ifpps -lpcd wlan0 > plot.dat\n\n"
132 "Please report bugs to <bugs@netsniff-ng.org>\n"
133 "Copyright (C) 2009-2012 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-2012 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 /* Omit table header from procfs file */
164 if (fgets(buff
, sizeof(buff
), fp
));
165 if (fgets(buff
, sizeof(buff
), fp
));
167 memset(buff
, 0, sizeof(buff
));
169 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
170 buff
[sizeof(buff
) -1] = 0;
172 if (strstr(buff
, ifname
) == NULL
)
175 if (sscanf(buff
, "%*[a-z0-9 .-]:%lu%lu%lu%lu%lu%lu"
176 "%lu%*u%lu%lu%lu%lu%lu%lu%lu",
177 &stats
->rx_bytes
, &stats
->rx_packets
,
178 &stats
->rx_errors
, &stats
->rx_drops
,
179 &stats
->rx_fifo
, &stats
->rx_frame
,
180 &stats
->rx_multi
, &stats
->tx_bytes
,
181 &stats
->tx_packets
, &stats
->tx_errors
,
182 &stats
->tx_drops
, &stats
->tx_fifo
,
183 &stats
->tx_colls
, &stats
->tx_carrier
) == 14) {
188 memset(buff
, 0, sizeof(buff
));
195 static int stats_proc_interrupts(char *ifname
, struct ifstat
*stats
)
197 int ret
= -EINVAL
, i
, cpus
, try = 0;
198 char *ptr
, buff
[256];
199 struct ethtool_drvinfo drvinf
;
202 fp
= fopen("/proc/interrupts", "r");
204 panic("Cannot open /proc/interrupts!\n");
206 cpus
= get_number_cpus();
207 bug_on(cpus
> MAX_CPUS
);
209 fseek(fp
, 0, SEEK_SET
);
210 memset(buff
, 0, sizeof(buff
));
212 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
213 buff
[sizeof(buff
) - 1] = 0;
216 if (strstr(buff
, ifname
) == NULL
)
219 stats
->irq_nr
= strtol(ptr
, &ptr
, 10);
220 bug_on(stats
->irq_nr
== 0);
223 ptr
++; /* Skip ':' char */
224 for (i
= 0; i
< cpus
&& ptr
; ++i
) {
225 stats
->irqs
[i
] = strtol(ptr
, &ptr
, 10);
232 memset(buff
, 0, sizeof(buff
));
235 /* We could get caught here in case of wireless devices which
236 * are not necessarily listed under 'wlan0' et al. in
237 * proc/interrupts. Therefore, we try once again with the
238 * ethtool driver name.
240 if (ret
== -EINVAL
&& try == 0) {
241 memset(&drvinf
, 0, sizeof(drvinf
));
242 if (ethtool_drvinf(ifname
, &drvinf
) < 0)
245 ifname
= drvinf
.driver
;
255 static int stats_proc_softirqs(struct ifstat
*stats
)
258 char *ptr
, buff
[256];
264 } net_type
= softirqs_net_none
;
266 fp
= fopen("/proc/softirqs", "r");
268 panic("Cannot open /proc/softirqs!\n");
270 cpus
= get_number_cpus();
271 bug_on(cpus
> MAX_CPUS
);
273 memset(buff
, 0, sizeof(buff
));
275 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
276 buff
[sizeof(buff
) - 1] = 0;
278 if ((ptr
= strstr(buff
, "NET_TX:")))
279 net_type
= softirqs_net_tx
;
280 else if ((ptr
= strstr(buff
, "NET_RX:")))
281 net_type
= softirqs_net_rx
;
285 for (ptr
+= strlen("NET_xX:"), i
= 0; i
< cpus
; ++i
) {
287 case softirqs_net_tx
:
288 stats
->irqs_stx
[i
] = strtol(ptr
, &ptr
, 10);
290 case softirqs_net_rx
:
291 stats
->irqs_srx
[i
] = strtol(ptr
, &ptr
, 10);
298 memset(buff
, 0, sizeof(buff
));
305 static int stats_proc_memory(struct ifstat
*stats
)
307 char *ptr
, buff
[256];
310 fp
= fopen("/proc/meminfo", "r");
312 panic("Cannot open /proc/meminfo!\n");
314 memset(buff
, 0, sizeof(buff
));
316 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
317 buff
[sizeof(buff
) - 1] = 0;
319 if ((ptr
= strstr(buff
, "MemTotal:"))) {
320 ptr
+= strlen("MemTotal:");
321 stats
->mem_total
= strtol(ptr
, &ptr
, 10);
322 } else if ((ptr
= strstr(buff
, "MemFree:"))) {
323 ptr
+= strlen("MemFree:");
324 stats
->mem_free
= strtol(ptr
, &ptr
, 10);
327 memset(buff
, 0, sizeof(buff
));
334 static int stats_proc_system(struct ifstat
*stats
)
337 char *ptr
, buff
[256];
340 fp
= fopen("/proc/stat", "r");
342 panic("Cannot open /proc/stat!\n");
344 cpus
= get_number_cpus();
345 bug_on(cpus
> MAX_CPUS
);
347 memset(buff
, 0, sizeof(buff
));
349 while (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
350 buff
[sizeof(buff
) - 1] = 0;
352 if ((ptr
= strstr(buff
, "cpu"))) {
353 ptr
+= strlen("cpu");
357 cpu
= strtol(ptr
, &ptr
, 10);
360 if (sscanf(ptr
, "%lu%lu%lu%lu%lu",
361 &stats
->cpu_user
[cpu
],
362 &stats
->cpu_nice
[cpu
],
363 &stats
->cpu_sys
[cpu
],
364 &stats
->cpu_idle
[cpu
],
365 &stats
->cpu_iow
[cpu
]) != 5)
367 } else if ((ptr
= strstr(buff
, "ctxt"))) {
368 ptr
+= strlen("ctxt");
369 stats
->cswitch
= strtol(ptr
, &ptr
, 10);
370 } else if ((ptr
= strstr(buff
, "processes"))) {
371 ptr
+= strlen("processes");
372 stats
->forks
= strtol(ptr
, &ptr
, 10);
373 } else if ((ptr
= strstr(buff
, "procs_running"))) {
374 ptr
+= strlen("procs_running");
375 stats
->procs_run
= strtol(ptr
, &ptr
, 10);
376 } else if ((ptr
= strstr(buff
, "procs_blocked"))) {
377 ptr
+= strlen("procs_blocked");
378 stats
->procs_iow
= strtol(ptr
, &ptr
, 10);
381 memset(buff
, 0, sizeof(buff
));
388 static int stats_wireless(const char *ifname
, struct ifstat
*stats
)
391 struct iw_statistics ws
;
393 ret
= wireless_sigqual(ifname
, &ws
);
395 stats
->wifi
.bitrate
= 0;
399 stats
->wifi
.bitrate
= wireless_bitrate(ifname
);
401 stats
->wifi
.signal_level
=
402 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.level
);
403 stats
->wifi
.noise_level
=
404 adjust_dbm_level(ws
.qual
.updated
& IW_QUAL_DBM
, ws
.qual
.noise
);
406 stats
->wifi
.link_qual
= ws
.qual
.qual
;
407 stats
->wifi
.link_qual_max
= wireless_rangemax_sigqual(ifname
);
412 #define DIFF1(member) do { diff->member = new->member - old->member; } while (0)
413 #define DIFF(member) do { \
414 if (sizeof(diff->member) != sizeof(new->member) || \
415 sizeof(diff->member) != sizeof(old->member)) \
417 bug_on((new->member - old->member) > (new->member)); \
421 static void stats_diff(struct ifstat
*old
, struct ifstat
*new,
446 DIFF1(wifi
.signal_level
);
447 DIFF1(wifi
.noise_level
);
449 DIFF1(wifi
.link_qual
);
454 cpus
= get_number_cpus();
455 bug_on(cpus
> MAX_CPUS
);
457 for (i
= 0; i
< cpus
; ++i
) {
470 static void stats_fetch(const char *ifname
, struct ifstat
*stats
)
472 if (stats_proc_net_dev(ifname
, stats
) < 0)
473 panic("Cannot fetch device stats!\n");
474 if (stats_proc_softirqs(stats
) < 0)
475 panic("Cannot fetch software interrupts!\n");
476 if (stats_proc_memory(stats
) < 0)
477 panic("Cannot fetch memory stats!\n");
478 if (stats_proc_system(stats
) < 0)
479 panic("Cannot fetch system stats!\n");
481 stats_proc_interrupts((char *) ifname
, stats
);
483 stats_wireless(ifname
, stats
);
486 static void stats_sample_generic(const char *ifname
, uint64_t ms_interval
)
488 memset(&stats_old
, 0, sizeof(stats_old
));
489 memset(&stats_new
, 0, sizeof(stats_new
));
490 memset(&stats_delta
, 0, sizeof(stats_delta
));
492 stats_fetch(ifname
, &stats_old
);
493 usleep(ms_interval
* 1000);
494 stats_fetch(ifname
, &stats_new
);
496 stats_diff(&stats_old
, &stats_new
, &stats_delta
);
499 static void screen_init(WINDOW
**screen
)
501 (*screen
) = initscr();
504 nodelay((*screen
), TRUE
);
509 static void screen_update(WINDOW
*screen
, const char *ifname
, const struct ifstat
*rel
,
510 const struct ifstat
*abs
, int *first
, uint64_t ms_interval
)
517 cpus
= get_number_cpus();
518 bug_on(cpus
> MAX_CPUS
);
520 mvwprintw(screen
, 1, 2, "Kernel net/sys statistics for %s, t=%lums", ifname
, ms_interval
);
523 mvwprintw(screen
, 3, 0, " RX: %16.3lf MiB/t %10lu pkts/t %10lu drops/t %10lu errors/t ",
524 1.0 * rel
->rx_bytes
/ (1 << 20), rel
->rx_packets
, rel
->rx_drops
, rel
->rx_errors
);
525 mvwprintw(screen
, 4, 0, " TX: %16.3lf MiB/t %10lu pkts/t %10lu drops/t %10lu errors/t ",
526 1.0 * rel
->tx_bytes
/ (1 << 20), rel
->tx_packets
, rel
->tx_drops
, rel
->tx_errors
);
529 mvwprintw(screen
, 6, 2, "RX: %16.3lf MiB %10lu pkts %10lu drops %10lu errors",
530 1.0 * abs
->rx_bytes
/ (1 << 20), abs
->rx_packets
, abs
->rx_drops
, abs
->rx_errors
);
531 mvwprintw(screen
, 7, 2, "TX: %16.3lf MiB %10lu pkts %10lu drops %10lu errors",
532 1.0 * abs
->tx_bytes
/ (1 << 20), abs
->tx_packets
, abs
->tx_drops
, abs
->tx_errors
);
534 mvwprintw(screen
, 9, 2, "SYS: %14ld cs/t %10.1lf%% mem %13ld running %10ld iowait",
535 rel
->cswitch
, 100.0 * (abs
->mem_total
- abs
->mem_free
) / abs
->mem_total
,
536 abs
->procs_run
, abs
->procs_iow
);
538 for(i
= 0, j
= 11; i
< cpus
; ++i
) {
539 all
= rel
->cpu_user
[i
] + rel
->cpu_nice
[i
] + rel
->cpu_sys
[i
] + rel
->cpu_idle
[i
] + rel
->cpu_iow
[i
];
541 mvwprintw(screen
, j
++, 2, "CPU%d: %13.1f%% usr/t %9.1f%% sys/t %10.1f%% idl/t %11.1f%% iow/t ",
542 i
, 100.f
* (rel
->cpu_user
[i
] + rel
->cpu_nice
[i
]) / all
, 100.f
* rel
->cpu_sys
[i
] / all
,
543 100.f
* rel
->cpu_idle
[i
] / all
, 100.f
* rel
->cpu_iow
[i
] / all
);
546 for(i
= 0, j
++; i
< cpus
; ++i
) {
547 mvwprintw(screen
, j
++, 2, "CPU%d: %14ld irqs/t %15ld soirq RX/t %15ld soirq TX/t ",
548 i
, rel
->irqs
[i
], rel
->irqs_srx
[i
], rel
->irqs_stx
[i
]);
551 for(i
= 0, j
++; i
< cpus
; ++i
) {
552 mvwprintw(screen
, j
++, 2, "CPU%d: %14ld irqs", i
, abs
->irqs
[i
]);
556 if (iswireless(abs
)) {
557 mvwprintw(screen
, j
++, 2, "LinkQual: %7d/%d (%d/t) ",
558 abs
->wifi
.link_qual
, abs
->wifi
.link_qual_max
, rel
->wifi
.link_qual
);
560 mvwprintw(screen
, j
++, 2, "Signal: %8d dBm (%d dBm/t) ",
561 abs
->wifi
.signal_level
, rel
->wifi
.signal_level
);
563 mvwprintw(screen
, j
++, 2, "Noise: %8d dBm (%d dBm/t) ",
564 abs
->wifi
.noise_level
, rel
->wifi
.noise_level
);
565 mvwprintw(screen
, j
++, 2, "SNR: %8d dBm (%s) ",
566 abs
->wifi
.signal_level
- abs
->wifi
.noise_level
,
567 snr_to_str(abs
->wifi
.signal_level
- abs
->wifi
.noise_level
));
572 mvwprintw(screen
, 2, 2, "Collecting data ...");
575 mvwprintw(screen
, 2, 2, " ");
582 static void screen_end(void)
587 static int screen_main(const char *ifname
, uint64_t ms_interval
)
591 screen_init(&stats_screen
);
597 screen_update(stats_screen
, ifname
, &stats_delta
, &stats_new
,
598 &first
, ms_interval
);
600 stats_sample_generic(ifname
, ms_interval
);
608 static void term_csv(const char *ifname
, const struct ifstat
*rel
,
609 const struct ifstat
*abs
, uint64_t ms_interval
)
613 printf("%ld ", time(0));
615 printf("%lu ", rel
->rx_bytes
);
616 printf("%lu ", rel
->rx_packets
);
617 printf("%lu ", rel
->rx_drops
);
618 printf("%lu ", rel
->rx_errors
);
620 printf("%lu ", abs
->rx_bytes
);
621 printf("%lu ", abs
->rx_packets
);
622 printf("%lu ", abs
->rx_drops
);
623 printf("%lu ", abs
->rx_errors
);
625 printf("%lu ", rel
->tx_bytes
);
626 printf("%lu ", rel
->tx_packets
);
627 printf("%lu ", rel
->tx_drops
);
628 printf("%lu ", rel
->tx_errors
);
630 printf("%lu ", abs
->tx_bytes
);
631 printf("%lu ", abs
->tx_packets
);
632 printf("%lu ", abs
->tx_drops
);
633 printf("%lu ", abs
->tx_errors
);
635 printf("%u ", rel
->cswitch
);
636 printf("%lu ", abs
->mem_free
);
637 printf("%lu ", abs
->mem_total
- abs
->mem_free
);
638 printf("%lu ", abs
->mem_total
);
639 printf("%u ", abs
->procs_run
);
640 printf("%u ", abs
->procs_iow
);
642 cpus
= get_number_cpus();
643 bug_on(cpus
> MAX_CPUS
);
645 for (i
= 0; i
< cpus
; ++i
) {
646 printf("%lu ", rel
->cpu_user
[i
]);
647 printf("%lu ", rel
->cpu_nice
[i
]);
648 printf("%lu ", rel
->cpu_sys
[i
]);
649 printf("%lu ", rel
->cpu_idle
[i
]);
650 printf("%lu ", rel
->cpu_iow
[i
]);
652 printf("%lu ", rel
->irqs
[i
]);
653 printf("%lu ", abs
->irqs
[i
]);
655 printf("%lu ", rel
->irqs_srx
[i
]);
656 printf("%lu ", abs
->irqs_srx
[i
]);
658 printf("%lu ", rel
->irqs_stx
[i
]);
659 printf("%lu ", abs
->irqs_stx
[i
]);
662 if (iswireless(abs
)) {
663 printf("%u ", rel
->wifi
.link_qual
);
664 printf("%u ", abs
->wifi
.link_qual
);
665 printf("%u ", abs
->wifi
.link_qual_max
);
667 printf("%d ", rel
->wifi
.signal_level
);
668 printf("%d ", abs
->wifi
.signal_level
);
670 printf("%d ", rel
->wifi
.noise_level
);
671 printf("%d ", abs
->wifi
.noise_level
);
678 static void term_csv_header(const char *ifname
, const struct ifstat
*stats
,
679 const struct ifstat
*curr
, uint64_t ms_interval
)
683 printf("# gnuplot dump (#col:description)\n");
684 printf("# sampling interval (t): %lu ms\n", ms_interval
);
685 printf("# %d:unixtime ", j
++);
687 printf("%d:rx-bytes-per-t ", j
++);
688 printf("%d:rx-pkts-per-t ", j
++);
689 printf("%d:rx-drops-per-t ", j
++);
690 printf("%d:rx-errors-per-t ", j
++);
692 printf("%d:rx-bytes ", j
++);
693 printf("%d:rx-pkts ", j
++);
694 printf("%d:rx-drops ", j
++);
695 printf("%d:rx-errors ", j
++);
697 printf("%d:tx-bytes-per-t ", j
++);
698 printf("%d:tx-pkts-per-t ", j
++);
699 printf("%d:tx-drops-per-t ", j
++);
700 printf("%d:tx-errors-per-t ", j
++);
702 printf("%d:tx-bytes ", j
++);
703 printf("%d:tx-pkts ", j
++);
704 printf("%d:tx-drops ", j
++);
705 printf("%d:tx-errors ", j
++);
707 printf("%d:context-switches-per-t ", j
++);
708 printf("%d:mem-free ", j
++);
709 printf("%d:mem-used ", j
++);
710 printf("%d:mem-total ", j
++);
711 printf("%d:procs-in-run ", j
++);
712 printf("%d:procs-in-iow ", j
++);
714 cpus
= get_number_cpus();
715 bug_on(cpus
> MAX_CPUS
);
717 for (i
= 0, j
= 22; i
< cpus
; ++i
) {
718 printf("%d:cpu%i-usr-per-t ", j
++, i
);
719 printf("%d:cpu%i-nice-per-t ", j
++, i
);
720 printf("%d:cpu%i-sys-per-t ", j
++, i
);
721 printf("%d:cpu%i-idle-per-t ", j
++, i
);
722 printf("%d:cpu%i-iow-per-t ", j
++, i
);
724 printf("%d:cpu%i-net-irqs-per-t ", j
++, i
);
725 printf("%d:cpu%i-net-irqs ", j
++, i
);
727 printf("%d:cpu%i-net-rx-soft-irqs-per-t ", j
++, i
);
728 printf("%d:cpu%i-net-rx-soft-irqs ", j
++, i
);
729 printf("%d:cpu%i-net-tx-soft-irqs-per-t ", j
++, i
);
730 printf("%d:cpu%i-net-tx-soft-irqs ", j
++, i
);
733 if (iswireless(curr
)) {
734 printf("%d:wifi-link-qual-per-t ", j
++);
735 printf("%d:wifi-link-qual ", j
++);
736 printf("%d:wifi-link-qual-max ", j
++);
738 printf("%d:wifi-signal-dbm-per-t ", j
++);
739 printf("%d:wifi-signal-dbm ", j
++);
741 printf("%d:wifi-noise-dbm-per-t ", j
++);
742 printf("%d:wifi-noise-dbm ", j
++);
750 static int term_main(const char *ifname
, uint64_t ms_interval
)
755 stats_sample_generic(ifname
, ms_interval
);
759 term_csv_header(ifname
, &stats_delta
, &stats_new
,
763 term_csv(ifname
, &stats_delta
, &stats_new
, ms_interval
);
764 } while (stats_loop
&& !sigint
);
769 int main(int argc
, char **argv
)
772 int c
, opt_index
, ret
, promisc
= 0;
773 uint64_t interval
= 1000;
775 int (*func_main
)(const char *ifname
, uint64_t ms_interval
) = screen_main
;
777 while ((c
= getopt_long(argc
, argv
, short_options
, long_options
,
778 &opt_index
)) != EOF
) {
787 ifname
= xstrndup(optarg
, IFNAMSIZ
);
790 interval
= strtol(optarg
, NULL
, 10);
799 func_main
= term_main
;
805 panic("Option -%c requires an argument!\n",
809 whine("Unknown option character "
810 "`0x%X\'!\n", optopt
);
822 ifname
= xstrndup(argv
[1], IFNAMSIZ
);
824 panic("No networking device given!\n");
826 if (!strncmp("lo", ifname
, IFNAMSIZ
))
827 panic("lo is not supported!\n");
828 if (device_mtu(ifname
) == 0)
829 panic("This is no networking device!\n");
831 register_signal(SIGINT
, signal_handler
);
832 register_signal(SIGHUP
, signal_handler
);
835 ifflags
= enter_promiscuous_mode(ifname
);
836 ret
= func_main(ifname
, interval
);
838 leave_promiscuous_mode(ifname
, ifflags
);