# HG changeset patch # User Kim Alvefur # Date 1387817873 -3600 # Node ID 958ad646c0f230508c3e0427388a1661a67ca172 # Parent 99d55f12a26f4c5d470409c2b0864f43cf6f655e 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) diff -r 99d55f12a26f -r 958ad646c0f2 net/server_event.lua --- 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 diff -r 99d55f12a26f -r 958ad646c0f2 net/server_select.lua --- 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