diff options
author | Kim Alvefur <zash@zash.se> | 2013-12-23 17:57:53 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2013-12-23 17:57:53 +0100 |
commit | bcb9af93c22dba3008a79ecd44eb947c2c7cd910 (patch) | |
tree | 90ef8d101114a4db8ee86dfa99884d8a7c586b81 /net/server_select.lua | |
parent | 24118d8f74b097bf71f61d240c855ff5655e510d (diff) | |
download | prosody-bcb9af93c22dba3008a79ecd44eb947c2c7cd910.tar.gz prosody-bcb9af93c22dba3008a79ecd44eb947c2c7cd910.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)
Diffstat (limited to 'net/server_select.lua')
-rw-r--r-- | net/server_select.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/net/server_select.lua b/net/server_select.lua index 1ce3c8c7..ee9cac7e 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 //-- @@ -942,12 +943,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 |