Software /
code /
prosody
Diff
net/server_event.lua @ 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 |
parent | 5965:99d55f12a26f |
child | 5967:3b7206981317 |
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