aboutsummaryrefslogtreecommitdiff
path: root/src/inet.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/inet.c')
-rw-r--r--src/inet.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/inet.c b/src/inet.c
index dff4bf2..d626b86 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -19,11 +19,13 @@
19static int inet_global_toip(lua_State *L); 19static int inet_global_toip(lua_State *L);
20static int inet_global_tohostname(lua_State *L); 20static int inet_global_tohostname(lua_State *L);
21static void inet_pushresolved(lua_State *L, struct hostent *hp); 21static void inet_pushresolved(lua_State *L, struct hostent *hp);
22static int inet_global_gethostname(lua_State *L);
22 23
23/* DNS functions */ 24/* DNS functions */
24static luaL_reg func[] = { 25static 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\*-------------------------------------------------------------------------*/
109static 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\*=========================================================================*/