Diff

net/server_event.lua @ 6819:ffb2b5e31456

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 6818:ae9d1289a868
child 6820:40d50c239564
child 6849:0455b9686e16
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")
 
@@ -748,7 +749,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