diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 2e5ae26e..17785878 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2444,6 +2444,7 @@ int sigar_net_route_list_get(sigar_t *sigar, SIGAR_ZERO(route); route->flags = rtm->rtm_flags; + if_indextoname(rtm->rtm_index, route->ifname); for (bit=RTA_DST; bit && ((char *)sa < lim); diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index 936c81f0..537cdd0d 100644 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -547,6 +547,7 @@ struct sigar_t { sigar_cache_t *netif_adapters; sigar_cache_t *netif_mib_rows; sigar_cache_t *netif_addr_rows; + sigar_cache_t *netif_names; /* dwIndex -> net_interface_config.name */ WORD ws_version; int ws_error; diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index ccbc8c37..9c0058e6 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -550,6 +550,7 @@ int sigar_os_open(sigar_t **sigar_ptr) sigar->netif_mib_rows = NULL; sigar->netif_addr_rows = NULL; sigar->netif_adapters = NULL; + sigar->netif_names = NULL; sigar->pinfo.pid = -1; sigar->ws_version = 0; sigar->lcpu = -1; @@ -599,6 +600,10 @@ int sigar_os_close(sigar_t *sigar) sigar_cache_destroy(sigar->netif_adapters); } + if (sigar->netif_names) { + sigar_cache_destroy(sigar->netif_names); + } + free(sigar); return retval; @@ -2473,6 +2478,10 @@ SIGAR_DECLARE(int) sigar_net_route_list_get(sigar_t *sigar, return GetLastError(); } + if (!sigar->netif_names) { + sigar_net_interface_list_get(sigar, NULL); + } + sigar_net_route_list_create(routelist); routelist->size = routelist->number = 0; @@ -2480,6 +2489,7 @@ SIGAR_DECLARE(int) sigar_net_route_list_get(sigar_t *sigar, for (i=0; idwNumEntries; i++) { MIB_IPFORWARDROW *ipr = ipt->table + i; + sigar_cache_entry_t *entry; 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; } + + entry = sigar_cache_get(sigar->netif_names, ipr->dwForwardIfIndex); + if (entry->value) { + SIGAR_SSTRCPY(route->ifname, (char *)entry->value); + } } free(buffer); @@ -2606,6 +2621,11 @@ sigar_net_interface_list_get(sigar_t *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) { return status; } @@ -2647,6 +2667,12 @@ sigar_net_interface_list_get(sigar_t *sigar, entry->value = malloc(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;