Esempio n. 1
0
static int lua_sigar_netif_get_info(lua_State *L) {
	lua_sigar_netif_t *netif = (lua_sigar_netif_t *)luaL_checkudata(L, 1, "sigar_netif");
	int err;
	const char *if_name = netif->netifs->netifs.data[netif->ndx];
	sigar_net_interface_config_t usage;

	if (SIGAR_OK != (err = sigar_net_interface_config_get(netif->netifs->sigar, if_name, &usage))) {
		lua_pushnil(L);
		lua_pushstring(L, strerror(err));
		return 2;
	}

	lua_newtable(L);
#define DATA \
	(&(usage))

	LUA_EXPORT_STR(DATA, name);
	LUA_EXPORT_STR(DATA, type);
	LUA_EXPORT_ADDRESS(DATA, hwaddr);
	LUA_EXPORT_ADDRESS(DATA, address);
	LUA_EXPORT_ADDRESS(DATA, destination);
	LUA_EXPORT_ADDRESS(DATA, broadcast);
	LUA_EXPORT_ADDRESS(DATA, netmask);
	LUA_EXPORT_INT(DATA, flags);
	LUA_EXPORT_INT(DATA, mtu);
	LUA_EXPORT_INT(DATA, metric);
#undef DATA

	return 1;

}
Esempio n. 2
0
static int sigar_netif_configured(sigar_t *sigar, char *name)
{
    int status;
    sigar_net_interface_config_t ifconfig;

    status = sigar_net_interface_config_get(sigar, name, &ifconfig);

    return status == SIGAR_OK;
}
Esempio n. 3
0
sigar_net_interface_config_primary_get(sigar_t *sigar,
                                       sigar_net_interface_config_t *ifconfig)
{
    int i, status, found=0;
    sigar_net_interface_list_t iflist;
    sigar_net_interface_config_t possible_config;

    possible_config.flags = 0;

    if ((status = sigar_net_interface_list_get(sigar, &iflist)) != SIGAR_OK) {
        return status;
    }

    for (i=0; i<iflist.number; i++) {
        status = sigar_net_interface_config_get(sigar,
                                                iflist.data[i], ifconfig);

        if ((status != SIGAR_OK) ||
            (ifconfig->flags & SIGAR_IFF_LOOPBACK) ||
            !ifconfig->hwaddr.addr.in)   /* no mac address */
        {
            continue;
        }

        if (!possible_config.flags) {
            /* save for later for use if we're not connected to the net
             * or all interfaces are aliases (e.g. solaris zone)
             */
            memcpy(&possible_config, ifconfig, sizeof(*ifconfig));
        }
        if (!ifconfig->address.addr.in) {
            continue; /* no ip address */
        }
        if (strchr(iflist.data[i], ':')) {
            continue; /* alias */
        }

        found = 1;
        break;
    }

    sigar_net_interface_list_destroy(sigar, &iflist);

    if (found) {
        return SIGAR_OK;
    }
    else if (possible_config.flags) {
        memcpy(ifconfig, &possible_config, sizeof(*ifconfig));
        return SIGAR_OK;
    }
    else {
        return SIGAR_ENXIO;
    }
}