From e2b1329fb5d446b84916c4aee702c86b8f269fae Mon Sep 17 00:00:00 2001 From: Robin Ekman Date: Fri, 29 Mar 2024 02:40:14 +0100 Subject: [PATCH] bandwidth2: fix interfaces logic the -i flag was not working as documented. the underlying reasons were 1) not accounting for whitespace padding in /proc/net/dev 2) incorrect usage of strcmp, which returns 0 for equal strings --- bandwidth2/bandwidth2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bandwidth2/bandwidth2.c b/bandwidth2/bandwidth2.c index d354b4ba..72479947 100644 --- a/bandwidth2/bandwidth2.c +++ b/bandwidth2/bandwidth2.c @@ -51,11 +51,11 @@ void get_values(char **const ifaces, int num_ifaces, time_t * const s, ulli * co *received = 0; *sent = 0; while (fgets(line, BUFSIZ - 1, f) != NULL) { - if (sscanf(line, "%[^:]: %llu %*u %*u %*u %*u %*u %*u %*u %llu", ifname, &temp_r, &temp_s) == 3) { + if (sscanf(line, " %[^:]: %llu %*u %*u %*u %*u %*u %*u %*u %llu", ifname, &temp_r, &temp_s) == 3) { int i; int iface_found = num_ifaces == 0; for (i = 0; i < num_ifaces; i++) { - if (strcmp(ifaces[i], ifname) != 0) { + if (strcmp(ifaces[i], ifname) == 0) { iface_found = 1; break; }