diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/network/hostip.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/network/hostip.cpp')
-rw-r--r-- | util/network/hostip.cpp | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/util/network/hostip.cpp b/util/network/hostip.cpp index cb8d43bf90..b7a691c5d3 100644 --- a/util/network/hostip.cpp +++ b/util/network/hostip.cpp @@ -1,21 +1,21 @@ -#include "socket.h" -#include "hostip.h" - +#include "socket.h" +#include "hostip.h" + #include <util/system/defaults.h> #include <util/system/byteorder.h> #if defined(_unix_) || defined(_cygwin_) - #include <netdb.h> + #include <netdb.h> #endif #if !defined(BIND_LIB) - #if !defined(__FreeBSD__) && !defined(_win32_) && !defined(_cygwin_) - #define AGENT_USE_GETADDRINFO - #endif - - #if defined(__FreeBSD__) - #define AGENT_USE_GETADDRINFO - #endif + #if !defined(__FreeBSD__) && !defined(_win32_) && !defined(_cygwin_) + #define AGENT_USE_GETADDRINFO + #endif + + #if defined(__FreeBSD__) + #define AGENT_USE_GETADDRINFO + #endif #endif int NResolver::GetHostIP(const char* hostname, ui32* ip, size_t* slots) { @@ -23,54 +23,54 @@ int NResolver::GetHostIP(const char* hostname, ui32* ip, size_t* slots) { size_t ipsFound = 0; #ifdef AGENT_USE_GETADDRINFO - int ret = 0; - struct addrinfo hints; - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; + int ret = 0; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; struct addrinfo* gai_res = nullptr; int gai_ret = getaddrinfo(hostname, nullptr, &hints, &gai_res); - if (gai_ret == 0 && gai_res->ai_addr) { - struct addrinfo* cur = gai_res; - for (i = 0; i < *slots && cur; i++, cur = cur->ai_next, ipsFound++) { + if (gai_ret == 0 && gai_res->ai_addr) { + struct addrinfo* cur = gai_res; + for (i = 0; i < *slots && cur; i++, cur = cur->ai_next, ipsFound++) { ip[i] = *(ui32*)(&((sockaddr_in*)(cur->ai_addr))->sin_addr); - } - } else { - if (gai_ret == EAI_NONAME || gai_ret == EAI_SERVICE) { - ret = HOST_NOT_FOUND; - } else { - ret = GetDnsError(); - } - } - - if (gai_res) { - freeaddrinfo(gai_res); - } - - if (ret) { - return ret; - } + } + } else { + if (gai_ret == EAI_NONAME || gai_ret == EAI_SERVICE) { + ret = HOST_NOT_FOUND; + } else { + ret = GetDnsError(); + } + } + + if (gai_res) { + freeaddrinfo(gai_res); + } + + if (ret) { + return ret; + } #else - hostent* hostent = gethostbyname(hostname); - - if (!hostent) - return GetDnsError(); - - if (hostent->h_addrtype != AF_INET || (unsigned)hostent->h_length < sizeof(ui32)) - return HOST_NOT_FOUND; - - char** cur = hostent->h_addr_list; - for (i = 0; i < *slots && *cur; i++, cur++, ipsFound++) + hostent* hostent = gethostbyname(hostname); + + if (!hostent) + return GetDnsError(); + + if (hostent->h_addrtype != AF_INET || (unsigned)hostent->h_length < sizeof(ui32)) + return HOST_NOT_FOUND; + + char** cur = hostent->h_addr_list; + for (i = 0; i < *slots && *cur; i++, cur++, ipsFound++) ip[i] = *(ui32*)*cur; #endif - for (i = 0; i < ipsFound; i++) { + for (i = 0; i < ipsFound; i++) { ip[i] = InetToHost(ip[i]); - } - *slots = ipsFound; + } + *slots = ipsFound; - return 0; -} + return 0; +} -int NResolver::GetDnsError() { - return h_errno; -} +int NResolver::GetDnsError() { + return h_errno; +} |