diff options
Diffstat (limited to 'src/inet.c')
-rw-r--r-- | src/inet.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -19,11 +19,13 @@ | |||
19 | static int inet_global_toip(lua_State *L); | 19 | static int inet_global_toip(lua_State *L); |
20 | static int inet_global_tohostname(lua_State *L); | 20 | static int inet_global_tohostname(lua_State *L); |
21 | static void inet_pushresolved(lua_State *L, struct hostent *hp); | 21 | static void inet_pushresolved(lua_State *L, struct hostent *hp); |
22 | static int inet_global_gethostname(lua_State *L); | ||
22 | 23 | ||
23 | /* DNS functions */ | 24 | /* DNS functions */ |
24 | static luaL_reg func[] = { | 25 | static luaL_reg func[] = { |
25 | { "toip", inet_global_toip }, | 26 | { "toip", inet_global_toip }, |
26 | { "tohostname", inet_global_tohostname }, | 27 | { "tohostname", inet_global_tohostname }, |
28 | { "gethostname", inet_global_gethostname}, | ||
27 | { NULL, NULL} | 29 | { NULL, NULL} |
28 | }; | 30 | }; |
29 | 31 | ||
@@ -101,6 +103,25 @@ static int inet_global_tohostname(lua_State *L) | |||
101 | return 2; | 103 | return 2; |
102 | } | 104 | } |
103 | 105 | ||
106 | /*-------------------------------------------------------------------------*\ | ||
107 | * Gets the host name | ||
108 | \*-------------------------------------------------------------------------*/ | ||
109 | static int inet_global_gethostname(lua_State *L) | ||
110 | { | ||
111 | char name[257]; | ||
112 | name[256] = '\0'; | ||
113 | if (gethostname(name, 256) < 0) { | ||
114 | lua_pushnil(L); | ||
115 | lua_pushstring(L, "gethostname failed"); | ||
116 | return 2; | ||
117 | } else { | ||
118 | lua_pushstring(L, name); | ||
119 | return 1; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | |||
124 | |||
104 | /*=========================================================================*\ | 125 | /*=========================================================================*\ |
105 | * Lua methods | 126 | * Lua methods |
106 | \*=========================================================================*/ | 127 | \*=========================================================================*/ |