From 56dbda39ed07faf2c14427797fe104213f734e00 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 11:20:52 +0400 Subject: Fix. getaddrinfo returns garbage as address on Windows. Add. test_getaddrinfo.lua --- test/test_getaddrinfo.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/test_getaddrinfo.lua (limited to 'test') diff --git a/test/test_getaddrinfo.lua b/test/test_getaddrinfo.lua new file mode 100644 index 0000000..4b52ff9 --- /dev/null +++ b/test/test_getaddrinfo.lua @@ -0,0 +1,15 @@ +local socket = require "socket" +local addresses = assert(socket.dns.getaddrinfo("localhost")) +assert(type(addresses) == 'table') + +local ipv4mask = "^%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?$" + +for i, alt in ipairs(addresses) do + if alt.family == 'inet' then + assert(type(alt.addr) == 'string') + assert(alt.addr:find(ipv4mask)) + assert(alt.addr == '127.0.0.1') + end +end + +print("done!") -- cgit v1.2.3-55-g6feb From e54f78c61cac7b0d7fe1e89d337b9ab06f40bdb0 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 11:25:31 +0400 Subject: Fix. setsockname fails with "*" as host. Add. test_bind.lua --- src/inet.c | 3 +++ src/tcp.c | 1 - test/test_bind.lua | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/test_bind.lua (limited to 'test') diff --git a/src/inet.c b/src/inet.c index b28852b..0469756 100644 --- a/src/inet.c +++ b/src/inet.c @@ -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) { diff --git a/src/tcp.c b/src/tcp.c index ca8eec2..60c1e8a 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -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); 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 @@ +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!") \ No newline at end of file -- cgit v1.2.3-55-g6feb From bd51d8c1a5bb30e6a358dee6e85963f777edfff4 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 11:26:35 +0400 Subject: Fix. Optional IPv6 test --- test/testclnt.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/testclnt.lua b/test/testclnt.lua index 8acb3d0..315783b 100644 --- a/test/testclnt.lua +++ b/test/testclnt.lua @@ -642,7 +642,10 @@ local tcp_methods = { "shutdown", } test_methods(socket.tcp(), tcp_methods) -test_methods(socket.tcp6(), tcp_methods) +do local sock = socket.tcp6() +if sock then test_methods(socket.tcp6(), tcp_methods) +else io.stderr:write("Warning! IPv6 does not support!\n") end +end local udp_methods = { "close", @@ -666,7 +669,10 @@ local udp_methods = { ------------------------------------------------------------------------ test_methods(socket.udp(), udp_methods) -test_methods(socket.udp6(), udp_methods) +do local sock = socket.tcp6() +if sock then test_methods(socket.udp6(), udp_methods) +else io.stderr:write("Warning! IPv6 does not support!\n") end +end test("partial receive") test_partialrecv() -- cgit v1.2.3-55-g6feb