diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/ipv6_address | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/ipv6_address')
-rw-r--r-- | library/cpp/ipv6_address/ipv6_address.cpp | 154 | ||||
-rw-r--r-- | library/cpp/ipv6_address/ipv6_address.h | 76 | ||||
-rw-r--r-- | library/cpp/ipv6_address/ut/ipv6_address_ut.cpp | 22 |
3 files changed, 126 insertions, 126 deletions
diff --git a/library/cpp/ipv6_address/ipv6_address.cpp b/library/cpp/ipv6_address/ipv6_address.cpp index f34075e808..be8fcbae13 100644 --- a/library/cpp/ipv6_address/ipv6_address.cpp +++ b/library/cpp/ipv6_address/ipv6_address.cpp @@ -35,53 +35,53 @@ namespace { } } -void TIpv6Address::InitFrom(const in6_addr& addr) { - const ui64* const ui64Ptr = reinterpret_cast<const ui64*>(&addr); - const ui64 raw[2] = {SwapBytes(*ui64Ptr), SwapBytes(*(ui64Ptr + 1))}; +void TIpv6Address::InitFrom(const in6_addr& addr) { + const ui64* const ui64Ptr = reinterpret_cast<const ui64*>(&addr); + const ui64 raw[2] = {SwapBytes(*ui64Ptr), SwapBytes(*(ui64Ptr + 1))}; Ip = FromMemMSF(reinterpret_cast<const char*>(raw)); - Type_ = Ipv6; + Type_ = Ipv6; } -void TIpv6Address::InitFrom(const in_addr& addr) { +void TIpv6Address::InitFrom(const in_addr& addr) { unsigned long swapped = SwapBytes(addr.s_addr); Ip = ui128{0, swapped}; Type_ = Ipv4; } -void TIpv6Address::InitFrom(const sockaddr_in6& Addr) { +void TIpv6Address::InitFrom(const sockaddr_in6& Addr) { InitFrom(Addr.sin6_addr); ScopeId_ = Addr.sin6_scope_id; } -void TIpv6Address::InitFrom(const sockaddr_in& Addr) { +void TIpv6Address::InitFrom(const sockaddr_in& Addr) { InitFrom(Addr.sin_addr); } -TIpv6Address::TIpv6Address(const NAddr::IRemoteAddr& addr) { - if (addr.Addr()->sa_family == AF_INET) { // IPv4 - const sockaddr_in* Tmp = reinterpret_cast<const sockaddr_in*>(addr.Addr()); +TIpv6Address::TIpv6Address(const NAddr::IRemoteAddr& addr) { + if (addr.Addr()->sa_family == AF_INET) { // IPv4 + const sockaddr_in* Tmp = reinterpret_cast<const sockaddr_in*>(addr.Addr()); InitFrom(*Tmp); } else { // IPv6 - const sockaddr_in6* Tmp = reinterpret_cast<const sockaddr_in6*>(addr.Addr()); + const sockaddr_in6* Tmp = reinterpret_cast<const sockaddr_in6*>(addr.Addr()); InitFrom(*Tmp); } } -TIpv6Address::TIpv6Address(const sockaddr_in6& Addr) { +TIpv6Address::TIpv6Address(const sockaddr_in6& Addr) { InitFrom(Addr); } -TIpv6Address::TIpv6Address(const sockaddr_in& Addr) { +TIpv6Address::TIpv6Address(const sockaddr_in& Addr) { InitFrom(Addr); } -TIpv6Address::TIpv6Address(const in6_addr& addr, ui32 Scope) { +TIpv6Address::TIpv6Address(const in6_addr& addr, ui32 Scope) { InitFrom(addr); ScopeId_ = Scope; } -TIpv6Address::TIpv6Address(const in_addr& addr) { +TIpv6Address::TIpv6Address(const in_addr& addr) { InitFrom(addr); } TIpv6Address TIpv6Address::FromString(TStringBuf str, bool& ok) noexcept { const TIpType ipType = FigureOutType(str); - if (ipType == Ipv6) { + if (ipType == Ipv6) { ui32 scopeId = 0; if (size_t pos = str.find('%'); pos != TStringBuf::npos) { ::TryFromString(str.substr(pos + 1), scopeId); @@ -110,69 +110,69 @@ TIpv6Address TIpv6Address::FromString(TStringBuf str, bool& ok) noexcept { } } -TString TIpv6Address::ToString(bool* ok) const noexcept { +TString TIpv6Address::ToString(bool* ok) const noexcept { return ToString(true, ok); } -TString TIpv6Address::ToString(bool PrintScopeId, bool* ok) const noexcept { +TString TIpv6Address::ToString(bool PrintScopeId, bool* ok) const noexcept { TString result; - bool isOk = true; + bool isOk = true; - if (Type_ == TIpv6Address::Ipv4) { + if (Type_ == TIpv6Address::Ipv4) { result.resize(INET_ADDRSTRLEN + 2); in_addr addr; ToInAddr(addr); isOk = inet_ntop(AF_INET, &addr, result.begin(), INET_ADDRSTRLEN); result.resize(result.find('\0')); - } else if (Type_ == TIpv6Address::Ipv6) { + } else if (Type_ == TIpv6Address::Ipv6) { result.resize(INET6_ADDRSTRLEN + 2); in6_addr addr; ToIn6Addr(addr); isOk = inet_ntop(AF_INET6, &addr, result.begin(), INET6_ADDRSTRLEN); result.resize(result.find('\0')); - if (PrintScopeId) + if (PrintScopeId) result += "%" + ::ToString(ScopeId_); } else { result = "null"; - isOk = true; + isOk = true; } - if (ok) { + if (ok) { *ok = isOk; } return result; } -void TIpv6Address::ToSockaddrAndSocklen(sockaddr_in& sockAddrIPv4, - sockaddr_in6& sockAddrIPv6, // in - const sockaddr*& sockAddrPtr, - socklen_t& sockAddrSize, - ui16 Port) const { // out +void TIpv6Address::ToSockaddrAndSocklen(sockaddr_in& sockAddrIPv4, + sockaddr_in6& sockAddrIPv6, // in + const sockaddr*& sockAddrPtr, + socklen_t& sockAddrSize, + ui16 Port) const { // out - if (Type_ == Ipv4) { + if (Type_ == Ipv4) { memset(&sockAddrIPv4, 0, sizeof(sockAddrIPv4)); sockAddrIPv4.sin_family = AF_INET; - sockAddrIPv4.sin_port = htons(Port); + sockAddrIPv4.sin_port = htons(Port); ToInAddr(sockAddrIPv4.sin_addr); sockAddrSize = sizeof(sockAddrIPv4); - sockAddrPtr = reinterpret_cast<sockaddr*>(&sockAddrIPv4); + sockAddrPtr = reinterpret_cast<sockaddr*>(&sockAddrIPv4); - } else if (Type_ == Ipv6) { + } else if (Type_ == Ipv6) { memset(&sockAddrIPv6, 0, sizeof(sockAddrIPv6)); sockAddrIPv6.sin6_family = AF_INET6; - sockAddrIPv6.sin6_port = htons(Port); + sockAddrIPv6.sin6_port = htons(Port); ToIn6Addr(sockAddrIPv6.sin6_addr); sockAddrIPv6.sin6_scope_id = ScopeId_; sockAddrIPv6.sin6_flowinfo = 0; sockAddrSize = sizeof(sockAddrIPv6); - sockAddrPtr = reinterpret_cast<sockaddr*>(&sockAddrIPv6); + sockAddrPtr = reinterpret_cast<sockaddr*>(&sockAddrIPv6); } else Y_VERIFY(false); } -void TIpv6Address::ToInAddr(in_addr& Addr4) const { +void TIpv6Address::ToInAddr(in_addr& Addr4) const { Y_VERIFY(Type_ == TIpv6Address::Ipv4); Zero(Addr4); @@ -181,22 +181,22 @@ void TIpv6Address::ToInAddr(in_addr& Addr4) const { Y_VERIFY(GetHigh(Ip) == 0, " "); Addr4.s_addr = SwapBytes(Value); } -void TIpv6Address::ToIn6Addr(in6_addr& Addr6) const { +void TIpv6Address::ToIn6Addr(in6_addr& Addr6) const { Y_VERIFY(Type_ == TIpv6Address::Ipv6); Zero(Addr6); ui64 Raw[2] = {GetHigh(Ip), GetLow(Ip)}; - *Raw = SwapBytes(*Raw); - Raw[1] = SwapBytes(1 [Raw]); + *Raw = SwapBytes(*Raw); + Raw[1] = SwapBytes(1 [Raw]); memcpy(&Addr6, Raw, sizeof(Raw)); } -void TIpv6Address::Save(IOutputStream* out) const { +void TIpv6Address::Save(IOutputStream* out) const { ::Save(out, Ip); ::Save(out, static_cast<ui8>(Type_)); ::Save(out, ScopeId_); } -void TIpv6Address::Load(IInputStream* in) { +void TIpv6Address::Load(IInputStream* in) { ::Load(in, Ip); ui8 num; ::Load(in, num); @@ -210,21 +210,21 @@ bool TIpv6Address::Isv4MappedTov6() const noexcept { /// the IPv4-mapped IPv6 addresses. In these addresses, the first 80 bits are zero, the next 16 bits are one, /// and the remaining 32 bits are the IPv4 address. - if (Type_ != Ipv6) + if (Type_ != Ipv6) return false; if (GetHigh(Ip) != 0) return false; // First 64 bit are not zero -> it is not ipv4-mapped-ipv6 address const ui64 Low = GetLow(Ip) >> 32; - if (Low != 0x0000ffff) + if (Low != 0x0000ffff) return false; return true; } TIpv6Address TIpv6Address::TryToExtractIpv4From6() const noexcept { - if (Isv4MappedTov6() == false) + if (Isv4MappedTov6() == false) return TIpv6Address(); const ui64 NewLow = GetLow(Ip) & 0x00000000ffffffff; @@ -233,7 +233,7 @@ TIpv6Address TIpv6Address::TryToExtractIpv4From6() const noexcept { } TIpv6Address TIpv6Address::Normalized() const noexcept { - if (Isv4MappedTov6() == false) + if (Isv4MappedTov6() == false) return *this; TIpv6Address Result = TryToExtractIpv4From6(); @@ -241,7 +241,7 @@ TIpv6Address TIpv6Address::Normalized() const noexcept { return Result; } -IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address::TIpType Type) noexcept { +IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address::TIpType Type) noexcept { switch (Type) { case TIpv6Address::Ipv4: Out << "Ipv4"; @@ -255,10 +255,10 @@ IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address::TIpType Type) } } -IOutputStream& operator<<(IOutputStream& out, const TIpv6Address& ipv6Address) noexcept { - bool ok; - const TString& strIp = ipv6Address.ToString(&ok); - if (!ok) { +IOutputStream& operator<<(IOutputStream& out, const TIpv6Address& ipv6Address) noexcept { + bool ok; + const TString& strIp = ipv6Address.ToString(&ok); + if (!ok) { return out << "Can not convert ip to string"; } else { return out << strIp; @@ -271,29 +271,29 @@ TString THostAddressAndPort::ToString() const noexcept { return Str.Str(); } -IOutputStream& operator<<(IOutputStream& Out, const THostAddressAndPort& HostAddressAndPort) noexcept { +IOutputStream& operator<<(IOutputStream& Out, const THostAddressAndPort& HostAddressAndPort) noexcept { Out << HostAddressAndPort.Ip << ":" << HostAddressAndPort.Port; return Out; } namespace { - class TRemoteAddr: public NAddr::IRemoteAddr { + class TRemoteAddr: public NAddr::IRemoteAddr { public: - TRemoteAddr(const TIpv6Address& Address, TIpPort Port); - const sockaddr* Addr() const override; - socklen_t Len() const override; + TRemoteAddr(const TIpv6Address& Address, TIpPort Port); + const sockaddr* Addr() const override; + socklen_t Len() const override; private: - sockaddr_in SockAddrIPv4; - sockaddr_in6 SockAddrIPv6; - const sockaddr* SockAddrPtr = nullptr; - socklen_t SockAddrSize = 0; + sockaddr_in SockAddrIPv4; + sockaddr_in6 SockAddrIPv6; + const sockaddr* SockAddrPtr = nullptr; + socklen_t SockAddrSize = 0; }; - TRemoteAddr::TRemoteAddr(const TIpv6Address& Address, TIpPort Port) { + TRemoteAddr::TRemoteAddr(const TIpv6Address& Address, TIpPort Port) { Address.ToSockaddrAndSocklen(SockAddrIPv4, SockAddrIPv6, SockAddrPtr, SockAddrSize, Port); } - const sockaddr* TRemoteAddr::Addr() const { + const sockaddr* TRemoteAddr::Addr() const { return SockAddrPtr; } socklen_t TRemoteAddr::Len() const { @@ -301,13 +301,13 @@ namespace { } } -NAddr::IRemoteAddr* ToIRemoteAddr(const TIpv6Address& Address, TIpPort Port) { +NAddr::IRemoteAddr* ToIRemoteAddr(const TIpv6Address& Address, TIpPort Port) { return new TRemoteAddr(Address, Port); } -std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromString(const TString& RawStr, - TIpPort DefaultPort, - bool& Ok) noexcept { +std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromString(const TString& RawStr, + TIpPort DefaultPort, + bool& Ok) noexcept { // Cout << "ParseHostAndMayBePortFromString: " << RawStr << ", Port: " << DefaultPort << Endl; using TRes = std::tuple<THostAddressAndPort, TString, TIpPort>; @@ -315,7 +315,7 @@ std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromStrin // --------------------------------------------------------------------- const size_t BracketColPos = RawStr.find("]:"); - if (BracketColPos != TString::npos) { + if (BracketColPos != TString::npos) { // [ipv6]:port if (!RawStr.StartsWith('[')) { Ok = false; @@ -324,13 +324,13 @@ std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromStrin const TStringBuf StrIpv6(RawStr.begin() + 1, RawStr.begin() + BracketColPos); const TStringBuf StrPort(RawStr.begin() + BracketColPos + 2, RawStr.end()); - bool IpConverted; + bool IpConverted; const TIpv6Address Ip = TIpv6Address::FromString(StrIpv6, IpConverted); if (!IpConverted) { Ok = false; return {}; } - if (Ip.Type() != TIpv6Address::Ipv6) { + if (Ip.Type() != TIpv6Address::Ipv6) { Ok = false; return {}; } @@ -347,7 +347,7 @@ std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromStrin // --------------------------------------------------------------------- - if (RawStr.StartsWith('[')) { + if (RawStr.StartsWith('[')) { // [ipv6] if (!RawStr.EndsWith(']')) { Ok = false; @@ -355,7 +355,7 @@ std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromStrin } const TStringBuf StrIpv6(RawStr.begin() + 1, RawStr.end() - 1); - bool IpConverted; + bool IpConverted; const TIpv6Address Ip = TIpv6Address::FromString(StrIpv6, IpConverted); if (!IpConverted || Ip.Type() != TIpv6Address::Ipv6) { Ok = false; @@ -370,15 +370,15 @@ std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromStrin // --------------------------------------------------------------------- const size_t ColPos = RawStr.find(':'); - if (ColPos != TString::npos) { + if (ColPos != TString::npos) { // host:port // ipv4:port // ipv6 { - bool IpConverted; + bool IpConverted; const TIpv6Address Ipv6 = TIpv6Address::FromString(RawStr, IpConverted); - if (IpConverted && Ipv6.Type() == TIpv6Address::Ipv6) { + if (IpConverted && Ipv6.Type() == TIpv6Address::Ipv6) { // ipv6 Ok = true; TRes Res{{Ipv6, DefaultPort}, {}, {}}; @@ -395,9 +395,9 @@ std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromStrin const TStringBuf StrIpv4OrHost(RawStr.begin(), RawStr.begin() + ColPos); { - bool IpConverted; + bool IpConverted; const TIpv6Address Ipv4 = TIpv6Address::FromString(StrIpv4OrHost, IpConverted); - if (IpConverted && Ipv4.Type() == TIpv6Address::Ipv4) { + if (IpConverted && Ipv4.Type() == TIpv6Address::Ipv4) { // ipv4:port Ok = true; TRes Res{{Ipv4, Port}, {}, {}}; @@ -417,9 +417,9 @@ std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromStrin { // ipv4 - bool IpConverted; + bool IpConverted; const TIpv6Address Ipv4 = TIpv6Address::FromString(RawStr, IpConverted); - if (IpConverted && Ipv4.Type() == TIpv6Address::Ipv4) { + if (IpConverted && Ipv4.Type() == TIpv6Address::Ipv4) { Ok = true; TRes Res{{Ipv4, DefaultPort}, {}, {}}; return Res; diff --git a/library/cpp/ipv6_address/ipv6_address.h b/library/cpp/ipv6_address/ipv6_address.h index bb6cbc6229..1d7eb0b65f 100644 --- a/library/cpp/ipv6_address/ipv6_address.h +++ b/library/cpp/ipv6_address/ipv6_address.h @@ -28,9 +28,9 @@ struct sockaddr_in6; // TODO (dimanne): rename to something like TIntInetAddress or THostAddress class TIpv6Address { public: - enum TIpType { Ipv6, - Ipv4, - LAST }; + enum TIpType { Ipv6, + Ipv4, + LAST }; constexpr TIpv6Address() noexcept = default; constexpr TIpv6Address(const TIpv6Address&) noexcept = default; @@ -54,11 +54,11 @@ public: Ip = {hi, lo}; } - explicit TIpv6Address(const NAddr::IRemoteAddr& addr); - explicit TIpv6Address(const sockaddr_in6& Addr); - explicit TIpv6Address(const sockaddr_in& Addr); - explicit TIpv6Address(const in6_addr& addr, ui32 Scope); - explicit TIpv6Address(const in_addr& addr); + explicit TIpv6Address(const NAddr::IRemoteAddr& addr); + explicit TIpv6Address(const sockaddr_in6& Addr); + explicit TIpv6Address(const sockaddr_in& Addr); + explicit TIpv6Address(const in6_addr& addr, ui32 Scope); + explicit TIpv6Address(const in_addr& addr); static TIpv6Address FromString(TStringBuf srcStr, bool& ok) noexcept; @@ -78,31 +78,31 @@ public: return !IsValid(); } - bool Isv4MappedTov6() const noexcept; + bool Isv4MappedTov6() const noexcept; TIpv6Address TryToExtractIpv4From6() const noexcept; TIpv6Address Normalized() const noexcept; - TString ToString(bool* ok = nullptr) const noexcept; - TString ToString(bool PrintScopeId, bool* ok = nullptr) const noexcept; + TString ToString(bool* ok = nullptr) const noexcept; + TString ToString(bool PrintScopeId, bool* ok = nullptr) const noexcept; - void ToSockaddrAndSocklen(sockaddr_in& sockAddrIPv4, - sockaddr_in6& sockAddrIPv6, // in - const sockaddr*& sockAddrPtr, - socklen_t& sockAddrSize, - ui16 Port) const; // out + void ToSockaddrAndSocklen(sockaddr_in& sockAddrIPv4, + sockaddr_in6& sockAddrIPv6, // in + const sockaddr*& sockAddrPtr, + socklen_t& sockAddrSize, + ui16 Port) const; // out - void ToInAddr(in_addr& Addr4) const; - void ToIn6Addr(in6_addr& Addr6) const; + void ToInAddr(in_addr& Addr4) const; + void ToIn6Addr(in6_addr& Addr6) const; // int SocketFamily() const; constexpr bool operator<(const TIpv6Address& other) const noexcept { - if (Type_ != other.Type_) + if (Type_ != other.Type_) return Type_ > other.Type_; else return Ip < other.Ip; } constexpr bool operator>(const TIpv6Address& other) const noexcept { - if (Type_ != other.Type_) + if (Type_ != other.Type_) return Type_ < other.Type_; else return Ip > other.Ip; @@ -137,22 +137,22 @@ public: return ScopeId_; } - void Save(IOutputStream* out) const; - void Load(IInputStream* in); + void Save(IOutputStream* out) const; + void Load(IInputStream* in); private: - void InitFrom(const in6_addr& addr); - void InitFrom(const in_addr& addr); + void InitFrom(const in6_addr& addr); + void InitFrom(const in_addr& addr); - void InitFrom(const sockaddr_in6& Addr); - void InitFrom(const sockaddr_in& Addr); + void InitFrom(const sockaddr_in6& Addr); + void InitFrom(const sockaddr_in& Addr); ui128 Ip{}; - TIpType Type_ = LAST; - ui32 ScopeId_ = 0; + TIpType Type_ = LAST; + ui32 ScopeId_ = 0; }; -IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address::TIpType Type) noexcept; -IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address& ipv6Address) noexcept; +IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address::TIpType Type) noexcept; +IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address& ipv6Address) noexcept; constexpr TIpv6Address Get127001() noexcept { return {127, 0, 0, 1}; @@ -184,7 +184,7 @@ struct THostAddressAndPort { TIpv6Address Ip {}; TIpPort Port {0}; }; -IOutputStream& operator<<(IOutputStream& Out, const THostAddressAndPort& HostAddressAndPort) noexcept; +IOutputStream& operator<<(IOutputStream& Out, const THostAddressAndPort& HostAddressAndPort) noexcept; /// /// Returns @@ -199,22 +199,22 @@ IOutputStream& operator<<(IOutputStream& Out, const THostAddressAndPort& HostAdd /// 2001::7348 // port wil be equal to DefaultPort /// [2001::7348]:80 /// -std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromString(const TString& RawStr, - TIpPort DefaultPort, - bool& Ok) noexcept; +std::tuple<THostAddressAndPort, TString, TIpPort> ParseHostAndMayBePortFromString(const TString& RawStr, + TIpPort DefaultPort, + bool& Ok) noexcept; using TIpv6AddressesSet = THashSet<TIpv6Address>; template <> struct THash<TIpv6Address> { - inline size_t operator()(const TIpv6Address& ip) const { + inline size_t operator()(const TIpv6Address& ip) const { const ui128& Tmp = static_cast<ui128>(ip); return CombineHashes(THash<ui128>()(Tmp), THash<ui8>()(static_cast<ui8>(ip.Type()))); } }; template <> struct THash<THostAddressAndPort> { - inline size_t operator()(const THostAddressAndPort& IpAndPort) const { + inline size_t operator()(const THostAddressAndPort& IpAndPort) const { return CombineHashes(THash<TIpv6Address>()(IpAndPort.Ip), THash<TIpPort>()(IpAndPort.Port)); } }; @@ -222,13 +222,13 @@ struct THash<THostAddressAndPort> { namespace std { template <> struct hash<TIpv6Address> { - std::size_t operator()(const TIpv6Address& Ip) const noexcept { + std::size_t operator()(const TIpv6Address& Ip) const noexcept { return THash<TIpv6Address>()(Ip); } }; } -NAddr::IRemoteAddr* ToIRemoteAddr(const TIpv6Address& Address, TIpPort Port); +NAddr::IRemoteAddr* ToIRemoteAddr(const TIpv6Address& Address, TIpPort Port); // template <> // class TSerializer<TIpv6Address> { diff --git a/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp b/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp index 377ffd0f65..73bb7cffdd 100644 --- a/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp +++ b/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/ipv6_address/ipv6_address.h> #include <unordered_set> -class TIpv6AddressTest: public TTestBase { +class TIpv6AddressTest: public TTestBase { UNIT_TEST_SUITE(TIpv6AddressTest); UNIT_TEST(ParseHostAndMayBePortFromString_data); UNIT_TEST(CheckAddressValidity) @@ -19,7 +19,7 @@ UNIT_TEST_SUITE_REGISTRATION(TIpv6AddressTest); using TResult = std::tuple<THostAddressAndPort, TString, TIpPort>; TResult IpRes(TString Ip, TIpPort Port) { - bool Ok; + bool Ok; THostAddressAndPort HostAddressAndPort; HostAddressAndPort.Ip = TIpv6Address::FromString(Ip, Ok); Y_VERIFY(Ok); @@ -30,24 +30,24 @@ TResult HostRes(TString HostName, TIpPort Port) { return TResult({}, HostName, Port); } -void ParseHostAndMayBePortFromString(TString RawStr, - TIpPort DefaultPort, +void ParseHostAndMayBePortFromString(TString RawStr, + TIpPort DefaultPort, const TResult ExpectedResult, - const bool ExpectedOk) { - bool Ok = false; + const bool ExpectedOk) { + bool Ok = false; const TResult ActualResult = ParseHostAndMayBePortFromString(RawStr, DefaultPort, Ok); UNIT_ASSERT(Ok == ExpectedOk); - if (Ok == false) + if (Ok == false) return; UNIT_ASSERT(ActualResult == ExpectedResult); } -void CheckIpDefPortAgainstIpPortDefPort_v4OrHost(TString Ip, - TIpPort Port, +void CheckIpDefPortAgainstIpPortDefPort_v4OrHost(TString Ip, + TIpPort Port, const TResult ExpectedResult, - const bool ExpectedOk) { + const bool ExpectedOk) { ParseHostAndMayBePortFromString(Ip, Port, ExpectedResult, ExpectedOk); TString New = Ip + ":" + ToString(Port); @@ -62,7 +62,7 @@ void CheckIpDefPortAgainstIpPortDefPort_v6(TString Ip, TIpPort Port, const TResu } void CheckIpDefPortAgainstIpPortDefPort(TString Ip, TIpPort Port, const TResult ExpectedResult, const bool ExpectedOk) { - if (Ip.find(':') == TString::npos) { + if (Ip.find(':') == TString::npos) { CheckIpDefPortAgainstIpPortDefPort_v4OrHost(Ip, Port, ExpectedResult, ExpectedOk); } else { CheckIpDefPortAgainstIpPortDefPort_v6(Ip, Port, ExpectedResult, ExpectedOk); |