[Iftop-users] [PATCH 4/4] Keep track of lost packets as reported by pcap_stats
fred at fperrin.net
fred at fperrin.net
Thu Apr 23 11:12:40 BST 2015
From: Frédéric Perrin <fperrin at brocade.com>
On my machine, if I generate the following IPv6 flood:
ip -6 neigh add fe80::1234 dev eth0 lladdr 00:11:22:33:44:55
nc -6 -u fe80::1234%eth0 1234 < /dev/zero
The traffic reported by iftop is much less than the reality, as iftop
can't read packets off pcap fast enough. This patch only demonstrate
the problem, I haven't started to dig into the cause yet.
---
iftop.c | 5 +++++
iftop.h | 1 +
tui.c | 5 +++++
ui.c | 4 +++-
4 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/iftop.c b/iftop.c
index 1640b11..562a45b 100644
--- a/iftop.c
+++ b/iftop.c
@@ -109,6 +109,8 @@ history_type* history_create() {
void history_rotate() {
hash_node_type* n = NULL;
+ struct pcap_stat ps;
+
history_pos = (history_pos + 1) % HISTORY_LENGTH;
hash_next_item(history, &n);
while(n != NULL) {
@@ -134,6 +136,9 @@ void history_rotate() {
if(history_len < HISTORY_LENGTH) {
history_len++;
}
+
+ pcap_stats(pd, &ps);
+ history_totals.lost_packets = ps.ps_drop + ps.ps_ifdrop;
}
diff --git a/iftop.h b/iftop.h
index f273c0f..e5279d1 100644
--- a/iftop.h
+++ b/iftop.h
@@ -28,6 +28,7 @@ typedef struct {
long sent[HISTORY_LENGTH];
double long total_sent;
double long total_recv;
+ long lost_packets;
int last_write;
} history_type;
diff --git a/tui.c b/tui.c
index 75c6e08..ebf7b4f 100644
--- a/tui.c
+++ b/tui.c
@@ -153,6 +153,11 @@ void tui_print() {
readable_size(history_totals.total_recv + history_totals.total_sent, buf2_10, 10, 1024, 1);
printf("%s %10s %10s %10s\n", labellong, buf0_10, buf1_10, buf2_10);
+ /* Dropped packets */
+ snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Dropped packets:");
+ readable_size(history_totals.lost_packets, buf0_10, 10, 1024, options.bandwidth_unit);
+ printf("%s %10s\n", labellong, buf0_10, buf1_10, buf2_10);
+
/* Double divider line */
for (j = 0; j < PRINT_WIDTH + 52; j++) {
printf("=");
diff --git a/ui.c b/ui.c
index 771be31..37bf3d5 100644
--- a/ui.c
+++ b/ui.c
@@ -400,7 +400,9 @@ void ui_print() {
readable_size(peakrecv / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
mvaddstr(y+1, 39, line);
- readable_size(peaktotal / RESOLUTION, line, 10, 1024, options.bandwidth_unit);
+ /* lost packets */
+ mvaddstr(y+2, 32, "lost: ");
+ readable_size(history_totals.lost_packets, line, 10, 1000, OPTION_BW_PKTS);
mvaddstr(y+2, 39, line);
mvaddstr(y, COLS - 8 * HISTORY_DIVISIONS - 8, "rates:");
--
2.3.5
More information about the iftop-users
mailing list