Bitcoin Core  0.20.99
P2P Digital Currency
Public Member Functions | Protected Attributes | Friends | List of all members
CNetAddr Class Reference

IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) More...

#include <netaddress.h>

Inheritance diagram for CNetAddr:
[legend]

Public Member Functions

 CNetAddr ()
 Construct an unspecified IPv6 network address (::/128). More...
 
 CNetAddr (const struct in_addr &ipv4Addr)
 
void SetIP (const CNetAddr &ip)
 
void SetRaw (Network network, const uint8_t *data)
 Set raw IPv4 or IPv6 address (in network byte order) More...
 
bool SetInternal (const std::string &name)
 Try to make this a dummy address that maps the specified name into IPv6 like so: (0xFD + sha256("bitcoin")[0:5]) + sha256(name)[0:10]. More...
 
bool SetSpecial (const std::string &strName)
 Try to make this a dummy address that maps the specified onion address into IPv6 using OnionCat's range and encoding. More...
 
bool IsBindAny () const
 
bool IsIPv4 () const
 
bool IsIPv6 () const
 
bool IsRFC1918 () const
 
bool IsRFC2544 () const
 
bool IsRFC6598 () const
 
bool IsRFC5737 () const
 
bool IsRFC3849 () const
 
bool IsRFC3927 () const
 
bool IsRFC3964 () const
 
bool IsRFC4193 () const
 
bool IsRFC4380 () const
 
bool IsRFC4843 () const
 
bool IsRFC7343 () const
 
bool IsRFC4862 () const
 
bool IsRFC6052 () const
 
bool IsRFC6145 () const
 
bool IsHeNet () const
 
bool IsTor () const
 
bool IsLocal () const
 
bool IsRoutable () const
 
bool IsInternal () const
 
bool IsValid () const
 
enum Network GetNetwork () const
 
std::string ToString () const
 
std::string ToStringIP () const
 
unsigned int GetByte (int n) const
 
uint64_t GetHash () const
 
bool GetInAddr (struct in_addr *pipv4Addr) const
 Try to get our IPv4 address. More...
 
uint32_t GetNetClass () const
 
uint32_t GetLinkedIPv4 () const
 For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32. More...
 
bool HasLinkedIPv4 () const
 Whether this address has a linked IPv4 address (see GetLinkedIPv4()). More...
 
uint32_t GetMappedAS (const std::vector< bool > &asmap) const
 
std::vector< unsigned char > GetGroup (const std::vector< bool > &asmap) const
 Get the canonical identifier of our network group. More...
 
std::vector< unsigned char > GetAddrBytes () const
 
int GetReachabilityFrom (const CNetAddr *paddrPartner=nullptr) const
 Calculates a metric for how reachable (*this) is from a given partner. More...
 
 CNetAddr (const struct in6_addr &pipv6Addr, const uint32_t scope=0)
 
bool GetIn6Addr (struct in6_addr *pipv6Addr) const
 Try to get our IPv6 address. More...
 
 SERIALIZE_METHODS (CNetAddr, obj)
 

Protected Attributes

unsigned char ip [16]
 
uint32_t scopeId {0}
 

Friends

class CSubNet
 
bool operator== (const CNetAddr &a, const CNetAddr &b)
 
bool operator!= (const CNetAddr &a, const CNetAddr &b)
 
bool operator< (const CNetAddr &a, const CNetAddr &b)
 

Detailed Description

IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))

Definition at line 31 of file netaddress.h.

Constructor & Destructor Documentation

◆ CNetAddr() [1/3]

CNetAddr::CNetAddr ( )

Construct an unspecified IPv6 network address (::/128).

Note
This address is considered invalid by CNetAddr::IsValid()

Definition at line 24 of file netaddress.cpp.

Here is the caller graph for this function:

◆ CNetAddr() [2/3]

CNetAddr::CNetAddr ( const struct in_addr &  ipv4Addr)
explicit

Definition at line 100 of file netaddress.cpp.

Here is the call graph for this function:

◆ CNetAddr() [3/3]

CNetAddr::CNetAddr ( const struct in6_addr &  pipv6Addr,
const uint32_t  scope = 0 
)
explicit

Definition at line 105 of file netaddress.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ GetAddrBytes()

