Changeset View
Changeset View
Standalone View
Standalone View
src/netaddress.h
Show All 31 Lines | 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; | ||||
public: | public: | ||||
CNetAddr(); | CNetAddr(); | ||||
CNetAddr(const struct in_addr &ipv4Addr); | CNetAddr(const struct in_addr &ipv4Addr); | ||||
void Init(); | |||||
void SetIP(const CNetAddr &ip); | void SetIP(const CNetAddr &ip); | ||||
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: | |||||
/** | /** | ||||
* 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); | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public: | ||||
bool GetInAddr(struct in_addr *pipv4Addr) const; | bool GetInAddr(struct in_addr *pipv4Addr) const; | ||||
std::vector<uint8_t> GetGroup() const; | std::vector<uint8_t> GetGroup() const; | ||||
int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const; | int GetReachabilityFrom(const CNetAddr *paddrPartner = nullptr) const; | ||||
CNetAddr(const struct in6_addr &pipv6Addr, const uint32_t scope = 0); | CNetAddr(const struct in6_addr &pipv6Addr, const uint32_t scope = 0); | ||||
bool GetIn6Addr(struct in6_addr *pipv6Addr) const; | bool GetIn6Addr(struct in6_addr *pipv6Addr) const; | ||||
friend bool operator==(const CNetAddr &a, const CNetAddr &b); | friend bool operator==(const CNetAddr &a, const CNetAddr &b); | ||||
friend bool operator!=(const CNetAddr &a, const CNetAddr &b); | friend bool operator!=(const CNetAddr &a, const CNetAddr &b) { | ||||
return !(a == b); | |||||
} | |||||
friend bool operator<(const CNetAddr &a, const CNetAddr &b); | friend bool operator<(const CNetAddr &a, const CNetAddr &b); | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(FLATDATA(ip)); | READWRITE(FLATDATA(ip)); | ||||
} | } | ||||
Show All 19 Lines | public: | ||||
explicit CSubNet(const CNetAddr &addr); | explicit CSubNet(const CNetAddr &addr); | ||||
bool Match(const CNetAddr &addr) const; | bool Match(const CNetAddr &addr) const; | ||||
std::string ToString() const; | std::string ToString() const; | ||||
bool IsValid() const; | bool IsValid() const; | ||||
friend bool operator==(const CSubNet &a, const CSubNet &b); | friend bool operator==(const CSubNet &a, const CSubNet &b); | ||||
friend bool operator!=(const CSubNet &a, const CSubNet &b); | friend bool operator!=(const CSubNet &a, const CSubNet &b) { | ||||
return !(a == b); | |||||
} | |||||
friend bool operator<(const CSubNet &a, const CSubNet &b); | friend bool operator<(const CSubNet &a, const CSubNet &b); | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(network); | READWRITE(network); | ||||
READWRITE(FLATDATA(netmask)); | READWRITE(FLATDATA(netmask)); | ||||
READWRITE(FLATDATA(valid)); | READWRITE(FLATDATA(valid)); | ||||
} | } | ||||
}; | }; | ||||
/** A combination of a network address (CNetAddr) and a (TCP) port */ | /** A combination of a network address (CNetAddr) and a (TCP) port */ | ||||
class CService : public CNetAddr { | class CService : public CNetAddr { | ||||
protected: | protected: | ||||
// host order | // host order | ||||
unsigned short port; | unsigned short port; | ||||
public: | public: | ||||
CService(); | CService(); | ||||
CService(const CNetAddr &ip, unsigned short port); | CService(const CNetAddr &ip, unsigned short port); | ||||
CService(const struct in_addr &ipv4Addr, unsigned short port); | CService(const struct in_addr &ipv4Addr, unsigned short port); | ||||
CService(const struct sockaddr_in &addr); | CService(const struct sockaddr_in &addr); | ||||
void Init(); | |||||
void SetPort(unsigned short portIn); | void SetPort(unsigned short portIn); | ||||
unsigned short GetPort() const; | unsigned short GetPort() const; | ||||
bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const; | bool GetSockAddr(struct sockaddr *paddr, socklen_t *addrlen) const; | ||||
bool SetSockAddr(const struct sockaddr *paddr); | bool SetSockAddr(const struct sockaddr *paddr); | ||||
friend bool operator==(const CService &a, const CService &b); | friend bool operator==(const CService &a, const CService &b); | ||||
friend bool operator!=(const CService &a, const CService &b); | friend bool operator!=(const CService &a, const CService &b) { | ||||
return !(a == b); | |||||
} | |||||
friend bool operator<(const CService &a, const CService &b); | friend bool operator<(const CService &a, const CService &b); | ||||
std::vector<uint8_t> GetKey() const; | std::vector<uint8_t> GetKey() const; | ||||
std::string ToString() const; | std::string ToString() const; | ||||
std::string ToStringPort() const; | std::string ToStringPort() const; | ||||
std::string ToStringIPPort() const; | std::string ToStringIPPort() const; | ||||
CService(const struct in6_addr &ipv6Addr, unsigned short port); | CService(const struct in6_addr &ipv6Addr, unsigned short port); | ||||
CService(const struct sockaddr_in6 &addr); | CService(const struct sockaddr_in6 &addr); | ||||
Show All 13 Lines |