(SIGAR-181) net_route.ifname impl for Win32

This commit is contained in:
Doug MacEachern 2009-09-15 11:35:51 -07:00
parent d3e019dd98
commit f16b3e3daa
2 changed files with 27 additions and 0 deletions

View File

@ -547,6 +547,7 @@ struct sigar_t {
sigar_cache_t *netif_adapters; sigar_cache_t *netif_adapters;
sigar_cache_t *netif_mib_rows; sigar_cache_t *netif_mib_rows;
sigar_cache_t *netif_addr_rows; sigar_cache_t *netif_addr_rows;
sigar_cache_t *netif_names; /* dwIndex -> net_interface_config.name */
WORD ws_version; WORD ws_version;
int ws_error; int ws_error;

View File

@ -549,6 +549,7 @@ int sigar_os_open(sigar_t **sigar_ptr)
sigar->netif_mib_rows = NULL; sigar->netif_mib_rows = NULL;
sigar->netif_addr_rows = NULL; sigar->netif_addr_rows = NULL;
sigar->netif_adapters = NULL; sigar->netif_adapters = NULL;
sigar->netif_names = NULL;
sigar->pinfo.pid = -1; sigar->pinfo.pid = -1;
sigar->ws_version = 0; sigar->ws_version = 0;
sigar->lcpu = -1; sigar->lcpu = -1;
@ -598,6 +599,10 @@ int sigar_os_close(sigar_t *sigar)
sigar_cache_destroy(sigar->netif_adapters); sigar_cache_destroy(sigar->netif_adapters);
} }
if (sigar->netif_names) {
sigar_cache_destroy(sigar->netif_names);
}
free(sigar); free(sigar);
return retval; return retval;
@ -2473,6 +2478,10 @@ SIGAR_DECLARE(int) sigar_net_route_list_get(sigar_t *sigar,
return GetLastError(); return GetLastError();
} }
if (!sigar->netif_names) {
sigar_net_interface_list_get(sigar, NULL);
}
sigar_net_route_list_create(routelist); sigar_net_route_list_create(routelist);
routelist->size = routelist->number = 0; routelist->size = routelist->number = 0;
@ -2480,6 +2489,7 @@ SIGAR_DECLARE(int) sigar_net_route_list_get(sigar_t *sigar,
for (i=0; i<ipt->dwNumEntries; i++) { for (i=0; i<ipt->dwNumEntries; i++) {
MIB_IPFORWARDROW *ipr = ipt->table + i; MIB_IPFORWARDROW *ipr = ipt->table + i;
sigar_cache_entry_t *entry;
SIGAR_NET_ROUTE_LIST_GROW(routelist); SIGAR_NET_ROUTE_LIST_GROW(routelist);
@ -2503,6 +2513,11 @@ SIGAR_DECLARE(int) sigar_net_route_list_get(sigar_t *sigar,
{ {
route->flags |= SIGAR_RTF_GATEWAY; route->flags |= SIGAR_RTF_GATEWAY;
} }
entry = sigar_cache_get(sigar->netif_names, ipr->dwForwardIfIndex);
if (entry->value) {
SIGAR_SSTRCPY(route->ifname, (char *)entry->value);
}
} }
free(buffer); free(buffer);
@ -2606,6 +2621,11 @@ sigar_net_interface_list_get(sigar_t *sigar,
sigar_netif_cache_new(sigar); sigar_netif_cache_new(sigar);
} }
if (!sigar->netif_names) {
sigar->netif_names =
sigar_netif_cache_new(sigar);
}
if ((status = sigar_get_if_table(sigar, &ift)) != SIGAR_OK) { if ((status = sigar_get_if_table(sigar, &ift)) != SIGAR_OK) {
return status; return status;
} }
@ -2647,6 +2667,12 @@ sigar_net_interface_list_get(sigar_t *sigar,
entry->value = malloc(sizeof(*ifr)); entry->value = malloc(sizeof(*ifr));
} }
memcpy(entry->value, ifr, sizeof(*ifr)); memcpy(entry->value, ifr, sizeof(*ifr));
/* save dwIndex -> name mapping for use by route_list */
entry = sigar_cache_get(sigar->netif_names, ifr->dwIndex);
if (!entry->value) {
entry->value = sigar_strdup(name);
}
} }
return SIGAR_OK; return SIGAR_OK;