Fix. setsockname fails with "*" as host.

Add. test_bind.lua
This commit is contained in:
moteus 2013-05-27 11:25:31 +04:00
parent 56dbda39ed
commit e54f78c61c
3 changed files with 9 additions and 1 deletions

View File

@ -478,6 +478,9 @@ const char *inet_trybind(p_socket ps, const char *address, const char *serv,
struct addrinfo *iterator = NULL, *resolved = NULL;
const char *err = NULL;
t_socket sock = *ps;
/* translate luasocket special values to C */
if (strcmp(address, "*") == 0) address = NULL;
if (!serv) serv = "0";
/* try resolving */
err = socket_gaistrerror(getaddrinfo(address, serv, bindhints, &resolved));
if (err) {

View File

@ -222,7 +222,6 @@ static int meth_bind(lua_State *L)
bindhints.ai_socktype = SOCK_STREAM;
bindhints.ai_family = tcp->family;
bindhints.ai_flags = AI_PASSIVE;
address = strcmp(address, "*")? address: NULL;
err = inet_trybind(&tcp->sock, address, port, &bindhints);
if (err) {
lua_pushnil(L);

6
test/test_bind.lua Normal file
View File

@ -0,0 +1,6 @@
local socket = require "socket"
local u = socket.udp() assert(u:setsockname("*", 5088)) u:close()
local u = socket.udp() assert(u:setsockname("*", 0)) u:close()
local t = socket.tcp() assert(t:bind("*", 5088)) t:close()
local t = socket.tcp() assert(t:bind("*", 0)) t:close()
print("done!")