diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-24 02:47:24 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-01-24 02:47:24 +0000 |
| commit | 62a4c505e488c714e8795ea85564504562d30301 (patch) | |
| tree | f270f53f26905b7275cea172e52ebc269a41c695 /src/inet.c | |
| parent | 0c9f420a3549df3fb331bb24157b65a3301641d4 (diff) | |
| download | luasocket-62a4c505e488c714e8795ea85564504562d30301.tar.gz luasocket-62a4c505e488c714e8795ea85564504562d30301.tar.bz2 luasocket-62a4c505e488c714e8795ea85564504562d30301.zip | |
Working on the manual...
Making better tests for error messages.
Changed a few names.
Moved gethostname to inet.c.
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 | \*=========================================================================*/ |
