diff options
-rw-r--r-- | src/inet.c | 3 | ||||
-rw-r--r-- | src/tcp.c | 1 | ||||
-rw-r--r-- | test/test_bind.lua | 6 |
3 files changed, 9 insertions, 1 deletions
@@ -478,6 +478,9 @@ const char *inet_trybind(p_socket ps, const char *address, const char *serv, | |||
478 | struct addrinfo *iterator = NULL, *resolved = NULL; | 478 | struct addrinfo *iterator = NULL, *resolved = NULL; |
479 | const char *err = NULL; | 479 | const char *err = NULL; |
480 | t_socket sock = *ps; | 480 | t_socket sock = *ps; |
481 | /* translate luasocket special values to C */ | ||
482 | if (strcmp(address, "*") == 0) address = NULL; | ||
483 | if (!serv) serv = "0"; | ||
481 | /* try resolving */ | 484 | /* try resolving */ |
482 | err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved)); | 485 | err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved)); |
483 | if (err) { | 486 | if (err) { |
@@ -222,7 +222,6 @@ static int meth_bind(lua_State *L) | |||
222 | bindhints.ai_socktype = SOCK_STREAM; | 222 | bindhints.ai_socktype = SOCK_STREAM; |
223 | bindhints.ai_family = tcp->family; | 223 | bindhints.ai_family = tcp->family; |
224 | bindhints.ai_flags = AI_PASSIVE; | 224 | bindhints.ai_flags = AI_PASSIVE; |
225 | address = strcmp(address, "*")? address: NULL; | ||
226 | err = inet_trybind(&tcp->sock, address, port, &bindhints); | 225 | err = inet_trybind(&tcp->sock, address, port, &bindhints); |
227 | if (err) { | 226 | if (err) { |
228 | lua_pushnil(L); | 227 | lua_pushnil(L); |
diff --git a/test/test_bind.lua b/test/test_bind.lua new file mode 100644 index 0000000..93c42d7 --- /dev/null +++ b/test/test_bind.lua | |||
@@ -0,0 +1,6 @@ | |||
1 | local socket = require "socket" | ||
2 | local u = socket.udp() assert(u:setsockname("*", 5088)) u:close() | ||
3 | local u = socket.udp() assert(u:setsockname("*", 0)) u:close() | ||
4 | local t = socket.tcp() assert(t:bind("*", 5088)) t:close() | ||
5 | local t = socket.tcp() assert(t:bind("*", 0)) t:close() | ||
6 | print("done!") \ No newline at end of file | ||