diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-07-01 13:09:22 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-07-01 13:09:22 +0300 |
commit | 4b120368d66d843f27f868cd84374c732d22e830 (patch) | |
tree | 4af41ca964de2dead72f54f8ac1a1eecb74fa8c9 /library/cpp | |
parent | 0c4ace9a6574efac8e4d423e77cbebd0592dc84c (diff) | |
download | ydb-4b120368d66d843f27f868cd84374c732d22e830.tar.gz |
intermediate changes
ref:090632378b7b7874f8203fa4877f372f9e3bf51e
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/actors/http/http_proxy_sock64.h | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/library/cpp/actors/http/http_proxy_sock64.h b/library/cpp/actors/http/http_proxy_sock64.h index 7f64a0f3538..29b7b34b477 100644 --- a/library/cpp/actors/http/http_proxy_sock64.h +++ b/library/cpp/actors/http/http_proxy_sock64.h @@ -25,9 +25,46 @@ public: } if (NHttp::IsIPv6(address)) { return std::make_shared<TSockAddrInet6>(address.data(), port); - } else { + } else if (NHttp::IsIPv4(address)) { return std::make_shared<TSockAddrInet>(address.data(), port); } + struct addrinfo hints = { + .ai_flags = AI_PASSIVE, + .ai_family = AF, + .ai_socktype = SOCK_STREAM, + }; + struct addrinfo* gai_res = nullptr; + int gai_ret = getaddrinfo(address.data(), nullptr, &hints, &gai_res); + std::shared_ptr<ISockAddr> result; + if (gai_ret == 0 && gai_res->ai_addr) { + switch (gai_res->ai_addr->sa_family) { + case AF_INET6: { + std::shared_ptr<TSockAddrInet6> resultIp6 = std::make_shared<TSockAddrInet6>(); + if (resultIp6->Size() >= gai_res->ai_addrlen) { + memcpy(resultIp6->SockAddr(), gai_res->ai_addr, gai_res->ai_addrlen); + resultIp6->SetPort(port); + result = std::move(resultIp6); + } + } + break; + case AF_INET: { + std::shared_ptr<TSockAddrInet> resultIp4 = std::make_shared<TSockAddrInet>(); + if (resultIp4->Size() >= gai_res->ai_addrlen) { + memcpy(resultIp4->SockAddr(), gai_res->ai_addr, gai_res->ai_addrlen); + resultIp4->SetPort(port); + result = std::move(resultIp4); + } + } + break; + } + } + if (gai_res) { + freeaddrinfo(gai_res); + } + if (result) { + return result; + } + throw yexception() << "Unable to resolve address " << address; } static std::shared_ptr<ISockAddr> MakeAddress(const sockaddr_storage& storage) { @@ -58,7 +95,7 @@ public: } protected: - int AF = 0; + int AF = AF_UNSPEC; void CreateSocket(int af) { SOCKET s; |