diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-06-11 01:42:18 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-06-11 01:42:18 +0000 |
commit | f330540576031528f0daac231c61d4dd06e8ba1e (patch) | |
tree | 8f9cd79ac7d4ec937413bbae8a90e8782c1afe18 /src/inet.c | |
parent | 58bdb658aaa1c30a8f3bed46eef880d308fae582 (diff) | |
download | luasocket-f330540576031528f0daac231c61d4dd06e8ba1e.tar.gz luasocket-f330540576031528f0daac231c61d4dd06e8ba1e.tar.bz2 luasocket-f330540576031528f0daac231c61d4dd06e8ba1e.zip |
Compiles and runs on linux and windows, using DLLs!
Diffstat (limited to 'src/inet.c')
-rw-r--r-- | src/inet.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -19,10 +19,6 @@ static int inet_global_tohostname(lua_State *L); | |||
19 | 19 | ||
20 | static void inet_pushresolved(lua_State *L, struct hostent *hp); | 20 | static void inet_pushresolved(lua_State *L, struct hostent *hp); |
21 | 21 | ||
22 | #ifdef INET_ATON | ||
23 | static int inet_aton(const char *cp, struct in_addr *inp); | ||
24 | #endif | ||
25 | |||
26 | static luaL_reg func[] = { | 22 | static luaL_reg func[] = { |
27 | { "toip", inet_global_toip }, | 23 | { "toip", inet_global_toip }, |
28 | { "tohostname", inet_global_tohostname }, | 24 | { "tohostname", inet_global_tohostname }, |
@@ -196,9 +192,11 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp) | |||
196 | * Returns | 192 | * Returns |
197 | * NULL in case of success, error message otherwise | 193 | * NULL in case of success, error message otherwise |
198 | \*-------------------------------------------------------------------------*/ | 194 | \*-------------------------------------------------------------------------*/ |
199 | const char *inet_tryconnect(p_sock ps, const char *address, ushort port) | 195 | const char *inet_tryconnect(p_sock ps, const char *address, |
196 | unsigned short port) | ||
200 | { | 197 | { |
201 | struct sockaddr_in remote; | 198 | struct sockaddr_in remote; |
199 | const char *err; | ||
202 | memset(&remote, 0, sizeof(remote)); | 200 | memset(&remote, 0, sizeof(remote)); |
203 | remote.sin_family = AF_INET; | 201 | remote.sin_family = AF_INET; |
204 | remote.sin_port = htons(port); | 202 | remote.sin_port = htons(port); |
@@ -213,7 +211,7 @@ const char *inet_tryconnect(p_sock ps, const char *address, ushort port) | |||
213 | } | 211 | } |
214 | } else remote.sin_family = AF_UNSPEC; | 212 | } else remote.sin_family = AF_UNSPEC; |
215 | sock_setblocking(ps); | 213 | sock_setblocking(ps); |
216 | const char *err = sock_connect(ps, (SA *) &remote, sizeof(remote)); | 214 | err = sock_connect(ps, (SA *) &remote, sizeof(remote)); |
217 | if (err) { | 215 | if (err) { |
218 | sock_destroy(ps); | 216 | sock_destroy(ps); |
219 | *ps = SOCK_INVALID; | 217 | *ps = SOCK_INVALID; |
@@ -233,10 +231,11 @@ const char *inet_tryconnect(p_sock ps, const char *address, ushort port) | |||
233 | * Returns | 231 | * Returns |
234 | * NULL in case of success, error message otherwise | 232 | * NULL in case of success, error message otherwise |
235 | \*-------------------------------------------------------------------------*/ | 233 | \*-------------------------------------------------------------------------*/ |
236 | const char *inet_trybind(p_sock ps, const char *address, ushort port, | 234 | const char *inet_trybind(p_sock ps, const char *address, unsigned short port, |
237 | int backlog) | 235 | int backlog) |
238 | { | 236 | { |
239 | struct sockaddr_in local; | 237 | struct sockaddr_in local; |
238 | const char *err; | ||
240 | memset(&local, 0, sizeof(local)); | 239 | memset(&local, 0, sizeof(local)); |
241 | /* address is either wildcard or a valid ip address */ | 240 | /* address is either wildcard or a valid ip address */ |
242 | local.sin_addr.s_addr = htonl(INADDR_ANY); | 241 | local.sin_addr.s_addr = htonl(INADDR_ANY); |
@@ -251,7 +250,7 @@ const char *inet_trybind(p_sock ps, const char *address, ushort port, | |||
251 | memcpy(&local.sin_addr, *addr, sizeof(struct in_addr)); | 250 | memcpy(&local.sin_addr, *addr, sizeof(struct in_addr)); |
252 | } | 251 | } |
253 | sock_setblocking(ps); | 252 | sock_setblocking(ps); |
254 | const char *err = sock_bind(ps, (SA *) &local, sizeof(local)); | 253 | err = sock_bind(ps, (SA *) &local, sizeof(local)); |
255 | if (err) { | 254 | if (err) { |
256 | sock_destroy(ps); | 255 | sock_destroy(ps); |
257 | *ps = SOCK_INVALID; | 256 | *ps = SOCK_INVALID; |
@@ -279,8 +278,8 @@ const char *inet_trycreate(p_sock ps, int type) | |||
279 | * Some systems do not provide this so that we provide our own. It's not | 278 | * Some systems do not provide this so that we provide our own. It's not |
280 | * marvelously fast, but it works just fine. | 279 | * marvelously fast, but it works just fine. |
281 | \*-------------------------------------------------------------------------*/ | 280 | \*-------------------------------------------------------------------------*/ |
282 | #ifdef COMPAT_INETATON | 281 | #ifdef INET_ATON |
283 | static int inet_aton(const char *cp, struct in_addr *inp) | 282 | int inet_aton(const char *cp, struct in_addr *inp) |
284 | { | 283 | { |
285 | unsigned int a = 0, b = 0, c = 0, d = 0; | 284 | unsigned int a = 0, b = 0, c = 0, d = 0; |
286 | int n = 0, r; | 285 | int n = 0, r; |