diff options
author | akhropov <akhropov@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:32 +0300 |
commit | 298c6da79f1d8f35089a67f463f0b541bec36d9b (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/network | |
parent | 00afc96e9c0298054b7386fa7fb9e3cc3d67b974 (diff) | |
download | ydb-298c6da79f1d8f35089a67f463f0b541bec36d9b.tar.gz |
Restoring authorship annotation for <akhropov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/network')
-rw-r--r-- | util/network/ip.h | 24 | ||||
-rw-r--r-- | util/network/ip_ut.cpp | 58 | ||||
-rw-r--r-- | util/network/socket.cpp | 2 | ||||
-rw-r--r-- | util/network/socket.h | 12 |
4 files changed, 48 insertions, 48 deletions
diff --git a/util/network/ip.h b/util/network/ip.h index 7fd0b63ae1..dc7c2d24a0 100644 --- a/util/network/ip.h +++ b/util/network/ip.h @@ -14,28 +14,28 @@ using TIpHost = ui32; /// Port number in host format using TIpPort = ui16; -/* +/* * ipStr is in 'ddd.ddd.ddd.ddd' format * returns IPv4 address in inet format */ -static inline TIpHost IpFromString(const char* ipStr) { - in_addr ia; +static inline TIpHost IpFromString(const char* ipStr) { + in_addr ia; - if (inet_aton(ipStr, &ia) == 0) { + if (inet_aton(ipStr, &ia) == 0) { ythrow TSystemError() << "Failed to convert (" << ipStr << ") to ip address"; - } + } + + return (ui32)ia.s_addr; +} - return (ui32)ia.s_addr; -} - static inline char* IpToString(TIpHost ip, char* buf, size_t len) { if (!inet_ntop(AF_INET, (void*)&ip, buf, (socklen_t)len)) { ythrow TSystemError() << "Failed to get ip address string"; - } - + } + return buf; -} - +} + static inline TString IpToString(TIpHost ip) { char buf[INET_ADDRSTRLEN]; diff --git a/util/network/ip_ut.cpp b/util/network/ip_ut.cpp index 753d62cd0e..6716c6a699 100644 --- a/util/network/ip_ut.cpp +++ b/util/network/ip_ut.cpp @@ -1,10 +1,10 @@ #include "ip.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/generic/yexception.h> - -class TSysIpTest: public TTestBase { + +class TSysIpTest: public TTestBase { UNIT_TEST_SUITE(TSysIpTest); UNIT_TEST(TestIpFromString); UNIT_TEST_EXCEPTION(TestIpFromString2, yexception); @@ -21,43 +21,43 @@ private: void TestIpFromString4(); void TestIpFromString5(); void TestIpToString(); -}; - -UNIT_TEST_SUITE_REGISTRATION(TSysIpTest); - +}; + +UNIT_TEST_SUITE_REGISTRATION(TSysIpTest); + void TSysIpTest::TestIpFromString() { - const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; - ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; - + const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; + ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; + for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { const ui32 ip = IpFromString(ipStr[i]); - UNIT_ASSERT(memcmp(&ip, ipArr[i], sizeof(ui32)) == 0); - } -} - + UNIT_ASSERT(memcmp(&ip, ipArr[i], sizeof(ui32)) == 0); + } +} + void TSysIpTest::TestIpFromString2() { IpFromString("XXXXXXWXW"); -} - +} + void TSysIpTest::TestIpFromString3() { IpFromString("986.0.37.255"); -} - +} + void TSysIpTest::TestIpFromString4() { IpFromString("256.0.22.365"); -} - +} + void TSysIpTest::TestIpFromString5() { IpFromString("245.12..0"); -} - -void TSysIpTest::TestIpToString() { - ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; - - const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; - +} + +void TSysIpTest::TestIpToString() { + ui8 ipArr[][4] = {{192, 168, 0, 1}, {87, 255, 18, 167}, {255, 255, 0, 31}, {188, 225, 124, 255}}; + + const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; + for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { UNIT_ASSERT(IpToString(*reinterpret_cast<TIpHost*>(&(ipArr[i]))) == ipStr[i]); - } -} + } +} diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 192656f57a..4f6e804346 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -49,7 +49,7 @@ using namespace NAddr; #if defined(_win_) - + int inet_aton(const char* cp, struct in_addr* inp) { sockaddr_in addr; addr.sin_family = AF_INET; diff --git a/util/network/socket.h b/util/network/socket.h index 4fb3926110..40c8648b40 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -14,10 +14,10 @@ #include <cerrno> -#ifndef INET_ADDRSTRLEN +#ifndef INET_ADDRSTRLEN #define INET_ADDRSTRLEN 16 -#endif - +#endif + #if defined(_unix_) #define get_host_error() h_errno #elif defined(_win_) @@ -46,15 +46,15 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout) noexcept; #else #define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) #endif - + int inet_aton(const char* cp, struct in_addr* inp); - + #define get_host_error() WSAGetLastError() #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND #define SHUT_RDWR SD_BOTH - + #define INFTIM (-1) #endif |