try IFMIB first to get hwaddr and MTU

This commit is contained in:
Doug MacEachern 2006-03-04 22:12:18 +00:00
parent 9fa41cc1c7
commit 61a2a98f67
2 changed files with 63 additions and 12 deletions

View File

@ -1919,9 +1919,9 @@ static int sigar_get_if_table(sigar_t *sigar, PMIB_IFTABLE *iftable)
} }
} }
SIGAR_DECLARE(int) static int get_mib_ifrow(sigar_t *sigar,
sigar_net_interface_stat_get(sigar_t *sigar, const char *name, const char *name,
sigar_net_interface_stat_t *ifstat) MIB_IFROW **ifrp)
{ {
DWORD rc, i; DWORD rc, i;
MIB_IFTABLE *ift; MIB_IFTABLE *ift;
@ -1964,6 +1964,42 @@ sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
return ENOENT; 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_bytes = ifr->dwInOctets;
ifstat->rx_packets = ifr->dwInUcastPkts + ifr->dwInNUcastPkts; ifstat->rx_packets = ifr->dwInUcastPkts + ifr->dwInNUcastPkts;
ifstat->rx_errors = ifr->dwInErrors; ifstat->rx_errors = ifr->dwInErrors;

View File

@ -58,7 +58,8 @@ int sigar_wsa_init(sigar_t *sigar)
#include <nb30.h> #include <nb30.h>
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; NCB ncb;
UCHAR rc; 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 */ #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]; 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); sigar_hwaddr_format(ifconfig->hwaddr, addr);
} }
else { else {
@ -224,19 +242,16 @@ sigar_net_interface_config_get(sigar_t *sigar,
ifconfig->flags |= SIGAR_IFF_LOOPBACK; ifconfig->flags |= SIGAR_IFF_LOOPBACK;
ifconfig->destination = ifconfig->address; ifconfig->destination = ifconfig->address;
ifconfig->broadcast = 0; ifconfig->broadcast = 0;
#ifdef NETWARE
hwaddr_lookup(ifconfig, i+1);
#else
sigar_hwaddr_set_null(ifconfig);
#endif
SIGAR_SSTRCPY(ifconfig->type, SIGAR_SSTRCPY(ifconfig->type,
SIGAR_NIC_LOOPBACK); SIGAR_NIC_LOOPBACK);
} }
else { else {
hwaddr_lookup(ifconfig, i);
SIGAR_SSTRCPY(ifconfig->type, SIGAR_SSTRCPY(ifconfig->type,
SIGAR_NIC_ETHERNET); SIGAR_NIC_ETHERNET);
} }
hwaddr_lookup(sigar, ifconfig, i);
if (flags & IFF_POINTTOPOINT) { if (flags & IFF_POINTTOPOINT) {
ifconfig->flags |= SIGAR_IFF_POINTOPOINT; ifconfig->flags |= SIGAR_IFF_POINTOPOINT;
} }