Skip to content

Commit 464dd05

Browse files
authored
fix: optional brackets were removed for ipv6 host (#4759)
fixed: IPv6 replication issues #4622
1 parent 5facf12 commit 464dd05

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/server/protocol_client.cc

+11-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,17 @@ ProtocolClient::~ProtocolClient() {
135135

136136
error_code ProtocolClient::ResolveHostDns() {
137137
char ip_addr[INET6_ADDRSTRLEN];
138-
auto ec = util::fb2::DnsResolve(server_context_.host, 0, ip_addr, ProactorBase::me());
138+
139+
// IPv6 address can be enclosed in square brackets.
140+
// https://www.rfc-editor.org/rfc/rfc2732#section-2
141+
// We need to remove the brackets before resolving the DNS.
142+
// Enclosed IPv6 addresses can't be resolved by the DNS resolver.
143+
std::string host = server_context_.host;
144+
if (!host.empty() && host.front() == '[' && host.back() == ']') {
145+
host = host.substr(1, host.size() - 2);
146+
}
147+
148+
auto ec = util::fb2::DnsResolve(host, 0, ip_addr, ProactorBase::me());
139149
if (ec) {
140150
LOG(ERROR) << "Dns error " << ec << ", host: " << server_context_.host;
141151
return make_error_code(errc::host_unreachable);

0 commit comments

Comments
 (0)