diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-10-07 04:40:59 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-10-07 04:40:59 +0000 |
| commit | f4dadea763c1959a27dead24df3ee6c54c209842 (patch) | |
| tree | c13b294a8ca5438d59b60e3f5a25a4f7c1fc9a1b /src/inet.c | |
| parent | 562d8cceb704a96a7b2f9acc4bc229ab9f5c6541 (diff) | |
| download | luasocket-f4dadea763c1959a27dead24df3ee6c54c209842.tar.gz luasocket-f4dadea763c1959a27dead24df3ee6c54c209842.tar.bz2 luasocket-f4dadea763c1959a27dead24df3ee6c54c209842.zip | |
Before compiling on Windows.
Diffstat (limited to 'src/inet.c')
| -rw-r--r-- | src/inet.c | 40 |
1 files changed, 20 insertions, 20 deletions
| @@ -53,9 +53,9 @@ int inet_open(lua_State *L) | |||
| 53 | static int inet_gethost(const char *address, struct hostent **hp) { | 53 | static int inet_gethost(const char *address, struct hostent **hp) { |
| 54 | struct in_addr addr; | 54 | struct in_addr addr; |
| 55 | if (inet_aton(address, &addr)) | 55 | if (inet_aton(address, &addr)) |
| 56 | return sock_gethostbyaddr((char *) &addr, sizeof(addr), hp); | 56 | return socket_gethostbyaddr((char *) &addr, sizeof(addr), hp); |
| 57 | else | 57 | else |
| 58 | return sock_gethostbyname(address, hp); | 58 | return socket_gethostbyname(address, hp); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | /*-------------------------------------------------------------------------*\ | 61 | /*-------------------------------------------------------------------------*\ |
| @@ -68,7 +68,7 @@ static int inet_global_tohostname(lua_State *L) { | |||
| 68 | int err = inet_gethost(address, &hp); | 68 | int err = inet_gethost(address, &hp); |
| 69 | if (err != IO_DONE) { | 69 | if (err != IO_DONE) { |
| 70 | lua_pushnil(L); | 70 | lua_pushnil(L); |
| 71 | lua_pushstring(L, sock_hoststrerror(err)); | 71 | lua_pushstring(L, socket_hoststrerror(err)); |
| 72 | return 2; | 72 | return 2; |
| 73 | } | 73 | } |
| 74 | lua_pushstring(L, hp->h_name); | 74 | lua_pushstring(L, hp->h_name); |
| @@ -87,7 +87,7 @@ static int inet_global_toip(lua_State *L) | |||
| 87 | int err = inet_gethost(address, &hp); | 87 | int err = inet_gethost(address, &hp); |
| 88 | if (err != IO_DONE) { | 88 | if (err != IO_DONE) { |
| 89 | lua_pushnil(L); | 89 | lua_pushnil(L); |
| 90 | lua_pushstring(L, sock_hoststrerror(err)); | 90 | lua_pushstring(L, socket_hoststrerror(err)); |
| 91 | return 2; | 91 | return 2; |
| 92 | } | 92 | } |
| 93 | lua_pushstring(L, inet_ntoa(*((struct in_addr *) hp->h_addr))); | 93 | lua_pushstring(L, inet_ntoa(*((struct in_addr *) hp->h_addr))); |
| @@ -121,7 +121,7 @@ static int inet_global_gethostname(lua_State *L) | |||
| 121 | /*-------------------------------------------------------------------------*\ | 121 | /*-------------------------------------------------------------------------*\ |
| 122 | * Retrieves socket peer name | 122 | * Retrieves socket peer name |
| 123 | \*-------------------------------------------------------------------------*/ | 123 | \*-------------------------------------------------------------------------*/ |
| 124 | int inet_meth_getpeername(lua_State *L, p_sock ps) | 124 | int inet_meth_getpeername(lua_State *L, p_socket ps) |
| 125 | { | 125 | { |
| 126 | struct sockaddr_in peer; | 126 | struct sockaddr_in peer; |
| 127 | socklen_t peer_len = sizeof(peer); | 127 | socklen_t peer_len = sizeof(peer); |
| @@ -138,7 +138,7 @@ int inet_meth_getpeername(lua_State *L, p_sock ps) | |||
| 138 | /*-------------------------------------------------------------------------*\ | 138 | /*-------------------------------------------------------------------------*\ |
| 139 | * Retrieves socket local name | 139 | * Retrieves socket local name |
| 140 | \*-------------------------------------------------------------------------*/ | 140 | \*-------------------------------------------------------------------------*/ |
| 141 | int inet_meth_getsockname(lua_State *L, p_sock ps) | 141 | int inet_meth_getsockname(lua_State *L, p_socket ps) |
| 142 | { | 142 | { |
| 143 | struct sockaddr_in local; | 143 | struct sockaddr_in local; |
| 144 | socklen_t local_len = sizeof(local); | 144 | socklen_t local_len = sizeof(local); |
| @@ -198,15 +198,15 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp) | |||
| 198 | /*-------------------------------------------------------------------------*\ | 198 | /*-------------------------------------------------------------------------*\ |
| 199 | * Tries to create a new inet socket | 199 | * Tries to create a new inet socket |
| 200 | \*-------------------------------------------------------------------------*/ | 200 | \*-------------------------------------------------------------------------*/ |
| 201 | const char *inet_trycreate(p_sock ps, int type) { | 201 | const char *inet_trycreate(p_socket ps, int type) { |
| 202 | return sock_strerror(sock_create(ps, AF_INET, type, 0)); | 202 | return socket_strerror(socket_create(ps, AF_INET, type, 0)); |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | /*-------------------------------------------------------------------------*\ | 205 | /*-------------------------------------------------------------------------*\ |
| 206 | * Tries to connect to remote address (address, port) | 206 | * Tries to connect to remote address (address, port) |
| 207 | \*-------------------------------------------------------------------------*/ | 207 | \*-------------------------------------------------------------------------*/ |
| 208 | const char *inet_tryconnect(p_sock ps, const char *address, | 208 | const char *inet_tryconnect(p_socket ps, const char *address, |
| 209 | unsigned short port, p_tm tm) | 209 | unsigned short port, p_timeout tm) |
| 210 | { | 210 | { |
| 211 | struct sockaddr_in remote; | 211 | struct sockaddr_in remote; |
| 212 | int err; | 212 | int err; |
| @@ -217,20 +217,20 @@ const char *inet_tryconnect(p_sock ps, const char *address, | |||
| 217 | if (!inet_aton(address, &remote.sin_addr)) { | 217 | if (!inet_aton(address, &remote.sin_addr)) { |
| 218 | struct hostent *hp = NULL; | 218 | struct hostent *hp = NULL; |
| 219 | struct in_addr **addr; | 219 | struct in_addr **addr; |
| 220 | err = sock_gethostbyname(address, &hp); | 220 | err = socket_gethostbyname(address, &hp); |
| 221 | if (err != IO_DONE) return sock_hoststrerror(err); | 221 | if (err != IO_DONE) return socket_hoststrerror(err); |
| 222 | addr = (struct in_addr **) hp->h_addr_list; | 222 | addr = (struct in_addr **) hp->h_addr_list; |
| 223 | memcpy(&remote.sin_addr, *addr, sizeof(struct in_addr)); | 223 | memcpy(&remote.sin_addr, *addr, sizeof(struct in_addr)); |
| 224 | } | 224 | } |
| 225 | } else remote.sin_family = AF_UNSPEC; | 225 | } else remote.sin_family = AF_UNSPEC; |
| 226 | err = sock_connect(ps, (SA *) &remote, sizeof(remote), tm); | 226 | err = socket_connect(ps, (SA *) &remote, sizeof(remote), tm); |
| 227 | return sock_strerror(err); | 227 | return socket_strerror(err); |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | /*-------------------------------------------------------------------------*\ | 230 | /*-------------------------------------------------------------------------*\ |
| 231 | * Tries to bind socket to (address, port) | 231 | * Tries to bind socket to (address, port) |
| 232 | \*-------------------------------------------------------------------------*/ | 232 | \*-------------------------------------------------------------------------*/ |
| 233 | const char *inet_trybind(p_sock ps, const char *address, unsigned short port) | 233 | const char *inet_trybind(p_socket ps, const char *address, unsigned short port) |
| 234 | { | 234 | { |
| 235 | struct sockaddr_in local; | 235 | struct sockaddr_in local; |
| 236 | int err; | 236 | int err; |
| @@ -242,14 +242,14 @@ const char *inet_trybind(p_sock ps, const char *address, unsigned short port) | |||
| 242 | if (strcmp(address, "*") && !inet_aton(address, &local.sin_addr)) { | 242 | if (strcmp(address, "*") && !inet_aton(address, &local.sin_addr)) { |
| 243 | struct hostent *hp = NULL; | 243 | struct hostent *hp = NULL; |
| 244 | struct in_addr **addr; | 244 | struct in_addr **addr; |
| 245 | err = sock_gethostbyname(address, &hp); | 245 | err = socket_gethostbyname(address, &hp); |
| 246 | if (err != IO_DONE) return sock_hoststrerror(err); | 246 | if (err != IO_DONE) return socket_hoststrerror(err); |
| 247 | addr = (struct in_addr **) hp->h_addr_list; | 247 | addr = (struct in_addr **) hp->h_addr_list; |
| 248 | memcpy(&local.sin_addr, *addr, sizeof(struct in_addr)); | 248 | memcpy(&local.sin_addr, *addr, sizeof(struct in_addr)); |
| 249 | } | 249 | } |
| 250 | err = sock_bind(ps, (SA *) &local, sizeof(local)); | 250 | err = socket_bind(ps, (SA *) &local, sizeof(local)); |
| 251 | if (err != IO_DONE) sock_destroy(ps); | 251 | if (err != IO_DONE) socket_destroy(ps); |
| 252 | return sock_strerror(err); | 252 | return socket_strerror(err); |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | /*-------------------------------------------------------------------------*\ | 255 | /*-------------------------------------------------------------------------*\ |
