changing hwaddr to sigar_net_address_t

This commit is contained in:
Doug MacEachern 2006-07-05 21:33:59 +00:00
parent 287af5e947
commit c2f0528538
5 changed files with 37 additions and 30 deletions

View File

@ -476,8 +476,6 @@ SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar,
#define SIGAR_IFF_MULTICAST 0x800
#define SIGAR_IFF_SLAVE 0x1000
#define SIGAR_NULL_HWADDR "00:00:00:00:00:00"
typedef struct {
char name[16];
char type[64];

View File

@ -200,11 +200,16 @@ int sigar_net_connection_list_grow(sigar_net_connection_list_t *connlist);
memcpy(&((a).addr.in6), val, sizeof((a).addr.in6)); \
(a).family = SIGAR_AF_INET6
#define SIGAR_IFHWADDRLEN
#define sigar_net_address_mac_set(a, val, len) \
if (len == 0) SIGAR_ZERO(&((a).addr.mac); \
if (len == 0) SIGAR_ZERO(&((a).addr.mac)); \
else memcpy(&((a).addr.mac), val, len); \
(a).family = SIGAR_AF_LINK
#define sigar_hwaddr_set_null(ifconfig) \
sigar_net_address_mac_set(ifconfig->hwaddr, 0, 0)
int sigar_who_list_create(sigar_who_list_t *wholist);
int sigar_who_list_grow(sigar_who_list_t *wholist);
@ -214,11 +219,6 @@ int sigar_who_list_grow(sigar_who_list_t *wholist);
sigar_who_list_grow(wholist); \
}
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))
int sigar_user_id_get(sigar_t *sigar, const char *name, int *uid);
int sigar_user_name_get(sigar_t *sigar, int uid, char *buf, int buflen);

View File

@ -1987,8 +1987,9 @@ int sigar_get_ifentry_config(sigar_t *sigar,
ifconfig->mtu = ifr->dwMtu;
sigar_hwaddr_format(ifconfig->hwaddr,
ifr->bPhysAddr);
sigar_net_address_mac_set(ifconfig->hwaddr,
ifr->bPhysAddr,
SIGAR_IFHWADDRLEN);
SIGAR_SSTRCPY(ifconfig->description,
ifr->bDescr);

View File

@ -1210,14 +1210,6 @@ int sigar_resource_limit_get(sigar_t *sigar,
}
#endif
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)
/* XXX: prolly will be moving these stuffs into os_net.c */
@ -1255,8 +1247,9 @@ static void hwaddr_aix_lookup(sigar_t *sigar, sigar_net_interface_config_t *ifco
if (strEQ(ifr->ifr_name, ifconfig->name)) {
struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr;
sigar_hwaddr_format(ifconfig->hwaddr,
(unsigned char *)LLADDR(sdl));
sigar_net_address_mac_set(ifconfig->hwaddr,
LLADDR(sdl),
sdl->sdl_alen);
return;
}
}
@ -1280,11 +1273,13 @@ static void hwaddr_arp_lookup(sigar_net_interface_config_t *ifconfig, int sock)
if (ioctl(sock, SIOCGARP, &areq) < 0) {
/* ho-hum */
memset(&areq.arp_ha.sa_data, '\0', sizeof(areq.arp_ha.sa_data));
sigar_hwaddr_set_null(ifconfig);
}
else {
sigar_net_address_mac_set(ifconfig->hwaddr,
areq.arp_ha.sa_data,
SIGAR_IFHWADDRLEN);
}
sigar_hwaddr_format(ifconfig->hwaddr,
(unsigned char *)areq.arp_ha.sa_data);
}
#endif
@ -1393,7 +1388,9 @@ int sigar_net_interface_config_get(sigar_t *sigar, const char *name,
if (!ioctl(sock, SIOCGIFHWADDR, &ifr)) {
get_interface_type(ifconfig,
ifr.ifr_hwaddr.sa_family);
sigar_hwaddr_format(ifconfig->hwaddr, ifr.ifr_hwaddr.sa_data);
sigar_net_address_mac_set(ifconfig->hwaddr,
ifr.ifr_hwaddr.sa_data,
IFHWADDRLEN);
}
#elif defined(_AIX) || defined(__osf__)
hwaddr_aix_lookup(sigar, ifconfig);
@ -1638,6 +1635,14 @@ static int sigar_inet_ntoa(sigar_t *sigar,
return SIGAR_OK;
}
static int sigar_ether_ntoa(char *buff, unsigned char *ptr)
{
sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
(ptr[0] & 0xff), (ptr[1] & 0xff), (ptr[2] & 0xff),
(ptr[3] & 0xff), (ptr[4] & 0xff), (ptr[5] & 0xff));
return SIGAR_OK;
}
SIGAR_DECLARE(int) sigar_net_address_to_string(sigar_t *sigar,
sigar_net_address_t *address,
char *addr_str)
@ -1659,7 +1664,7 @@ SIGAR_DECLARE(int) sigar_net_address_to_string(sigar_t *sigar,
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]);
return sigar_ether_ntoa(addr_str, &address->addr.mac[0]);
default:
return EINVAL;
}

View File

@ -92,8 +92,9 @@ static void hwaddr_lookup_netbios(sigar_net_interface_config_t *ifconfig,
ncb.ncb_buffer = (unsigned char *)&adapter;
ncb.ncb_length = sizeof(adapter);
if ((rc = Netbios(&ncb)) == 0) {
sigar_hwaddr_format(ifconfig->hwaddr,
adapter.status.adapter_address);
sigar_net_address_mac_set(ifconfig->hwaddr,
adapter.status.adapter_address,
SIGAR_IFHWADDRLEN);
}
else {
sigar_hwaddr_set_null(ifconfig);
@ -121,10 +122,12 @@ static void hwaddr_lookup(sigar_t *sigar,
sigar_net_interface_config_t *ifconfig,
int num)
{
uint8_t addr[6];
uint8_t addr[SIGAR_IFHWADDRLEN];
if (netware_net_macaddr(num+1, addr) == 0) {
sigar_hwaddr_format(ifconfig->hwaddr, addr);
sigar_net_address_mac_set(ifconfig->hwaddr,
addr,
sizeof(addr));
}
else {
sigar_hwaddr_set_null(ifconfig);