Changeset View
Changeset View
Standalone View
Standalone View
src/netaddress.h
Show All 27 Lines | |||||
}; | }; | ||||
/** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */ | /** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */ | ||||
class CNetAddr { | class CNetAddr { | ||||
protected: | protected: | ||||
// in network byte order | // in network byte order | ||||
uint8_t ip[16]; | uint8_t ip[16]; | ||||
// for scoped/link-local ipv6 addresses | // for scoped/link-local ipv6 addresses | ||||
uint32_t scopeId; | uint32_t scopeId{0}; | ||||
public: | public: | ||||
CNetAddr(); | CNetAddr(); | ||||
explicit CNetAddr(const struct in_addr &ipv4Addr); | explicit CNetAddr(const struct in_addr &ipv4Addr); | ||||
void SetIP(const CNetAddr &ip); | void SetIP(const CNetAddr &ip); | ||||
private: | private: | ||||
/** | /** | ||||
* Set raw IPv4 or IPv6 address (in network byte order) | * Set raw IPv4 or IPv6 address (in network byte order) | ||||
* @note Only NET_IPV4 and NET_IPV6 are allowed for network. | * @note Only NET_IPV4 and NET_IPV6 are allowed for network. | ||||
*/ | */ | ||||
void SetRaw(Network network, const uint8_t *data); | void SetRaw(Network network, const uint8_t *data); | ||||
public: | public: | ||||
/** | /** | ||||
* Transform an arbitrary string into a non-routable ipv6 address. | * Transform an arbitrary string into a non-routable ipv6 address. | ||||
* Useful for mapping resolved addresses back to their source. | * Useful for mapping resolved addresses back to their source. | ||||
*/ | */ | ||||
bool SetInternal(const std::string &name); | bool SetInternal(const std::string &name); | ||||
// for Tor addresses | // for Tor addresses | ||||
bool SetSpecial(const std::string &strName); | bool SetSpecial(const std::string &strName); | ||||
// INADDR_ANY equivalent | |||||
bool IsBindAny() const; | |||||
// IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) | // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) | ||||
bool IsIPv4() const; | bool IsIPv4() const; | ||||
// IPv6 address (not mapped IPv4, not Tor) | // IPv6 address (not mapped IPv4, not Tor) | ||||
bool IsIPv6() const; | bool IsIPv6() const; | ||||
// IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12) | // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12) | ||||
bool IsRFC1918() const; | bool IsRFC1918() const; | ||||
// IPv4 inter-network communications (192.18.0.0/15) | // IPv4 inter-network communications (192.18.0.0/15) | ||||
bool IsRFC2544() const; | bool IsRFC2544() const; | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |