[Iftop-users] [PATCH] Fix MAC address formatting

Zev Weiss zev at bewilderbeest.net
Fri, 7 Feb 2014 15:39:07 -0600


Hi,

Running iftop-1.0pre4 I noticed my MAC address getting printed with some =
bytes (the "negative" ones) sign-extended into 32 bits (i.e. with =
"ffffff" prefixed).  The below patch restores more a =
conventional-looking format.

Thanks,
Zev Weiss

diff -Naur iftop-1.0pre4.orig/iftop.c iftop-1.0pre4/iftop.c
--- iftop-1.0pre4.orig/iftop.c	2014-01-19 12:21:19.000000000 -0800
+++ iftop-1.0pre4/iftop.c	2014-02-07 13:26:15.669698968 -0800
@@ -713,7 +713,7 @@
     if(have_hw_addr) {
       fprintf(stderr, "MAC address is:");
       for (i =3D 0; i < 6; ++i)
-	fprintf(stderr, "%c%02x", i ? ':' : ' ', (unsigned =
int)if_hw_addr[i]);
+	fprintf(stderr, "%c%02hhx", i ? ':' : ' ', if_hw_addr[i]);
       fprintf(stderr, "\n");
     }
    =20