]> gitweb.fperrin.net Git - iftop.git/commitdiff
Keep track of lost packets as reported by pcap_stats for-upstream
authorFrédéric Perrin <fperrin@brocade.com>
Wed, 1 Apr 2015 16:16:47 +0000 (17:16 +0100)
committerFrédéric Perrin <fperrin@brocasde.com>
Thu, 23 Apr 2015 09:47:51 +0000 (09:47 +0000)
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
iftop.h
tui.c
ui.c

diff --git a/iftop.c b/iftop.c
index 1640b11ffbb67aaaa0f4db48d1b16cbe31d5825f..562a45bd33b719b9a5b77e85fa3001748c2c558a 100644 (file)
--- 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 f273c0f6088f997673ac2e9193a6e39b8279b148..e5279d172625c6ad3206dfdd4deb7ba9b0807abb 100644 (file)
--- 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 75c6e08c15eeab7eaccdb57ae6fd344842f2de22..ebf7b4fd03af9f64e1752d02bf750b4ba9179c62 100644 (file)
--- 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 771be3155b2094b306f69416e8056442f0cf9737..37bf3d515c6aa2ecf86bd39bd4f102bd747a0d20 100644 (file)
--- 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:");