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(a)gmail.com>
Signed-off-by: Vitezslav Samel <vitezslav(a)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;
--
1.7.8.4