diff --git a/src/SyncClient.cpp b/src/SyncClient.cpp index 5aa5608..cb5b1fb 100644 --- a/src/SyncClient.cpp +++ b/src/SyncClient.cpp @@ -8,6 +8,7 @@ #include #endif +#include #include #include #include @@ -112,10 +113,11 @@ static bool dns_resolve(std::string const& target, } std::string host(target.substr(0,rindex)); - // check target is '[ipv6]:port' + + // host format is [ipv6] if(!ipv4 && !host.empty() && host[0] == '[' && host[host.size()-1] == ']') { - endpoints.emplace_back(target); - return true; + host = target.substr(1, rindex - 2); + ipv6_url = true; } target_parts.push_back(host); @@ -140,6 +142,16 @@ static bool dns_resolve(std::string const& target, } #endif + if (ipv6_url) { + // check valid ipv6 + struct sockaddr_in6 sa6; + if (inet_pton(AF_INET6, target_parts[0].c_str(), &(sa6.sin6_addr)) == 1) { + endpoints.emplace_back(target); + return true; + } + return false; + } + struct addrinfo hints = {}, *addrs; hints.ai_family = ipv4 ? AF_INET : AF_INET6; hints.ai_socktype = SOCK_STREAM;