summaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/http/http_proxy_sock64.h
diff options
context:
space:
mode:
authorDaniil Cherednik <[email protected]>2022-11-24 13:14:34 +0300
committerDaniil Cherednik <[email protected]>2022-11-24 14:46:00 +0300
commit87f7fceed34bcafb8aaff351dd493a35c916986f (patch)
tree26809ec8f550aba8eb019e59adc3d48e51913eb2 /library/cpp/actors/http/http_proxy_sock64.h
parent11bc4015b8010ae201bf3eb33db7dba425aca35e (diff)
Ydb stable 22-4-4322.4.43
x-stable-origin-commit: 8d49d46cc834835bf3e50870516acd7376a63bcf
Diffstat (limited to 'library/cpp/actors/http/http_proxy_sock64.h')
-rw-r--r--library/cpp/actors/http/http_proxy_sock64.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/library/cpp/actors/http/http_proxy_sock64.h b/library/cpp/actors/http/http_proxy_sock64.h
index 29b7b34b477..9b7db8f6620 100644
--- a/library/cpp/actors/http/http_proxy_sock64.h
+++ b/library/cpp/actors/http/http_proxy_sock64.h
@@ -67,6 +67,35 @@ public:
throw yexception() << "Unable to resolve address " << address;
}
+ static int GuessAddressFamily(const TString& address) {
+ if (!address) {
+ return 0;
+ }
+ if (NHttp::IsIPv6(address)) {
+ return AF_INET6;
+ } else if (NHttp::IsIPv4(address)) {
+ return AF_INET;
+ }
+ struct addrinfo hints = {
+ .ai_flags = AI_PASSIVE,
+ .ai_family = 0,
+ .ai_socktype = SOCK_STREAM,
+ };
+ struct addrinfo* gai_res = nullptr;
+ int gai_ret = getaddrinfo(address.data(), nullptr, &hints, &gai_res);
+ if (gai_ret == 0 && gai_res->ai_addr) {
+ switch (gai_res->ai_addr->sa_family) {
+ case AF_INET:
+ case AF_INET6:
+ return gai_res->ai_addr->sa_family;
+ }
+ }
+ if (gai_res) {
+ freeaddrinfo(gai_res);
+ }
+ return 0;
+ }
+
static std::shared_ptr<ISockAddr> MakeAddress(const sockaddr_storage& storage) {
std::shared_ptr<ISockAddr> addr;
switch (storage.ss_family) {