Changeset View
Changeset View
Standalone View
Standalone View
src/netaddress.h
Show First 20 Lines • Show All 290 Lines • ▼ Show 20 Lines | |||||
protected: | protected: | ||||
/// Network (base) address | /// Network (base) address | ||||
CNetAddr network; | CNetAddr network; | ||||
/// Netmask, in network byte order | /// Netmask, in network byte order | ||||
uint8_t netmask[16]; | uint8_t netmask[16]; | ||||
/// Is this value valid? (only used to signal parse errors) | /// Is this value valid? (only used to signal parse errors) | ||||
bool valid; | bool valid; | ||||
bool SanityCheck() const; | |||||
public: | public: | ||||
CSubNet(); | CSubNet(); | ||||
CSubNet(const CNetAddr &addr, uint8_t mask); | CSubNet(const CNetAddr &addr, uint8_t mask); | ||||
CSubNet(const CNetAddr &addr, const CNetAddr &mask); | CSubNet(const CNetAddr &addr, const CNetAddr &mask); | ||||
// constructor for single ip subnet (<ipv4>/32 or <ipv6>/128) | // constructor for single ip subnet (<ipv4>/32 or <ipv6>/128) | ||||
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); | return !(a == b); | ||||
} | } | ||||
friend bool operator<(const CSubNet &a, const CSubNet &b); | friend bool operator<(const CSubNet &a, const CSubNet &b); | ||||
SERIALIZE_METHODS(CSubNet, obj) { | SERIALIZE_METHODS(CSubNet, obj) { | ||||
READWRITE(obj.network, obj.netmask, obj.valid); | READWRITE(obj.network); | ||||
if (obj.network.IsIPv4()) { | |||||
// Before D9176, CSubNet used the last 4 bytes of netmask to store | |||||
// the relevant bytes for an IPv4 mask. For compatiblity reasons, | |||||
// keep doing so in serialized form. | |||||
uint8_t dummy[12] = {0}; | |||||
READWRITE(dummy); | |||||
READWRITE(MakeSpan(obj.netmask).first(4)); | |||||
} else { | |||||
READWRITE(obj.netmask); | |||||
} | |||||
READWRITE(obj.valid); | |||||
// Mark invalid if the result doesn't pass sanity checking. | |||||
SER_READ(obj, if (obj.valid) obj.valid = obj.SanityCheck()); | |||||
} | } | ||||
}; | }; | ||||
/** 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 | ||||
uint16_t port; | uint16_t port; | ||||
Show All 31 Lines |