(SIGAR-142) loosen net_interface_list filters

This commit is contained in:
Doug MacEachern 2009-05-24 18:09:32 -07:00
parent 64a6f41925
commit fb9a5f3357
1 changed files with 31 additions and 5 deletions

View File

@ -2456,6 +2456,26 @@ static int sigar_ifmsg_init(sigar_t *sigar)
return SIGAR_OK; return SIGAR_OK;
} }
static int has_ifaddr(char *name)
{
int sock, status;
struct ifreq ifr;
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
return errno;
}
SIGAR_SSTRCPY(ifr.ifr_name, name);
if (ioctl(sock, SIOCGIFADDR, &ifr) == 0) {
status = SIGAR_OK;
}
else {
status = errno;
}
close(sock);
return status;
}
static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter) static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter)
{ {
char *end = sigar->ifconf_buf + sigar->ifconf_len; char *end = sigar->ifconf_buf + sigar->ifconf_len;
@ -2490,14 +2510,20 @@ static int sigar_ifmsg_iter(sigar_t *sigar, ifmsg_iter_t *iter)
if (sdl->sdl_family != AF_LINK) { if (sdl->sdl_family != AF_LINK) {
continue; continue;
} }
if (!((sdl->sdl_type == IFT_ETHER) ||
(sdl->sdl_type == IFT_LOOP)))
{
continue; /* XXX deal w/ other weirdo interfaces */
}
switch (iter->type) { switch (iter->type) {
case IFMSG_ITER_LIST: case IFMSG_ITER_LIST:
if (sdl->sdl_type == IFT_OTHER) {
if (has_ifaddr(sdl->sdl_data) != SIGAR_OK) {
break;
}
}
else if (!((sdl->sdl_type == IFT_ETHER) ||
(sdl->sdl_type == IFT_LOOP)))
{
break; /* XXX deal w/ other weirdo interfaces */
}
SIGAR_NET_IFLIST_GROW(iter->data.iflist); SIGAR_NET_IFLIST_GROW(iter->data.iflist);
/* sdl_data doesn't include a trailing \0, it is only sdl_nlen long */ /* sdl_data doesn't include a trailing \0, it is only sdl_nlen long */