std::vector<unsigned char> CNetAddr::GetAddrBytes ( ) const
inline

Definition at line 93 of file netaddress.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetByte()

unsigned int CNetAddr::GetByte ( int  n) const

Definition at line 111 of file netaddress.cpp.

Here is the caller graph for this function:

◆ GetGroup()

std::vector< unsigned char > CNetAddr::GetGroup ( const std::vector< bool > &  asmap) const

Get the canonical identifier of our network group.

The groups are assigned in a way where it should be costly for an attacker to obtain addresses with many different group identifiers, even if it is cheap to obtain addresses with the same identifier.

Note
No two connections will be attempted to addresses with the same network group.

Definition at line 487 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHash()

uint64_t CNetAddr::GetHash ( ) const

Definition at line 547 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetIn6Addr()

bool CNetAddr::GetIn6Addr ( struct in6_addr *  pipv6Addr) const

Try to get our IPv6 address.

Parameters
[out]pipv6AddrThe in6_addr struct to which to copy.
Returns
Whether or not the operation was successful, in particular, whether or not our address was an IPv6 address.
See also
CNetAddr::IsIPv6()

Definition at line 401 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetInAddr()

bool CNetAddr::GetInAddr ( struct in_addr *  pipv4Addr) const

Try to get our IPv4 address.

Parameters
[out]pipv4AddrThe in_addr struct to which to copy.
Returns
Whether or not the operation was successful, in particular, whether or not our address was an IPv4 address.
See also
CNetAddr::IsIPv4()

Definition at line 383 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLinkedIPv4()

uint32_t CNetAddr::GetLinkedIPv4 ( ) const

For IPv4, mapped IPv4, SIIT translated IPv4, Teredo, 6to4 tunneled addresses, return the relevant IPv4 address as a uint32.

Definition at line 415 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMappedAS()

uint32_t CNetAddr::GetMappedAS ( const std::vector< bool > &  asmap) const

Definition at line 447 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNetClass()

uint32_t CNetAddr::GetNetClass ( ) const

Definition at line 430 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNetwork()

enum Network CNetAddr::GetNetwork ( ) const

Definition at line 317 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetReachabilityFrom()

int CNetAddr::GetReachabilityFrom ( const CNetAddr paddrPartner = nullptr) const

Calculates a metric for how reachable (*this) is from a given partner.

Definition at line 569 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasLinkedIPv4()

bool CNetAddr::HasLinkedIPv4 ( ) const

Whether this address has a linked IPv4 address (see GetLinkedIPv4()).

Definition at line 410 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsBindAny()

bool CNetAddr::IsBindAny ( ) const

Definition at line 116 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsHeNet()

bool CNetAddr::IsHeNet ( ) const

Definition at line 214 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsInternal()

bool CNetAddr::IsInternal ( ) const
Returns
Whether or not this is a dummy address that maps a name into IPv6.
See also
CNetAddr::SetInternal(const std::string &)

Definition at line 312 of file netaddress.cpp.

Here is the caller graph for this function:

◆ IsIPv4()

bool CNetAddr::IsIPv4 ( ) const

Definition at line 126 of file netaddress.cpp.

Here is the caller graph for this function:

◆ IsIPv6()

bool CNetAddr::IsIPv6 ( ) const

Definition at line 131 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsLocal()

bool CNetAddr::IsLocal ( ) const

Definition at line 230 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC1918()

bool CNetAddr::IsRFC1918 ( ) const

Definition at line 136 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC2544()

bool CNetAddr::IsRFC2544 ( ) const

Definition at line 144 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC3849()

bool CNetAddr::IsRFC3849 ( ) const

Definition at line 166 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC3927()

bool CNetAddr::IsRFC3927 ( ) const

Definition at line 149 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC3964()

bool CNetAddr::IsRFC3964 ( ) const

Definition at line 171 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC4193()

bool CNetAddr::IsRFC4193 ( ) const

Definition at line 193 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC4380()

bool CNetAddr::IsRFC4380 ( ) const

Definition at line 182 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC4843()

bool CNetAddr::IsRFC4843 ( ) const

Definition at line 204 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC4862()

bool CNetAddr::IsRFC4862 ( ) const

Definition at line 187 of file netaddress.cpp.

Here is the caller graph for this function:

◆ IsRFC5737()

