Skip to content

Commit

Permalink
feat(socket): bind htonl, htons, ntohl, ntohs
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Jul 23, 2024
1 parent 9511dc3 commit a626b0e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,34 @@ static int lua_if_indextoname(lua_State *L)
return 1;
}

static int lua_htonl(lua_State *L)
{
uint32_t n = luaL_checkinteger(L, 1);
lua_pushinteger(L, htonl(n));
return 1;
}

static int lua_htons(lua_State *L)
{
uint16_t n = luaL_checkinteger(L, 1);
lua_pushinteger(L, htons(n));
return 1;
}

static int lua_ntohl(lua_State *L)
{
uint32_t n = luaL_checkinteger(L, 1);
lua_pushinteger(L, ntohl(n));
return 1;
}

static int lua_ntohs(lua_State *L)
{
uint16_t n = luaL_checkinteger(L, 1);
lua_pushinteger(L, ntohs(n));
return 1;
}

static const luaL_Reg funcs[] = {
{"socket", lua_socket},
{"is_ipv4_address", lua_is_ipv4_address},
Expand All @@ -986,6 +1014,10 @@ static const luaL_Reg funcs[] = {
{"inet_pton", lua_inet_pton},
{"if_nametoindex", lua_if_nametoindex},
{"if_indextoname", lua_if_indextoname},
{"htonl", lua_htonl},
{"htons", lua_htons},
{"ntohl", lua_ntohl},
{"ntohs", lua_ntohs},
{NULL, NULL}
};

Expand Down

0 comments on commit a626b0e

Please sign in to comment.