Skip to content

Commit a626b0e

Browse files
committed
feat(socket): bind htonl, htons, ntohl, ntohs
Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
1 parent 9511dc3 commit a626b0e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

socket.c

+32
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,34 @@ static int lua_if_indextoname(lua_State *L)
976976
return 1;
977977
}
978978

979+
static int lua_htonl(lua_State *L)
980+
{
981+
uint32_t n = luaL_checkinteger(L, 1);
982+
lua_pushinteger(L, htonl(n));
983+
return 1;
984+
}
985+
986+
static int lua_htons(lua_State *L)
987+
{
988+
uint16_t n = luaL_checkinteger(L, 1);
989+
lua_pushinteger(L, htons(n));
990+
return 1;
991+
}
992+
993+
static int lua_ntohl(lua_State *L)
994+
{
995+
uint32_t n = luaL_checkinteger(L, 1);
996+
lua_pushinteger(L, ntohl(n));
997+
return 1;
998+
}
999+
1000+
static int lua_ntohs(lua_State *L)
1001+
{
1002+
uint16_t n = luaL_checkinteger(L, 1);
1003+
lua_pushinteger(L, ntohs(n));
1004+
return 1;
1005+
}
1006+
9791007
static const luaL_Reg funcs[] = {
9801008
{"socket", lua_socket},
9811009
{"is_ipv4_address", lua_is_ipv4_address},
@@ -986,6 +1014,10 @@ static const luaL_Reg funcs[] = {
9861014
{"inet_pton", lua_inet_pton},
9871015
{"if_nametoindex", lua_if_nametoindex},
9881016
{"if_indextoname", lua_if_indextoname},
1017+
{"htonl", lua_htonl},
1018+
{"htons", lua_htons},
1019+
{"ntohl", lua_ntohl},
1020+
{"ntohs", lua_ntohs},
9891021
{NULL, NULL}
9901022
};
9911023

0 commit comments

Comments
 (0)