From d3e019dd98ca5a9c982a750a0c5a47c204510e80 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 15 Sep 2009 11:32:07 -0700 Subject: [PATCH 1/2] (SIGAR-181) net_route.ifname impl for MacOSX and *BSD --- src/os/darwin/darwin_sigar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 0ca030b7..149ee453 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2416,6 +2416,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); From f16b3e3daa3c9c7a9f4256f9a50a6a8c7ccb7752 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 15 Sep 2009 11:35:51 -0700 Subject: [PATCH 2/2] (SIGAR-181) net_route.ifname impl for Win32 --- src/os/win32/sigar_os.h | 1 + src/os/win32/win32_sigar.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) 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 5ac57b64..39c46ac1 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -549,6 +549,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; @@ -598,6 +599,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;