mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Light cleanup of the 'CNetAdr' class
This commit is contained in:
parent
7870f1557a
commit
fd5b840ba9
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user