From bill at nonick.org Sun Feb 7 17:16:33 2021 From: bill at nonick.org (Bill Nickless) Date: Sun, 7 Feb 2021 09:16:33 -0800 Subject: [Iftop-users] [PATCH] Support passively sniffing IPv6 Message-ID: Support passively sniffing and displaying IPv6 traffic, previously silently ignored. Also submitted: https://github.com/gdm85/iftop/pull/1 Signed-off-by: Bill Nickless --- iftop.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iftop.c b/iftop.c index 311401e..5e829f9 100644 --- a/iftop.c +++ b/iftop.c @@ -352,6 +352,13 @@ static void handle_ip_packet(struct ip* iptr, int hw_dir, int pld_len) assign_addr_pair(&ap, iptr, 0); direction = 0; } + else if(IP_V(iptr) == 6 && memcmp(&ip6tr->ip6_src, + &ip6tr->ip6_dst, + sizeof(struct in6_addr)) < 0) { + assign_addr_pair(&ap, iptr, 1); + } else if(IP_V(iptr) == 6) { + assign_addr_pair(&ap, iptr, 0); + } /* Drop other uncertain packages. */ else return; -- 2.25.1 -------------- next part -------------- An HTML attachment was scrubbed... URL: From bill at nonick.org Mon Feb 8 00:10:22 2021 From: bill at nonick.org (Bill Nickless) Date: Sun, 7 Feb 2021 16:10:22 -0800 Subject: [Iftop-users] [PATCH] Fix -Wformat-truncation warnings Message-ID: Fix -Wformat-truncation warnings and get rid of the magic constant 9 in tui.c. Also available at https://github.com/wknickless/iftop/commit/6f5c565a5fdaf127cfcdc236c22fdc96a398a599 Signed-off-by: Bill Nickless --- tui.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tui.c b/tui.c index af10a2f..59221a5 100644 --- a/tui.c +++ b/tui.c @@ -34,6 +34,7 @@ /* Width of the host column in the output */ #define PRINT_WIDTH 40 +#define PRINT_WIDTH_LONG 49 /* @@ -55,7 +56,7 @@ void tui_print() { if (!labellong) { xfree(labellong); - labellong = (char *)calloc(PRINT_WIDTH + 1 + 9, 1); + labellong = (char *)calloc(PRINT_WIDTH_LONG + 1, 1); } if (options.paused ) { @@ -63,7 +64,7 @@ void tui_print() { } /* Headings */ - snprintf(label, PRINT_WIDTH, "%-*s", PRINT_WIDTH, "Host name (port/service if enabled)"); + snprintf(label, PRINT_WIDTH + 1, "%-*s", PRINT_WIDTH, "Host name (port/service if enabled)"); printf("%s %s %10s %10s %10s %10s\n", " #", label, "last 2s", "last 10s", "last 40s", "cumulative"); /* Divider line */ @@ -112,21 +113,21 @@ void tui_print() { printf("\n"); /* Rate totals */ - snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send rate:"); + snprintf(labellong, PRINT_WIDTH_LONG + 1, "%-*s", PRINT_WIDTH_LONG, "Total send rate:"); printf("%s ", labellong); for(j = 0; j < HISTORY_DIVISIONS; j++) { readable_size(((host_pair_line *)&totals)->sent[j], buf0_10, 10, 1024, options.bandwidth_unit); printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' '); } - snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total receive rate:"); + snprintf(labellong, PRINT_WIDTH_LONG + 1, "%-*s", PRINT_WIDTH_LONG, "Total receive rate:"); printf("%s ", labellong); for(j = 0; j < HISTORY_DIVISIONS; j++) { readable_size(((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit); printf("%10s%c", buf0_10, j == HISTORY_DIVISIONS - 1 ? '\n' : ' '); } - snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Total send and receive rate:"); + snprintf(labellong, PRINT_WIDTH_LONG + 1, "%-*s", PRINT_WIDTH_LONG, "Total send and receive rate:"); printf("%s ", labellong); for(j = 0; j < HISTORY_DIVISIONS; j++) { readable_size(((host_pair_line *)&totals)->sent[j] + ((host_pair_line *)&totals)->recv[j], buf0_10, 10, 1024, options.bandwidth_unit); @@ -140,14 +141,14 @@ void tui_print() { printf("\n"); /* Peak traffic */ - snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Peak rate (sent/received/total):"); + snprintf(labellong, PRINT_WIDTH_LONG + 1, "%-*s", PRINT_WIDTH_LONG, "Peak rate (sent/received/total):"); readable_size(peaksent / RESOLUTION, buf0_10, 10, 1024, options.bandwidth_unit); readable_size(peakrecv / RESOLUTION, buf1_10, 10, 1024, options.bandwidth_unit); readable_size(peaktotal / RESOLUTION, buf2_10, 10, 1024, options.bandwidth_unit); printf("%s %10s %10s %10s\n", labellong, buf0_10, buf1_10, buf2_10); /* Cumulative totals */ - snprintf(labellong, PRINT_WIDTH + 9, "%-*s", PRINT_WIDTH + 9, "Cumulative (sent/received/total):"); + snprintf(labellong, PRINT_WIDTH_LONG + 1, "%-*s", PRINT_WIDTH_LONG, "Cumulative (sent/received/total):"); readable_size(history_totals.total_sent, buf0_10, 10, 1024, 1); readable_size(history_totals.total_recv, buf1_10, 10, 1024, 1); readable_size(history_totals.total_recv + history_totals.total_sent, buf2_10, 10, 1024, 1); -- 2.25.1 From bill at nonick.org Mon Feb 8 03:15:49 2021 From: bill at nonick.org (Bill Nickless) Date: Sun, 7 Feb 2021 19:15:49 -0800 Subject: [Iftop-users] [PATCH] sethostent() and setprotoent() are not thread safe Message-ID: Remove calls to sethostent() and setprotoent() because they are only optimizations and are not thread safe. Signed-off-by: Bill Nickless --- resolver.c | 1 - serv_hash.c | 1 - 2 files changed, 2 deletions(-) diff --git a/resolver.c b/resolver.c index 8557125..6c4c21d 100644 --- a/resolver.c +++ b/resolver.c @@ -407,7 +407,6 @@ char *do_resolve(struct addr_storage *addr) { void resolver_worker(void* ignored) { pthread_mutex_lock(&resolver_queue_mutex); - sethostent(1); while(1) { /* Wait until we are told that an address has been added to the * queue. */ diff --git a/serv_hash.c b/serv_hash.c index 279032e..10af520 100644 --- a/serv_hash.c +++ b/serv_hash.c @@ -52,7 +52,6 @@ void serv_hash_initialise(hash_type* sh) { struct servent* ent; struct protoent* pent; ip_service* service; - setprotoent(1); while((ent = getservent()) != NULL) { pent = getprotobyname(ent->s_proto); if(pent != NULL) { -- 2.25.1 From bill at nonick.org Mon Feb 8 03:21:15 2021 From: bill at nonick.org (Bill Nickless) Date: Sun, 7 Feb 2021 19:21:15 -0800 Subject: [Iftop-users] [PATCH] Reverse order of pthread_cond_signal()/pthread_mutex_unlock() Message-ID: Valgrand was not happy with the order in which pthread_cond_signal() and pthread_mutex_unlock() were being called. Also see https://docs.oracle.com/cd/E19455-01/806-5257/6je9h032r/index.html which states "Call pthread_cond_signal() under the protection of the same mutex used with the condition variable being signaled. Otherwise, the condition variable could be signaled between the test of the associated condition and blocking in pthread_cond_wait(), which can cause an infinite wait." Patch also available at: https://github.com/wknickless/iftop/commit/4c2fc858dc90b497819f0580fa4723a23276be9a Signed-off-by: Bill Nickless --- resolver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resolver.c b/resolver.c index 6c4c21d..70394c2 100644 --- a/resolver.c +++ b/resolver.c @@ -508,12 +508,13 @@ void resolve(int af, void* addr, char* result, int buflen) { added = 1; } } - pthread_mutex_unlock(&resolver_queue_mutex); if(added == 1) { pthread_cond_signal(&resolver_queue_cond); } + pthread_mutex_unlock(&resolver_queue_mutex); + if(result != NULL && buflen > 1) { strncpy(result, hostname, buflen - 1); result[buflen - 1] = '\0'; -- 2.25.1