Changeset View
Changeset View
Standalone View
Standalone View
src/netaddress.h
Show All 24 Lines | enum Network { | ||||
NET_INTERNAL, | NET_INTERNAL, | ||||
NET_MAX, | NET_MAX, | ||||
}; | }; | ||||
/** 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 | uint8_t ip[16]; // in network byte order | ||||
uint8_t ip[16]; | uint32_t scopeId{0}; // for scoped/link-local ipv6 addresses | ||||
deadalnix: Revert | |||||
// for scoped/link-local ipv6 addresses | |||||
uint32_t scopeId; | |||||
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 | bool SetSpecial(const std::string &strName); // for Tor addresses | ||||
bool SetSpecial(const std::string &strName); | bool IsBindAny() const; // INADDR_ANY equivalent | ||||
// IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) | bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) | ||||
bool IsIPv4() const; | bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor) | ||||
// IPv6 address (not mapped IPv4, not Tor) | bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, | ||||
bool IsIPv6() const; | // 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 IsRFC2544() const; // IPv4 inter-network communications (192.18.0.0/15) | ||||
bool IsRFC1918() const; | bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10) | ||||
// IPv4 inter-network communications (192.18.0.0/15) | bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, | ||||
bool IsRFC2544() const; | // 198.51.100.0/24, 203.0.113.0/24) | ||||
// IPv4 ISP-level NAT (100.64.0.0/10) | bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32) | ||||
bool IsRFC6598() const; | bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16) | ||||
// IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, | bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16) | ||||
// 203.0.113.0/24) | bool IsRFC4193() const; // IPv6 unique local (FC00::/7) | ||||
bool IsRFC5737() const; | bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32) | ||||
// IPv6 documentation address (2001:0DB8::/32) | bool IsRFC4843() const; // IPv6 ORCHID (2001:10::/28) | ||||
bool IsRFC3849() const; | bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64) | ||||
// IPv4 autoconfig (169.254.0.0/16) | bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96) | ||||
bool IsRFC3927() const; | bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) | ||||
deadalnixUnsubmitted Not Done Inline Actionsdito deadalnix: dito | |||||
// IPv6 6to4 tunnelling (2002::/16) | |||||
bool IsRFC3964() const; | |||||
// IPv6 unique local (FC00::/7) | |||||
bool IsRFC4193() const; | |||||
// IPv6 Teredo tunnelling (2001::/32) | |||||
bool IsRFC4380() const; | |||||
// IPv6 ORCHID (2001:10::/28) | |||||
bool IsRFC4843() const; | |||||
// IPv6 autoconfig (FE80::/64) | |||||
bool IsRFC4862() const; | |||||
// IPv6 well-known prefix (64:FF9B::/96) | |||||
bool IsRFC6052() const; | |||||
// IPv6 IPv4-translated address (::FFFF:0:0:0/96) | |||||
bool IsRFC6145() const; | |||||
bool IsTor() const; | bool IsTor() const; | ||||
bool IsLocal() const; | bool IsLocal() const; | ||||
bool IsRoutable() const; | bool IsRoutable() const; | ||||
bool IsInternal() const; | bool IsInternal() const; | ||||
bool IsValid() const; | bool IsValid() const; | ||||
enum Network GetNetwork() const; | enum Network GetNetwork() const; | ||||
std::string ToString() const; | std::string ToString() const; | ||||
std::string ToStringIP() const; | std::string ToStringIP() const; | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |
Revert