示例#1
0
文件: factidC.c 项目: tongson/omnia
/*
Show configured IP addresses.
@function ifaddrs
@return information (TABLE)
*/
static int
Fifaddrs(lua_State *L)
{
	struct ifaddrs *ifaddr = {0};
	struct ifaddrs *i = {0};
	int c = 1;

	errno = 0;
	if (0 > getifaddrs(&ifaddr)) return luaX_pusherror(L, "getifaddrs(3) error");
	lua_newtable(L);
	for (i = ifaddr; i != 0 ; i = i->ifa_next) {
		if (i->ifa_addr == 0) {
			continue;
		}
		lua_newtable(L);
		lua_pushstring(L, i->ifa_name);
		lua_setfield(L, -2, "interface");
		if (i->ifa_addr->sa_family == AF_INET || i->ifa_addr->sa_family == AF_INET6) {
			ipaddr(L, i);
		}
		if (i->ifa_data && (i->ifa_addr->sa_family == AF_PACKET)) {
			ifstats(L, i);
		}
		lua_rawseti(L, -2, c++);
	}
	freeifaddrs(ifaddr);
	return 1;
}
示例#2
0
文件: menulib.c 项目: fjanssen/Car2X
int
iface_stats(void * pio)
{
   char *   cp;
   struct net * ifp;

   ifp = (NET)(netlist.q_head);   /* default to first net */

   cp = nextarg(((GEN_IO)pio)->inbuf);    /* get console arg */
   if(cp && *cp)     /* arg is present on command line */
   {
      ifp = if_netbytext(pio, cp);
      if(ifp == NULL)      /* error parsing iface name/number text? */
         return -1;
   }

   ifstats(pio, ifp);
   return 0;
}