Random comment, please always use braces for logic blocks and for/while loops.
On Tue, Jan 25, 2011 at 8:32 PM, Adam Stokes <astokes(a)fedoraproject.org> wrote:
- to insert adapter friendlyname based on hardware address
matching
There is still some work to be done as it looks like my best approach
would be to either:
a) create a lookup bridge table to pull the full friendly name
of the adapter since the length of the name array is
hardcoded to 16.
no
Its a _local_ variable, change it to whatever you like.
b) alter the hardcoded array length to allow for more
characters, however, this seems to prove problematic in my
tests. So far just simply altering the struct to something
like name[256] does not seem to be enough.
Then you're doing something else wrong.
Possibly that name is unset (and therefor potentially contains
garbage) for non-ethernet devices.
But you didn't include any symptoms so I'm guessing.
Its not clear to me why you need to do this every time around the loop:
+ } else {
+ sprintf(name, "eth%d", eth++);
I also love the irony of:
+ sprintf(name, "Windows Name to
long");
That alone would crash the daemon.
> ---
> src/CMakeLists.txt | 11 +++++++-
> src/os/win32/win32_sigar.c | 61 ++++++++++++++++++++++++++++++++-----------
> 2 files changed, 55 insertions(+), 17 deletions(-)
>
> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
> index 40137d0..1091c81 100644
> --- a/src/CMakeLists.txt
> +++ b/src/CMakeLists.txt
> @@ -100,8 +100,17 @@ SET(SIGAR_SRC ${SIGAR_SRC}
>
> ADD_LIBRARY(sigar SHARED ${SIGAR_SRC})
> IF(WIN32)
> - TARGET_LINK_LIBRARIES(sigar ws2_32 netapi32 version)
> + TARGET_LINK_LIBRARIES(sigar ws2_32 netapi32 version iphlpapi)
> ENDIF(WIN32)
> +#glib
> +include(FindPkgConfig)
> +pkg_check_modules(glib REQUIRED glib-2.0)
> +if(glib_FOUND)
> + include_directories(${glib_INCLUDE_DIRS})
> + target_link_libraries(sigar ${glib_LIBRARIES})
> +else(glib_FOUND)
> + message(FATAL_ERROR "Glib2 header/library not found.")
> +endif(glib_FOUND)
> IF(SIGAR_LINK_FLAGS)
> SET_TARGET_PROPERTIES(sigar PROPERTIES LINK_FLAGS "${SIGAR_LINK_FLAGS}")
> ENDIF(SIGAR_LINK_FLAGS)
> diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c
> index 87076c8..af55cf8 100755
> --- a/src/os/win32/win32_sigar.c
> +++ b/src/os/win32/win32_sigar.c
> @@ -24,6 +24,8 @@
> #include "sigar_format.h"
> #include <shellapi.h>
> #include <iphlpapi.h>
> +#include <glib.h>
> +#include <stdlib.h>
>
> #define USING_WIDE_S(s) (s)->using_wide
> #define USING_WIDE() USING_WIDE_S(sigar)
> @@ -2671,13 +2673,17 @@ static int netif_hash(char *s)
> #define IF_TYPE_IEEE80211 71
> #endif
>
> +#define GAA_FLAGS ( GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_MULTICAST |
GAA_FLAG_SKIP_ANYCAST )
> +#define IFACE_BUFSIZE 256
> SIGAR_DECLARE(int)
> sigar_net_interface_list_get(sigar_t *sigar,
> sigar_net_interface_list_t *iflist)
> {
> MIB_IFTABLE *ift;
> + PIP_ADAPTER_ADDRESSES aa, addrs;
> int i, status;
> int lo=0, eth=0, la=0;
> + DWORD tableSize = 0;
>
> if (!sigar->netif_mib_rows) {
> sigar->netif_mib_rows =
> @@ -2700,27 +2706,51 @@ sigar_net_interface_list_get(sigar_t *sigar,
> malloc(sizeof(*(iflist->data)) * iflist->size);
> }
>
> + GetAdaptersAddresses(AF_UNSPEC, GAA_FLAGS, NULL, aa, &tableSize);
> + aa = malloc(tableSize);
> + if ((status = GetAdaptersAddresses(AF_INET, GAA_FLAGS, NULL, aa,
&tableSize)) != NO_ERROR)
> + return status;
> +
> for (i=0; i<ift->dwNumEntries; i++) {
> char name[16];
> int key;
> MIB_IFROW *ifr = ift->table + i;
> sigar_cache_entry_t *entry;
> + char *mac = NULL, *mac_cmp = NULL;
>
> - if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
> - /* special-case */
> - sprintf(name, NETIF_LA "%d", la++);
> - }
> - else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
> - sprintf(name, "lo%d", lo++);
> - }
> - else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
> - (ifr->dwType == IF_TYPE_IEEE80211))
> - {
> - sprintf(name, "eth%d", eth++);
> - }
> - else {
> - continue; /*XXX*/
> - }
> + if((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
> + (ifr->dwType == IF_TYPE_IEEE80211))
> + {
> + mac = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
> + ifr->bPhysAddr[0],
> + ifr->bPhysAddr[1],
> + ifr->bPhysAddr[2],
> + ifr->bPhysAddr[3],
> + ifr->bPhysAddr[4],
> + ifr->bPhysAddr[5]);
> + for (addrs = aa; addrs; addrs = addrs->Next) {
> + if(addrs->PhysicalAddressLength < 6)
> + continue;
> + mac_cmp = g_strdup_printf("%02X%02X%02X%02X%02X%02X",
> + addrs->PhysicalAddress[0],
> + addrs->PhysicalAddress[1],
> + addrs->PhysicalAddress[2],
> + addrs->PhysicalAddress[3],
> + addrs->PhysicalAddress[4],
> + addrs->PhysicalAddress[5]);
> + if(strcmp(mac, mac_cmp) == 0) {
> + if ((status = wcstombs(name, addrs->FriendlyName,
sizeof(name))) < 0) {
+ sprintf(name, "Windows Name to
long");
> + }
+ } else {
+ sprintf(name, "eth%d", eth++);
> +
}
> + }
> + }
> + else
> + {
> + continue; /* Just ethernet */
> + }
>
> if (iflist) {
> iflist->data[iflist->number++] = sigar_strdup(name);
> @@ -2739,7 +2769,6 @@ sigar_net_interface_list_get(sigar_t *sigar,
> entry->value = sigar_strdup(name);
> }
> }
> -
> return SIGAR_OK;
> }
>
> --
> 1.7.3.5
>
> _______________________________________________
> Matahari mailing list
> Matahari(a)lists.fedorahosted.org
>
https://fedorahosted.org/mailman/listinfo/matahari
>