fix: optional brackets were removed for ipv6 host (#4759)

fixed: IPv6 replication issues #4622
This commit is contained in:
Volodymyr Yavdoshenko 2025-03-15 10:23:13 +02:00 committed by GitHub
parent 5facf12836
commit 464dd0522e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

2
helio

@ -1 +1 @@
Subproject commit 6e29a5af38cb9e99be37469a87c6faac7114f55b
Subproject commit 309cf5816cee5eb732f31311b73bcdb31f51d378

View file

@ -135,7 +135,17 @@ ProtocolClient::~ProtocolClient() {
error_code ProtocolClient::ResolveHostDns() {
char ip_addr[INET6_ADDRSTRLEN];
auto ec = util::fb2::DnsResolve(server_context_.host, 0, ip_addr, ProactorBase::me());
// IPv6 address can be enclosed in square brackets.
// https://www.rfc-editor.org/rfc/rfc2732#section-2
// We need to remove the brackets before resolving the DNS.
// Enclosed IPv6 addresses can't be resolved by the DNS resolver.
std::string host = server_context_.host;
if (!host.empty() && host.front() == '[' && host.back() == ']') {
host = host.substr(1, host.size() - 2);
}
auto ec = util::fb2::DnsResolve(host, 0, ip_addr, ProactorBase::me());
if (ec) {
LOG(ERROR) << "Dns error " << ec << ", host: " << server_context_.host;
return make_error_code(errc::host_unreachable);