Software /
code /
prosody
Changeset
5966:958ad646c0f2
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)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 23 Dec 2013 17:57:53 +0100 |
parents | 5965:99d55f12a26f |
children | 5967:3b7206981317 |
files | net/server_event.lua net/server_select.lua |
diffstat | 2 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/net/server_event.lua Mon Dec 23 17:55:41 2013 +0100 +++ b/net/server_event.lua Mon Dec 23 17:57:53 2013 +0100 @@ -46,6 +46,7 @@ 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") @@ -742,7 +743,13 @@ 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
--- a/net/server_select.lua Mon Dec 23 17:55:41 2013 +0100 +++ b/net/server_select.lua Mon Dec 23 17:57:53 2013 +0100 @@ -51,6 +51,7 @@ 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 @@ 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