From fd5b840ba94f04e62928b8ce428cc171e951f0bc Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 16 Apr 2023 00:08:06 +0200 Subject: [PATCH] Light cleanup of the 'CNetAdr' class --- r5dev/tier1/NetAdr.cpp | 109 +++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/r5dev/tier1/NetAdr.cpp b/r5dev/tier1/NetAdr.cpp index 1a930153..1304a360 100644 --- a/r5dev/tier1/NetAdr.cpp +++ b/r5dev/tier1/NetAdr.cpp @@ -25,6 +25,57 @@ CNetAdr::CNetAdr(const char* pch) SetFromString(pch); } +////////////////////////////////////////////////////////////////////// +// Clears IP. +////////////////////////////////////////////////////////////////////// +void CNetAdr::Clear(void) +{ + adr = { }; + port = 0; + reliable = 0; + type = netadrtype_t::NA_NULL; +} + +////////////////////////////////////////////////////////////////////// +// Sets IP. +////////////////////////////////////////////////////////////////////// +void CNetAdr::SetIP(IN6_ADDR* inAdr) +{ + adr = *inAdr; +} + +////////////////////////////////////////////////////////////////////// +// Sets the address type. +////////////////////////////////////////////////////////////////////// +void CNetAdr::SetType(netadrtype_t newtype) +{ + type = newtype; +} + +////////////////////////////////////////////////////////////////////// +// Returns the address type. +////////////////////////////////////////////////////////////////////// +netadrtype_t CNetAdr::GetType(void) const +{ + return type; +} + +////////////////////////////////////////////////////////////////////// +// Sets the port (must be network byte order, use 'htons' to flip). +////////////////////////////////////////////////////////////////////// +void CNetAdr::SetPort(uint16_t newport) +{ + port = newport; +} + +////////////////////////////////////////////////////////////////////// +// Returns the port in network byte order (use 'ntohs' to flip). +////////////////////////////////////////////////////////////////////// +uint16_t CNetAdr::GetPort(void) const +{ + return port; +} + ////////////////////////////////////////////////////////////////////// // Convert address to string. ////////////////////////////////////////////////////////////////////// @@ -99,57 +150,6 @@ void CNetAdr::ToAdrinfo(addrinfo* pHint) const } } -////////////////////////////////////////////////////////////////////// -// Clears IP. -////////////////////////////////////////////////////////////////////// -void CNetAdr::Clear(void) -{ - adr = { }; - port = 0; - reliable = 0; - type = netadrtype_t::NA_NULL; -} - -////////////////////////////////////////////////////////////////////// -// Sets IP. -////////////////////////////////////////////////////////////////////// -void CNetAdr::SetIP(IN6_ADDR* inAdr) -{ - adr = *inAdr; -} - -////////////////////////////////////////////////////////////////////// -// Sets the port (must be network byte order, use 'htons' to flip). -////////////////////////////////////////////////////////////////////// -void CNetAdr::SetPort(std::uint16_t newport) -{ - port = newport; -} - -////////////////////////////////////////////////////////////////////// -// Returns the port in network byte order (use 'ntohs' to flip). -////////////////////////////////////////////////////////////////////// -std::uint16_t CNetAdr::GetPort(void) const -{ - return port; -} - -////////////////////////////////////////////////////////////////////// -// Sets the address type. -////////////////////////////////////////////////////////////////////// -void CNetAdr::SetType(netadrtype_t newtype) -{ - type = newtype; -} - -////////////////////////////////////////////////////////////////////// -// Returns the address type. -////////////////////////////////////////////////////////////////////// -netadrtype_t CNetAdr::GetType(void) const -{ - return type; -} - ////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// @@ -241,12 +241,16 @@ bool CNetAdr::SetFromString(const char* pch, bool bUseDNS) V_snprintf(szNewAddressV4, sizeof(szNewAddressV4), "::FFFF:%s", pszAddress); if (inet_pton(AF_INET6, szNewAddressV4, &this->adr) > 0) + { return true; + } } else // Address is formatted as IPv6. { if (inet_pton(AF_INET6, pszAddress, &this->adr) > 0) + { return true; + } } if (bUseDNS) // Perform DNS lookup instead. @@ -262,8 +266,7 @@ bool CNetAdr::SetFromString(const char* pch, bool bUseDNS) pHints.ai_addr = nullptr; pHints.ai_next = nullptr; - INT ret = getaddrinfo(pszAddress, nullptr, &pHints, &ppResult); - if (ret) + if (getaddrinfo(pszAddress, nullptr, &pHints, &ppResult)) { freeaddrinfo(ppResult); return false;