diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index a5e58d78..4dc5dd9f 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -1919,9 +1919,9 @@ static int sigar_get_if_table(sigar_t *sigar, PMIB_IFTABLE *iftable) } } -SIGAR_DECLARE(int) -sigar_net_interface_stat_get(sigar_t *sigar, const char *name, - sigar_net_interface_stat_t *ifstat) +static int get_mib_ifrow(sigar_t *sigar, + const char *name, + MIB_IFROW **ifrp) { DWORD rc, i; MIB_IFTABLE *ift; @@ -1964,6 +1964,42 @@ sigar_net_interface_stat_get(sigar_t *sigar, const char *name, return ENOENT; } + *ifrp = ifr; + + return SIGAR_OK; +} + +int sigar_get_ifentry_config(sigar_t *sigar, + sigar_net_interface_config_t *ifconfig) +{ + MIB_IFROW *ifr; + int status; + + status = get_mib_ifrow(sigar, ifconfig->name, &ifr); + if (status != SIGAR_OK) { + return status; + } + + ifconfig->mtu = ifr->dwMtu; + + sigar_hwaddr_format(ifconfig->hwaddr, + ifr->bPhysAddr); + + return SIGAR_OK; +} + +SIGAR_DECLARE(int) +sigar_net_interface_stat_get(sigar_t *sigar, const char *name, + sigar_net_interface_stat_t *ifstat) +{ + MIB_IFROW *ifr; + int status; + + status = get_mib_ifrow(sigar, name, &ifr); + if (status != SIGAR_OK) { + return status; + } + ifstat->rx_bytes = ifr->dwInOctets; ifstat->rx_packets = ifr->dwInUcastPkts + ifr->dwInNUcastPkts; ifstat->rx_errors = ifr->dwInErrors; diff --git a/src/sigar_win32ish.c b/src/sigar_win32ish.c index ec48022c..fd1ea201 100644 --- a/src/sigar_win32ish.c +++ b/src/sigar_win32ish.c @@ -58,7 +58,8 @@ int sigar_wsa_init(sigar_t *sigar) #include -static void hwaddr_lookup(sigar_net_interface_config_t *ifconfig, int num) +static void hwaddr_lookup_netbios(sigar_net_interface_config_t *ifconfig, + int num) { NCB ncb; UCHAR rc; @@ -99,13 +100,30 @@ static void hwaddr_lookup(sigar_net_interface_config_t *ifconfig, int num) } } +static void hwaddr_lookup(sigar_t *sigar, + sigar_net_interface_config_t *ifconfig, + int num) +{ + /* try IFMIB first, fallback on netbios for hwaddr */ + if (sigar_get_ifentry_config(sigar, ifconfig) != SIGAR_OK) { + if (ifconfig->flags & SIGAR_IFF_LOOPBACK) { + sigar_hwaddr_set_null(ifconfig); + } + else { + hwaddr_lookup_netbios(ifconfig, num); + } + } +} + #else /* NETWARE */ -static void hwaddr_lookup(sigar_net_interface_config_t *ifconfig, int num) +static void hwaddr_lookup(sigar_t *sigar, + sigar_net_interface_config_t *ifconfig, + int num) { uint8_t addr[6]; - if (netware_net_macaddr(num, addr) == 0) { + if (netware_net_macaddr(num+1, addr) == 0) { sigar_hwaddr_format(ifconfig->hwaddr, addr); } else { @@ -224,19 +242,16 @@ sigar_net_interface_config_get(sigar_t *sigar, ifconfig->flags |= SIGAR_IFF_LOOPBACK; ifconfig->destination = ifconfig->address; ifconfig->broadcast = 0; -#ifdef NETWARE - hwaddr_lookup(ifconfig, i+1); -#else - sigar_hwaddr_set_null(ifconfig); -#endif SIGAR_SSTRCPY(ifconfig->type, SIGAR_NIC_LOOPBACK); } else { - hwaddr_lookup(ifconfig, i); SIGAR_SSTRCPY(ifconfig->type, SIGAR_NIC_ETHERNET); } + + hwaddr_lookup(sigar, ifconfig, i); + if (flags & IFF_POINTTOPOINT) { ifconfig->flags |= SIGAR_IFF_POINTOPOINT; }