IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */
| 40 | |
| 41 | /** IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96)) */ |
| 42 | class CNetAddr |
| 43 | { |
| 44 | protected: |
| 45 | unsigned char ip[16]; // in network byte order |
| 46 | |
| 47 | public: |
| 48 | CNetAddr(); |
| 49 | CNetAddr(const struct in_addr& ipv4Addr); |
| 50 | explicit CNetAddr(const char* pszIp, bool fAllowLookup = false); |
| 51 | explicit CNetAddr(const std::string& strIp, bool fAllowLookup = false); |
| 52 | void Init(); |
| 53 | void SetIP(const CNetAddr& ip); |
| 54 | |
| 55 | /** |
| 56 | * Set raw IPv4 or IPv6 address (in network byte order) |
| 57 | * @note Only NET_IPV4 and NET_IPV6 are allowed for network. |
| 58 | */ |
| 59 | void SetRaw(Network network, const uint8_t* data); |
| 60 | |
| 61 | bool SetSpecial(const std::string& strName); // for Tor addresses |
| 62 | bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) |
| 63 | bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor) |
| 64 | bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12) |
| 65 | bool IsRFC2544() const; // IPv4 inter-network communcations (192.18.0.0/15) |
| 66 | bool IsRFC6598() const; // IPv4 ISP-level NAT (100.64.0.0/10) |
| 67 | bool IsRFC5737() const; // IPv4 documentation addresses (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24) |
| 68 | bool IsRFC3849() const; // IPv6 documentation address (2001:0DB8::/32) |
| 69 | bool IsRFC3927() const; // IPv4 autoconfig (169.254.0.0/16) |
| 70 | bool IsRFC3964() const; // IPv6 6to4 tunnelling (2002::/16) |
| 71 | bool IsRFC4193() const; // IPv6 unique local (FC00::/7) |
| 72 | bool IsRFC4380() const; // IPv6 Teredo tunnelling (2001::/32) |
| 73 | bool IsRFC4843() const; // IPv6 ORCHID (2001:10::/28) |
| 74 | bool IsRFC4862() const; // IPv6 autoconfig (FE80::/64) |
| 75 | bool IsRFC6052() const; // IPv6 well-known prefix (64:FF9B::/96) |
| 76 | bool IsRFC6145() const; // IPv6 IPv4-translated address (::FFFF:0:0:0/96) |
| 77 | bool IsTor() const; |
| 78 | bool IsLocal() const; |
| 79 | bool IsRoutable() const; |
| 80 | bool IsValid() const; |
| 81 | bool IsMulticast() const; |
| 82 | enum Network GetNetwork() const; |
| 83 | std::string ToString() const; |
| 84 | std::string ToStringIP() const; |
| 85 | unsigned int GetByte(int n) const; |
| 86 | uint64_t GetHash() const; |
| 87 | bool GetInAddr(struct in_addr* pipv4Addr) const; |
| 88 | std::vector<unsigned char> GetGroup() const; |
| 89 | int GetReachabilityFrom(const CNetAddr* paddrPartner = NULL) const; |
| 90 | |
| 91 | CNetAddr(const struct in6_addr& pipv6Addr); |
| 92 | bool GetIn6Addr(struct in6_addr* pipv6Addr) const; |
| 93 | |
| 94 | friend bool operator==(const CNetAddr& a, const CNetAddr& b); |
| 95 | friend bool operator!=(const CNetAddr& a, const CNetAddr& b); |
| 96 | friend bool operator<(const CNetAddr& a, const CNetAddr& b); |
| 97 | |
| 98 | ADD_SERIALIZE_METHODS; |
| 99 |
no outgoing calls