diff --git a/src/SyncClient.cpp b/src/SyncClient.cpp index 953106a..5aa5608 100644 --- a/src/SyncClient.cpp +++ b/src/SyncClient.cpp @@ -110,7 +110,15 @@ static bool dns_resolve(std::string const& target, #endif return false; } - target_parts.push_back(target.substr(0, rindex)); + + std::string host(target.substr(0,rindex)); + // check target is '[ipv6]:port' + if(!ipv4 && !host.empty() && host[0] == '[' && host[host.size()-1] == ']') { + endpoints.emplace_back(target); + return true; + } + + target_parts.push_back(host); target_parts.push_back(target.substr(rindex + 1)); } diff --git a/tst/EtcdResolverTest.cpp b/tst/EtcdResolverTest.cpp index 2d00bf6..14f7ad1 100644 --- a/tst/EtcdResolverTest.cpp +++ b/tst/EtcdResolverTest.cpp @@ -9,6 +9,9 @@ static const std::string etcd_v4_url = etcdv3::detail::resolve_etcd_endpoints("http://127.0.0.1:2379"); static const std::string etcd_v6_url = etcdv3::detail::resolve_etcd_endpoints("http://::1:2379"); +// http://[ipv6]:port url +static const std::string etcd_ipv6_url = + etcdv3::detail::resolve_etcd_endpoints("http://[::1]:2379"); TEST_CASE("test ipv4 connection") { std::cout << "ipv4 endpoints: " << etcd_v4_url << std::endl; @@ -20,4 +23,8 @@ TEST_CASE("test ipv6 connection") { std::cout << "ipv6 endpoints: " << etcd_v6_url << std::endl; etcd::Client etcd(etcd_v6_url); REQUIRE(etcd.head().get().is_ok()); + + std::cout << "ipv6 endpoints: " << etcd_ipv6_url << std::endl; + etcd::Client etcd1(etcd_ipv6_url); + REQUIRE(etcd1.head().get().is_ok()); }