changing hwaddr to sigar_net_address_t

This commit is contained in:
Doug MacEachern 2006-07-05 21:12:10 +00:00
parent a2597443b7
commit 287af5e947
5 changed files with 20 additions and 8 deletions

View File

@ -659,7 +659,7 @@ my %classes = (
plat => '*'
},
{
name => 'hwaddr', type => 'String',
name => 'hwaddr', type => 'NetAddress',
desc => '',
plat => '*'
},

View File

@ -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;

View File

@ -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))

View File

@ -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;

View File

@ -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;
}