Fix the bug Danilo Câmara reported on iptraf-ng mailing list.
Vitezslav Samel (3): landesc.c: check_mac_addr(): make room for trailing '\0' hostmon.c: convmacaddr(): fix MAC addr to ASCII conversion hostmon.c: addethentry(): make the MAC addr description searching case insensitive
src/hostmon.c | 19 +++++++++---------- src/hostmon.h | 2 +- src/landesc.c | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-)
When parsing ETH description file make sure we have enough room for every MAC addr entity.
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/landesc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/landesc.c b/src/landesc.c index 52ea500..85c7d0a 100644 --- a/src/landesc.c +++ b/src/landesc.c @@ -31,7 +31,7 @@ static int check_mac_addr(const char *mac) if (strlen(mac) != 17) return 0;
- char a[2], b[2], c[2], d[2], e[2], f[2]; + char a[3], b[3], c[3], d[3], e[3], f[3];
int success = sscanf(mac, "%02s:%02s:%02s:%02s:%02s:%02s", a, b, c, d, e, f);
As reported by Danilo Câmara ethernet descriptions didn't work. Someone changed the MAC addr ASCII representation for ETH descriptions and didn't change this conversion routine. So fix it by printing to the right format. Also the copying of the description (if found) was borked. We must also make room for this extended representation (hostmon.h change).
Reported-by: Danilo Câmara dfcamara@gmail.com Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/hostmon.c | 19 +++++++++---------- src/hostmon.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c index 53d1d8e..63f63c3 100644 --- a/src/hostmon.c +++ b/src/hostmon.c @@ -139,16 +139,15 @@ struct ethtabent *addethnode(struct ethtab *table, int *nomem)
void convmacaddr(char *addr, char *result) { - unsigned int i; u_int8_t *ptmp = (u_int8_t *) addr; - char hexbyte[3];
- strcpy(result, ""); - for (i = 0; i <= 5; i++) { - sprintf(hexbyte, "%02x", *ptmp); - strcat(result, hexbyte); - ptmp++; - } + sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x", + *ptmp, + *(ptmp + 1), + *(ptmp + 2), + *(ptmp + 3), + *(ptmp + 4), + *(ptmp + 5)); }
struct ethtabent *addethentry(struct ethtab *table, unsigned int linktype, @@ -172,8 +171,8 @@ struct ethtabent *addethentry(struct ethtab *table, unsigned int linktype, struct eth_desc *desc = NULL;
list_for_each_entry(desc, &list->hd_list, hd_list) - if (!strcmp(desc->hd_mac, ptemp->un.desc.ascaddr)) - strcpy(ptemp->un.desc.ascaddr, ptemp->un.desc.desc); + if (!strcmp(desc->hd_mac, ptemp->un.desc.ascaddr)) + strcpy(ptemp->un.desc.desc, desc->hd_desc);
strcpy(ptemp->un.desc.ifname, ifname);
diff --git a/src/hostmon.h b/src/hostmon.h index 34251dc..983ff99 100644 --- a/src/hostmon.h +++ b/src/hostmon.h @@ -26,7 +26,7 @@ struct ethtabent {
struct { char eth_addr[ETH_ALEN]; - char ascaddr[15]; + char ascaddr[18]; char desc[65]; char ifname[IFNAMSIZ]; int withdesc;
Signed-off-by: Vitezslav Samel vitezslav@samel.cz --- src/hostmon.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c index 63f63c3..5790bc7 100644 --- a/src/hostmon.c +++ b/src/hostmon.c @@ -171,7 +171,7 @@ struct ethtabent *addethentry(struct ethtab *table, unsigned int linktype, struct eth_desc *desc = NULL;
list_for_each_entry(desc, &list->hd_list, hd_list) - if (!strcmp(desc->hd_mac, ptemp->un.desc.ascaddr)) + if (!strcasecmp(desc->hd_mac, ptemp->un.desc.ascaddr)) strcpy(ptemp->un.desc.desc, desc->hd_desc);
strcpy(ptemp->un.desc.ifname, ifname);
Vitezslav Samel vitezslav@samel.cz writes:
Fix the bug Danilo Câmara reported on iptraf-ng mailing list.
Vitezslav Samel (3): landesc.c: check_mac_addr(): make room for trailing '\0' hostmon.c: convmacaddr(): fix MAC addr to ASCII conversion hostmon.c: addethentry(): make the MAC addr description searching case insensitive
src/hostmon.c | 19 +++++++++---------- src/hostmon.h | 2 +- src/landesc.c | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-)
all applied. thanks
iptraf-ng@lists.fedorahosted.org