bool CNetAddr::IsRFC5737 ( ) const

Definition at line 159 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC6052()

bool CNetAddr::IsRFC6052 ( ) const

Definition at line 176 of file netaddress.cpp.

Here is the caller graph for this function:

◆ IsRFC6145()

bool CNetAddr::IsRFC6145 ( ) const

Definition at line 198 of file netaddress.cpp.

Here is the caller graph for this function:

◆ IsRFC6598()

bool CNetAddr::IsRFC6598 ( ) const

Definition at line 154 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRFC7343()

bool CNetAddr::IsRFC7343 ( ) const

Definition at line 209 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRoutable()

bool CNetAddr::IsRoutable ( ) const
Returns
Whether or not this network address is publicly routable on the global internet.
Note
A routable address is always valid. As in, the set of routable addresses is a subset of the set of valid addresses.
See also
CNetAddr::IsValid()

Definition at line 302 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsTor()

bool CNetAddr::IsTor ( ) const
Returns
Whether or not this is a dummy address that maps an onion address into IPv6.
See also
CNetAddr::SetSpecial(const std::string &)

Definition at line 225 of file netaddress.cpp.

Here is the caller graph for this function:

◆ IsValid()

bool CNetAddr::IsValid ( ) const
Returns
Whether or not this network address is a valid address that could be used to refer to an actual host.
Note
A valid address may or may not be publicly routable on the global internet. As in, the set of valid addresses is a superset of the set of publicly routable addresses.
See also
CNetAddr::IsRoutable()

Definition at line 254 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SERIALIZE_METHODS()

CNetAddr::SERIALIZE_METHODS ( CNetAddr  ,
obj   
)
inline

Definition at line 103 of file netaddress.h.

◆ SetInternal()

bool CNetAddr::SetInternal ( const std::string &  name)

Try to make this a dummy address that maps the specified name into IPv6 like so: (0xFD + sha256("bitcoin")[0:5]) + sha256(name)[0:10].

Such dummy addresses have a prefix of fd6b:88c0:8724::/48 and are guaranteed to not be publicly routable as it falls under RFC4193's fc00::/7 subnet allocated to unique-local addresses.

CAddrMan uses these fake addresses to keep track of which DNS seeds were used.

Returns
Whether or not the operation was successful.
See also
CNetAddr::IsInternal(), CNetAddr::IsRFC4193()

Definition at line 64 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetIP()

void CNetAddr::SetIP ( const CNetAddr ip)

Definition at line 29 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRaw()

void CNetAddr::SetRaw ( Network  network,
const uint8_t *  data 
)

Set raw IPv4 or IPv6 address (in network byte order)

Note
Only NET_IPV4 and NET_IPV6 are allowed for network.

Definition at line 34 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSpecial()

bool CNetAddr::SetSpecial ( const std::string &  strName)

Try to make this a dummy address that maps the specified onion address into IPv6 using OnionCat's range and encoding.

Such dummy addresses have a prefix of fd87:d87e:eb43::/48 and are guaranteed to not be publicly routable as they fall under RFC4193's fc00::/7 subnet allocated to unique-local addresses.

Returns
Whether or not the operation was successful.
See also
CNetAddr::IsTor(), CNetAddr::IsRFC4193()

Definition at line 86 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToString()

std::string CNetAddr::ToString ( ) const

Definition at line 358 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToStringIP()

std::string CNetAddr::ToStringIP ( ) const

Definition at line 334 of file netaddress.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ CSubNet

friend class CSubNet
friend

Definition at line 105 of file netaddress.h.

◆ operator!=

bool operator!= ( const CNetAddr a,
const CNetAddr b 
)
friend

Definition at line 100 of file netaddress.h.

◆ operator<

bool operator< ( const CNetAddr a,
const CNetAddr b 
)
friend

Definition at line 368 of file netaddress.cpp.

◆ operator==

bool operator== ( const CNetAddr a,
const CNetAddr b 
)
friend

Definition at line 363 of file netaddress.cpp.

Member Data Documentation

◆ ip

unsigned char CNetAddr::ip[16]
protected

Definition at line 34 of file netaddress.h.

◆ scopeId

uint32_t CNetAddr::scopeId {0}
protected

Definition at line 35 of file netaddress.h.


The documentation for this class was generated from the following files: