diff options
author | Håkon Nessjøen <haakon.nessjoen@gmail.com> | 2011-11-13 08:19:06 +0100 |
---|---|---|
committer | Håkon Nessjøen <haakon.nessjoen@gmail.com> | 2011-11-13 08:19:06 +0100 |
commit | 4d3923c1cc947fbf1a6b23e2adf6915c47aac8d1 (patch) | |
tree | c67f91f5df532bcc6b494c2f21bdce59247a8f67 | |
parent | e78481d2e5a4a3ea133980403041579b048ede74 (diff) | |
download | MAC-Telnet-4d3923c1cc947fbf1a6b23e2adf6915c47aac8d1.tar.gz MAC-Telnet-4d3923c1cc947fbf1a6b23e2adf6915c47aac8d1.zip |
Fix bug in interface enumerator
-rw-r--r-- | interfaces.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/interfaces.c b/interfaces.c index 86b9aab..d1d177c 100644 --- a/interfaces.c +++ b/interfaces.c @@ -66,6 +66,7 @@ static struct net_interface *net_get_interface_ptr(struct net_interface *interfa #ifdef __linux__ static void net_update_mac(struct net_interface *interfaces, int max_devices) { + unsigned char emptymac[] = {0, 0, 0, 0, 0, 0}; struct ifreq ifr; int i,tmpsock; @@ -82,7 +83,9 @@ static void net_update_mac(struct net_interface *interfaces, int max_devices) { if (ioctl(tmpsock, SIOCGIFHWADDR, &ifr) == 0) { /* Fetch mac address */ memcpy(interfaces[i].mac_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); - interfaces[i].has_mac = 1; + if (memcmp(interfaces[i].mac_addr, &emptymac, ETH_ALEN) != 0) { + interfaces[i].has_mac = 1; + } } } @@ -141,8 +144,8 @@ int net_get_interfaces(struct net_interface *interfaces, int max_devices) { struct sockaddr_dl *sdl = (struct sockaddr_dl *)int_cursor->ifa_addr; if (sdl->sdl_alen == ETH_ALEN) { struct net_interface *interface = net_get_interface_ptr(interfaces, max_devices, int_cursor->ifa_name, 1); - if (interface != NULL && memcmp(interfaces->mac_addr, emptymac, ETH_ALEN) != 0) { - memcpy(interface->mac_addr, LLADDR(sdl), ETH_ALEN); + memcpy(interface->mac_addr, LLADDR(sdl), ETH_ALEN); + if (interface != NULL && memcmp(interface->mac_addr, &emptymac, ETH_ALEN) != 0) { interface->has_mac = 1; } } |