# HG changeset patch # User Kim Alvefur # Date 1574566232 -3600 # Node ID 55490be0dc2948bed3e7d6731104886f65e22ddc # Parent 6e3fa523c9698f33727422bab50c1638539f4f33# Parent fcfc8f4d14a83307a1a2a13f66515f0a4b45b49d Merge 0.11->trunk diff -r 6e3fa523c969 -r 55490be0dc29 net/resolvers/basic.lua --- a/net/resolvers/basic.lua Sun Nov 24 00:02:48 2019 +0100 +++ b/net/resolvers/basic.lua Sun Nov 24 04:30:32 2019 +0100 @@ -34,16 +34,6 @@ self:next(cb); end - local is_ip = inet_pton(self.hostname); - if is_ip then - if #is_ip == 16 then - cb(self.conn_type.."6", self.hostname, self.port, self.extra); - elseif #is_ip == 4 then - cb(self.conn_type.."4", self.hostname, self.port, self.extra); - end - return; - end - -- Resolve DNS to target list local dns_resolver = adns.resolver(); dns_resolver:lookup(function (answer) @@ -66,11 +56,27 @@ end local function new(hostname, port, conn_type, extra) + local ascii_host = idna_to_ascii(hostname); + local targets = nil; + + local is_ip = inet_pton(hostname); + if not is_ip and hostname:sub(1,1) == '[' then + is_ip = inet_pton(hostname:sub(2,-2)); + end + if is_ip then + if #is_ip == 16 then + targets = { { conn_type.."6", hostname, port, extra } }; + elseif #is_ip == 4 then + targets = { { conn_type.."4", hostname, port, extra } }; + end + end + return setmetatable({ - hostname = idna_to_ascii(hostname); + hostname = ascii_host; port = port; conn_type = conn_type or "tcp"; extra = extra; + targets = targets; }, resolver_mt); end