aboutsummaryrefslogtreecommitdiff
path: root/src/netbase.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-04-28 11:08:57 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-09 16:45:57 +0200
commite16be73753d870c5ce77094d3a402bbe8e3bf542 (patch)
treed5c308bf0f0a9fa660161043edbabb5541e97a6b /src/netbase.h
parentd8642752992799b0695cf97ada03c56d0526830c (diff)
net: Add CSubNet class for subnet matching
Diffstat (limited to 'src/netbase.h')
-rw-r--r--src/netbase.h30
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
{