Changeset View
Changeset View
Standalone View
Standalone View
src/netaddress.h
Show All 30 Lines | |||||
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; | ||||
public: | public: | ||||
CNetAddr(); | CNetAddr(); | ||||
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); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public: | ||||
std::string ToString() const; | std::string ToString() const; | ||||
std::string ToStringIP() const; | std::string ToStringIP() const; | ||||
unsigned int GetByte(int n) const; | unsigned int GetByte(int n) const; | ||||
uint64_t GetHash() const; | uint64_t GetHash() const; | ||||
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); | explicit 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); | return !(a == b); | ||||
} | } | ||||
friend bool operator<(const CNetAddr &a, const CNetAddr &b); | friend bool operator<(const CNetAddr &a, const CNetAddr &b); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
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); | explicit CService(const struct sockaddr_in &addr); | ||||
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); | 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); | explicit CService(const struct sockaddr_in6 &addr); | ||||
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)); | ||||
unsigned short portN = htons(port); | unsigned short portN = htons(port); | ||||
READWRITE(FLATDATA(portN)); | READWRITE(FLATDATA(portN)); | ||||
if (ser_action.ForRead()) port = ntohs(portN); | if (ser_action.ForRead()) port = ntohs(portN); | ||||
} | } | ||||
}; | }; | ||||
#endif // BITCOIN_NETADDRESS_H | #endif // BITCOIN_NETADDRESS_H |