aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2013-12-23 17:57:53 +0100
committerKim Alvefur <zash@zash.se>2013-12-23 17:57:53 +0100
commit24056ae3ad82a08483ac2449f1c36923a26358fa (patch)
tree3d7304efa0bb54dab83cad5bf127e08fa61219c2
parentae81ea6edae7c3b151aa831324ff5d80fbc238fa (diff)
downloadprosody-24056ae3ad82a08483ac2449f1c36923a26358fa.tar.gz
prosody-24056ae3ad82a08483ac2449f1c36923a26358fa.zip
net.server_{select,event}: addclient: Use getaddrinfo to detect IP address type if no socket type argument given. (Argument must be given for non-TCP)
-rw-r--r--net/server_event.lua9
-rw-r--r--net/server_select.lua10
2 files changed, 17 insertions, 2 deletions
diff --git a/net/server_event.lua b/net/server_event.lua
index bc67d175..6c8a7632 100644
--- a/net/server_event.lua
+++ b/net/server_event.lua
@@ -46,6 +46,7 @@ local t_concat = table.concat
local has_luasec, ssl = pcall ( require , "ssl" )
local socket = use "socket" or require "socket"
+local getaddrinfo = socket.dns.getaddrinfo
local log = require ("util.logger").init("socket")
@@ -748,7 +749,13 @@ do
return nil, "luasec not found"
end
if not typ then
- typ = "tcp"
+ local addrinfo, err = getaddrinfo(addr)
+ if not addrinfo then return nil, err end
+ if addrinfo[1] and addrinfo[1].family == "inet6" then
+ typ = "tcp6"
+ else
+ typ = "tcp"
+ end
end
local create = socket[typ]
if type( create ) ~= "function" then
diff --git a/net/server_select.lua b/net/server_select.lua
index 537ff440..9c5225c6 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -51,6 +51,7 @@ local coroutine_yield = coroutine.yield
local has_luasec, luasec = pcall ( require , "ssl" )
local luasocket = use "socket" or require "socket"
local luasocket_gettime = luasocket.gettime
+local getaddrinfo = luasocket.dns.getaddrinfo
--// extern lib methods //--
@@ -954,12 +955,19 @@ local addclient = function( address, port, listeners, pattern, sslctx, typ )
err = "luasec not found"
end
if not typ then
- typ = "tcp"
+ local addrinfo, err = getaddrinfo(address)
+ if not addrinfo then return nil, err end
+ if addrinfo[1] and addrinfo[1].family == "inet6" then
+ typ = "tcp6"
+ else
+ typ = "tcp"
+ end
end
local create = luasocket[typ]
if type( create ) ~= "function" then
err = "invalid socket type"
end
+
if err then
out_error( "server.lua, addclient: ", err )
return nil, err