summaryrefslogtreecommitdiffstats
path: root/util/network/hostip.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <[email protected]>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /util/network/hostip.cpp
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
Restoring authorship annotation for Anton Samokhvalov <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'util/network/hostip.cpp')
-rw-r--r--util/network/hostip.cpp106
1 files changed, 53 insertions, 53 deletions
diff --git a/util/network/hostip.cpp b/util/network/hostip.cpp
index b7a691c5d36..cb8d43bf903 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;
+}