diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-16 00:06:04 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-16 00:06:04 +0000 |
commit | c51d4acf1c2a8675a3bb043e799ff4390cef47d6 (patch) | |
tree | 345b71aa70b50c964a58980461e147a260fa6e0b /src/inet.c | |
parent | 3099704affa1fda195eb8f3934f6c1f18bf1f706 (diff) | |
download | luasocket-c51d4acf1c2a8675a3bb043e799ff4390cef47d6.tar.gz luasocket-c51d4acf1c2a8675a3bb043e799ff4390cef47d6.tar.bz2 luasocket-c51d4acf1c2a8675a3bb043e799ff4390cef47d6.zip |
Adjusted a few inconsistencies with the manual.
Diffstat (limited to 'src/inet.c')
-rw-r--r-- | src/inet.c | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -20,6 +20,7 @@ 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 | 22 | ||
23 | /* DNS functions */ | ||
23 | static luaL_reg func[] = { | 24 | static luaL_reg func[] = { |
24 | { "toip", inet_global_toip }, | 25 | { "toip", inet_global_toip }, |
25 | { "tohostname", inet_global_tohostname }, | 26 | { "tohostname", inet_global_tohostname }, |
@@ -34,7 +35,19 @@ static luaL_reg func[] = { | |||
34 | \*-------------------------------------------------------------------------*/ | 35 | \*-------------------------------------------------------------------------*/ |
35 | void inet_open(lua_State *L) | 36 | void inet_open(lua_State *L) |
36 | { | 37 | { |
37 | luaL_openlib(L, LUASOCKET_LIBNAME, func, 0); | 38 | lua_pushstring(L, LUASOCKET_LIBNAME); |
39 | lua_gettable(L, LUA_GLOBALSINDEX); | ||
40 | if (lua_isnil(L, -1)) { | ||
41 | lua_pop(L, 1); | ||
42 | lua_newtable(L); | ||
43 | lua_pushstring(L, LUASOCKET_LIBNAME); | ||
44 | lua_pushvalue(L, -2); | ||
45 | lua_settable(L, LUA_GLOBALSINDEX); | ||
46 | } | ||
47 | lua_pushstring(L, "dns"); | ||
48 | lua_newtable(L); | ||
49 | luaL_openlib(L, NULL, func, 0); | ||
50 | lua_settable(L, -3); | ||
38 | lua_pop(L, 1); | 51 | lua_pop(L, 1); |
39 | } | 52 | } |
40 | 53 | ||
@@ -100,10 +113,11 @@ int inet_meth_getpeername(lua_State *L, p_sock ps) | |||
100 | socklen_t peer_len = sizeof(peer); | 113 | socklen_t peer_len = sizeof(peer); |
101 | if (getpeername(*ps, (SA *) &peer, &peer_len) < 0) { | 114 | if (getpeername(*ps, (SA *) &peer, &peer_len) < 0) { |
102 | lua_pushnil(L); | 115 | lua_pushnil(L); |
103 | return 1; | 116 | lua_pushstring(L, "getpeername failed"); |
117 | } else { | ||
118 | lua_pushstring(L, inet_ntoa(peer.sin_addr)); | ||
119 | lua_pushnumber(L, ntohs(peer.sin_port)); | ||
104 | } | 120 | } |
105 | lua_pushstring(L, inet_ntoa(peer.sin_addr)); | ||
106 | lua_pushnumber(L, ntohs(peer.sin_port)); | ||
107 | return 2; | 121 | return 2; |
108 | } | 122 | } |
109 | 123 | ||
@@ -116,10 +130,11 @@ int inet_meth_getsockname(lua_State *L, p_sock ps) | |||
116 | socklen_t local_len = sizeof(local); | 130 | socklen_t local_len = sizeof(local); |
117 | if (getsockname(*ps, (SA *) &local, &local_len) < 0) { | 131 | if (getsockname(*ps, (SA *) &local, &local_len) < 0) { |
118 | lua_pushnil(L); | 132 | lua_pushnil(L); |
119 | return 1; | 133 | lua_pushstring(L, "getsockname failed"); |
134 | } else { | ||
135 | lua_pushstring(L, inet_ntoa(local.sin_addr)); | ||
136 | lua_pushnumber(L, ntohs(local.sin_port)); | ||
120 | } | 137 | } |
121 | lua_pushstring(L, inet_ntoa(local.sin_addr)); | ||
122 | lua_pushnumber(L, ntohs(local.sin_port)); | ||
123 | return 2; | 138 | return 2; |
124 | } | 139 | } |
125 | 140 | ||