diff options
author | Kim Alvefur <zash@zash.se> | 2018-10-11 15:48:30 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2018-10-11 15:48:30 +0200 |
commit | 7953747a89caaf00c4587a3d238329a2ce992390 (patch) | |
tree | 1f23a6726a51d1b6c2dc854dd34812f3e6ed656c /net/server_event.lua | |
parent | 9a1027d82045261d48515b8aa5de606cb02b49b8 (diff) | |
download | prosody-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_event.lua')
-rw-r--r-- | net/server_event.lua | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/net/server_event.lua b/net/server_event.lua index 9fde558e..5a4dc1a4 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -50,9 +50,10 @@ local coroutine_yield = coroutine.yield 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 @@ local function addclient( addr, serverport, listener, pattern, sslctx, typ ) 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 |