diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-05-09 17:26:16 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-05-09 17:26:42 +0200 |
commit | 605d5b55582f00ea8a089fe632cd8a52e951126b (patch) | |
tree | c92db0c674fb1adf9f3a8f0c743547af1db59523 /src/netbase.h | |
parent | 8bcfccbc2de25e3b40d1c222d7c5d9991345a0aa (diff) | |
parent | 21bf3d257b88c45e2bb0b47e36e73d7462760c2c (diff) | |
download | bitcoin-605d5b55582f00ea8a089fe632cd8a52e951126b.tar.xz |
Merge pull request #4102
21bf3d2 Add tests for BoostAsioToCNetAddr (Wladimir J. van der Laan)
fdbd707 Remove unused function WildcardMatch (Wladimir J. van der Laan)
ee21912 rpc: Use netmasks instead of wildcards for IP address matching (Wladimir J. van der Laan)
e16be73 net: Add CSubNet class for subnet matching (Wladimir J. van der Laan)
d864275 Use new function parseint32 in SplitHostPort (Wladimir J. van der Laan)
0d4ea1c util: add parseint32 function with strict error reporting (Wladimir J. van der Laan)
Diffstat (limited to 'src/netbase.h')
-rw-r--r-- | src/netbase.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/netbase.h b/src/netbase.h index 95b1795767..118f866d6c 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -49,6 +49,13 @@ class CNetAddr explicit CNetAddr(const std::string &strIp, bool fAllowLookup = false); void Init(); void SetIP(const CNetAddr& ip); + + /** + * Set raw IPv4 or IPv6 address (in network byte order) + * @note Only NET_IPV4 and NET_IPV6 are allowed for network. + */ + void SetRaw(Network network, const uint8_t *data); + bool SetSpecial(const std::string &strName); // for Tor addresses bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0) bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor) @@ -90,6 +97,29 @@ class CNetAddr ) }; +class CSubNet +{ + protected: + /// Network (base) address + CNetAddr network; + /// Netmask, in network byte order + uint8_t netmask[16]; + /// Is this value valid? (only used to signal parse errors) + bool valid; + + public: + CSubNet(); + explicit CSubNet(const std::string &strSubnet, bool fAllowLookup = false); + + bool Match(const CNetAddr &addr) const; + + std::string ToString() const; + bool IsValid() const; + + friend bool operator==(const CSubNet& a, const CSubNet& b); + friend bool operator!=(const CSubNet& a, const CSubNet& b); +}; + /** A combination of a network address (CNetAddr) and a (TCP) port */ class CService : public CNetAddr { |