hostname should be nil if host is ip address, see #2125

This commit is contained in:
Cloud Wu
2025-12-28 10:11:00 +08:00
parent 2a5d6c38ae
commit 351d21d62c

View File

@@ -83,13 +83,18 @@ end
local function connect(host, timeout) local function connect(host, timeout)
local protocol, host, port = check_protocol(host) local protocol, host, port = check_protocol(host)
local hostaddr = host local hostaddr = host
if async_dns and host:find "^[^:]-%D$" then local hostname
-- if ipv6, contains colons if host:find "^[^:]-%D$" then
-- if ipv4, end with a digit -- it's a hostname (not ip address), because
local msg -- ipv6 contains colons
hostaddr, msg = dns.resolve(host) -- ipv4 end with a digit
if not hostaddr then hostname = host
error(string.format("%s dns resolve failed msg:%s", host, msg)) if async_dns then
local msg
hostaddr, msg = dns.resolve(host)
if not hostaddr then
error(string.format("%s dns resolve failed msg:%s", host, msg))
end
end end
end end
@@ -97,7 +102,7 @@ local function connect(host, timeout)
if not fd then if not fd then
error(string.format("%s connect error host:%s, port:%s, timeout:%s", protocol, host, port, timeout)) error(string.format("%s connect error host:%s, port:%s, timeout:%s", protocol, host, port, timeout))
end end
local interface = gen_interface(protocol, fd, host) local interface = gen_interface(protocol, fd, hostname)
if timeout then if timeout then
skynet.timeout(timeout, function() skynet.timeout(timeout, function()
if not interface.finish then if not interface.finish then