From 287af5e9477c20b893a604158e4a902a2c667766 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 5 Jul 2006 21:12:10 +0000 Subject: [PATCH] changing hwaddr to sigar_net_address_t --- bindings/java/src/jni/generate.pl | 2 +- include/sigar.h | 6 ++++-- include/sigar_private.h | 9 +++++++-- src/os/darwin/darwin_sigar.c | 6 ++++-- src/sigar.c | 5 ++++- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/bindings/java/src/jni/generate.pl b/bindings/java/src/jni/generate.pl index ea50fd1f..7538173f 100644 --- a/bindings/java/src/jni/generate.pl +++ b/bindings/java/src/jni/generate.pl @@ -659,7 +659,7 @@ my %classes = ( plat => '*' }, { - name => 'hwaddr', type => 'String', + name => 'hwaddr', type => 'NetAddress', desc => '', plat => '*' }, diff --git a/include/sigar.h b/include/sigar.h index 5de91ccd..41c1295f 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -395,11 +395,13 @@ typedef struct { enum { SIGAR_AF_UNSPEC, SIGAR_AF_INET, - SIGAR_AF_INET6 + SIGAR_AF_INET6, + SIGAR_AF_LINK } family; union { sigar_uint32_t in; sigar_uint32_t in6[4]; + unsigned char mac[8]; } addr; } sigar_net_address_t; @@ -478,9 +480,9 @@ SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar, typedef struct { char name[16]; - char hwaddr[64]; char type[64]; char description[256]; + sigar_net_address_t hwaddr; sigar_net_address_t address; sigar_net_address_t destination; sigar_net_address_t broadcast; diff --git a/include/sigar_private.h b/include/sigar_private.h index a90417ef..df68e993 100644 --- a/include/sigar_private.h +++ b/include/sigar_private.h @@ -196,10 +196,15 @@ int sigar_net_connection_list_grow(sigar_net_connection_list_t *connlist); (a).addr.in = val; \ (a).family = SIGAR_AF_INET -#define sigar_net_address6_set(addr, val) \ +#define sigar_net_address6_set(a, val) \ memcpy(&((a).addr.in6), val, sizeof((a).addr.in6)); \ (a).family = SIGAR_AF_INET6 +#define sigar_net_address_mac_set(a, val, len) \ + if (len == 0) SIGAR_ZERO(&((a).addr.mac); \ + else memcpy(&((a).addr.mac), val, len); \ + (a).family = SIGAR_AF_LINK + int sigar_who_list_create(sigar_who_list_t *wholist); int sigar_who_list_grow(sigar_who_list_t *wholist); @@ -209,7 +214,7 @@ int sigar_who_list_grow(sigar_who_list_t *wholist); sigar_who_list_grow(wholist); \ } -void sigar_hwaddr_format(char *buff, unsigned char *ptr); +int sigar_hwaddr_format(char *buff, unsigned char *ptr); #define sigar_hwaddr_set_null(ifconfig) \ memcpy(ifconfig->hwaddr, SIGAR_NULL_HWADDR, sizeof(SIGAR_NULL_HWADDR)) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 1dcd0d57..8daeaaae 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -1617,8 +1617,10 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name, SIGAR_SSTRCPY(ifconfig->name, name); sdl = (struct sockaddr_dl *)(ifm + 1); - sigar_hwaddr_format(ifconfig->hwaddr, - (unsigned char *)LLADDR(sdl)); + + sigar_net_address_mac_set(ifconfig->hwaddr, + LLADDR(sdl), + sdl->sdl_alen); ifconfig->flags = ifm->ifm_flags; ifconfig->mtu = ifm->ifm_data.ifi_mtu; diff --git a/src/sigar.c b/src/sigar.c index 7fe6bb7c..484534eb 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1210,11 +1210,12 @@ int sigar_resource_limit_get(sigar_t *sigar, } #endif -void sigar_hwaddr_format(char *buff, unsigned char *ptr) +int sigar_hwaddr_format(char *buff, unsigned char *ptr) { sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X", (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)); + return SIGAR_OK; } #if !defined(WIN32) && !defined(DARWIN) && !defined(__FreeBSD__) && !defined(NETWARE) @@ -1657,6 +1658,8 @@ SIGAR_DECLARE(int) sigar_net_address_to_string(sigar_t *sigar, return sigar_inet_ntoa(sigar, address->addr.in, addr_str); case SIGAR_AF_UNSPEC: return sigar_inet_ntoa(sigar, 0, addr_str); /*XXX*/ + case SIGAR_AF_LINK: + return sigar_hwaddr_format(addr_str, &address->addr.mac[0]); default: return EINVAL; }