コード例 #1
0
ファイル: utsname.c プロジェクト: luaposix/luaposix
static int
pushutsname(lua_State *L, struct utsname *u)
{
	if (!u)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 5);
	setstringfield(u, machine);
	setstringfield(u, nodename);
	setstringfield(u, release);
	setstringfield(u, sysname);
	setstringfield(u, version);

	settypemetatable("PosixUtsname");
	return 1;
}
コード例 #2
0
static int
pushpasswd(lua_State *L, struct passwd *p)
{
	if (!p)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 6);
	setintegerfield(p, pw_uid);
	setintegerfield(p, pw_gid);
	setstringfield(p, pw_name);
	setstringfield(p, pw_dir);
	setstringfield(p, pw_shell);
	setstringfield(p, pw_passwd);

	settypemetatable("PosixPasswd");
	return 1;
}
コード例 #3
0
ファイル: net.c プロジェクト: Wurldtech/libnet
static void
setethfield(lua_State* L, int tindex, const char* field, const uint8_t addr[ETHER_ADDR_LEN])
{
    char addrstr[] = "11:22:33:44:55:66";
    eth_addr_t ethaddr;

    memcpy(ethaddr.data, addr, ETHER_ADDR_LEN);

    setstringfield(L, tindex, field, eth_ntop(&ethaddr, addrstr, sizeof(addrstr)));
}
コード例 #4
0
ファイル: net.c プロジェクト: Wurldtech/libnet
static void pushpblock(lua_State* L, libnet_pblock_t* pblock)
{
    int tindex = lua_gettop(L) + 1;
    lua_newtable(L);
    setlstringfield(L, tindex, "buf", pblock->buf, pblock->b_len);
    setintfield(L, tindex, "b_len", pblock->b_len);
    setintfield(L, tindex, "h_len", pblock->h_len);
    setintfield(L, tindex, "copied", pblock->copied);
    setstringfield(L, tindex, "type", libnet_diag_dump_pblock_type(pblock->type));
    setintfield(L, tindex, "flags", pblock->flags);
    setintfield(L, tindex, "ptag", pblock->ptag);
    if(pblock->next)
        setintfield(L, tindex, "next", pblock->next->ptag);
    if(pblock->prev)
        setintfield(L, tindex, "prev", pblock->prev->ptag);
}
コード例 #5
0
static int
pushgroup(lua_State *L, struct group *g)
{
	if (!g)
		return lua_pushnil(L), 1;

	lua_createtable(L, 0, 3);
	setintegerfield(g, gr_gid);
	setstringfield(g, gr_name);
	if (g->gr_mem)
	{
		int i;
		lua_newtable(L);
		for (i = 0; g->gr_mem[i] != NULL; i++)
		{
			lua_pushstring(L, g->gr_mem[i]);
			lua_rawseti(L, -2, i + 1);
		}
		lua_setfield(L, -2, "gr_mem");
	}

	settypemetatable("PosixGroup");
	return 1;
}