Diff

net/server_event.lua @ 9473:5fdda751333a

net.server: Require IP address as argument to addclient (no DNS names) The net.connect API should be used to resolve DNS names first
author Kim Alvefur <zash@zash.se>
date Thu, 11 Oct 2018 15:48:30 +0200
parent 9387:33e52f727f0f
child 9495:89e05b118f6e
line wrap: on
line diff
--- a/net/server_event.lua	Thu Oct 11 14:18:38 2018 +0100
+++ b/net/server_event.lua	Thu Oct 11 15:48:30 2018 +0200
@@ -50,9 +50,10 @@
 local has_luasec, ssl = pcall ( require , "ssl" )
 local socket = require "socket"
 local levent = require "luaevent.core"
+local inet = require "util.net";
+local inet_pton = inet.pton;
 
 local socket_gettime = socket.gettime
-local getaddrinfo = socket.dns.getaddrinfo
 
 local log = require ("util.logger").init("socket")
 
@@ -728,15 +729,15 @@
 		return nil, "luasec not found"
 	end
 	if not typ then
-		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"
+		local n = inet_pton(addr);
+		if not n then return nil, "invalid-ip"; end
+		if #n == 16 then
+			typ = "tcp6";
+		elseif #n == 4 then
+			typ = "tcp4";
 		end
 	end
-	local create = socket[typ]
+	local create = socket[typ] or socket.tcp;
 	if type( create ) ~= "function"  then
 		return nil, "invalid socket type"
 	end