aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2018-10-20 14:48:29 +0000
committerLuke Dashjr <luke-jr+git@utopios.org>2018-11-22 01:44:59 +0000
commitd6a1287481428d982dc03be3a6d9aeef8398f468 (patch)
treec9523b290b7c1714a4cc6d0e829cf9033ccf2c19 /src
parent3615003952ffbc814bdb53d9d0e45790f152bd2f (diff)
CNetAddr: Add IsBindAny method to check for INADDR_ANY
Diffstat (limited to 'src')
-rw-r--r--src/netaddress.cpp10
-rw-r--r--src/netaddress.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index e1af4eff62..72be77dfd9 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -83,6 +83,16 @@ unsigned int CNetAddr::GetByte(int n) const
return ip[15-n];
}
+bool CNetAddr::IsBindAny() const
+{
+ const int cmplen = IsIPv4() ? 4 : 16;
+ for (int i = 0; i < cmplen; ++i) {
+ if (GetByte(i)) return false;
+ }
+
+ return true;
+}
+
bool CNetAddr::IsIPv4() const
{
return (memcmp(ip, pchIPv4, sizeof(pchIPv4)) == 0);
diff --git a/src/netaddress.h b/src/netaddress.h
index cc0e4d4f12..86c13b3465 100644
--- a/src/netaddress.h
+++ b/src/netaddress.h
@@ -55,6 +55,7 @@ class CNetAddr
bool SetInternal(const std::string& name);
bool SetSpecial(const std::string &strName); // for Tor addresses
+ bool IsBindAny() const; // INADDR_ANY equivalent
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)
bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)