@@ -976,6 +976,34 @@ static int lua_if_indextoname(lua_State *L)
976
976
return 1 ;
977
977
}
978
978
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
+
979
1007
static const luaL_Reg funcs [] = {
980
1008
{"socket" , lua_socket },
981
1009
{"is_ipv4_address" , lua_is_ipv4_address },
@@ -986,6 +1014,10 @@ static const luaL_Reg funcs[] = {
986
1014
{"inet_pton" , lua_inet_pton },
987
1015
{"if_nametoindex" , lua_if_nametoindex },
988
1016
{"if_indextoname" , lua_if_indextoname },
1017
+ {"htonl" , lua_htonl },
1018
+ {"htons" , lua_htons },
1019
+ {"ntohl" , lua_ntohl },
1020
+ {"ntohs" , lua_ntohs },
989
1021
{NULL , NULL }
990
1022
};
991
1023
0 commit comments