aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_select.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-11 15:48:30 +0200
committerKim Alvefur <zash@zash.se>2018-10-11 15:48:30 +0200
commit7953747a89caaf00c4587a3d238329a2ce992390 (patch)
tree1f23a6726a51d1b6c2dc854dd34812f3e6ed656c /net/server_select.lua
parent9a1027d82045261d48515b8aa5de606cb02b49b8 (diff)
downloadprosody-7953747a89caaf00c4587a3d238329a2ce992390.tar.gz
prosody-7953747a89caaf00c4587a3d238329a2ce992390.zip
net.server: Require IP address as argument to addclient (no DNS names)
The net.connect API should be used to resolve DNS names first
Diffstat (limited to 'net/server_select.lua')
-rw-r--r--net/server_select.lua17
1 files changed, 10 insertions, 7 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index cd97f0a6..c5f9004c 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -50,7 +50,8 @@ local coroutine_yield = coroutine.yield
local has_luasec, luasec = pcall ( require , "ssl" )
local luasocket = use "socket" or require "socket"
local luasocket_gettime = luasocket.gettime
-local getaddrinfo = luasocket.dns.getaddrinfo
+local inet = require "util.net";
+local inet_pton = inet.pton;
--// extern lib methods //--
@@ -1007,14 +1008,16 @@ local addclient = function( address, port, listeners, pattern, sslctx, typ )
elseif sslctx and not has_luasec then
err = "luasec not found"
end
- if getaddrinfo and not typ then
- local addrinfo, err = getaddrinfo(address)
- if not addrinfo then return nil, err end
- if addrinfo[1] and addrinfo[1].family == "inet6" then
- typ = "tcp6"
+ if not typ then
+ 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 = luasocket[typ or "tcp"]
+ local create = luasocket[typ] or luasocket.tcp;
if type( create ) ~= "function" then
err = "invalid socket type"
end