Skip to content

Commit d6a1287

Browse files
committed
CNetAddr: Add IsBindAny method to check for INADDR_ANY
1 parent 3615003 commit d6a1287

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/netaddress.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ unsigned int CNetAddr::GetByte(int n) const
8383
return ip[15-n];
8484
}
8585

86+
bool CNetAddr::IsBindAny() const
87+
{
88+
const int cmplen = IsIPv4() ? 4 : 16;
89+
for (int i = 0; i < cmplen; ++i) {
90+
if (GetByte(i)) return false;
91+
}
92+
93+
return true;
94+
}
95+
8696
bool CNetAddr::IsIPv4() const
8797
{
8898
return (memcmp(ip, pchIPv4, sizeof(pchIPv4)) == 0);

src/netaddress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CNetAddr
5555
bool SetInternal(const std::string& name);
5656

5757
bool SetSpecial(const std::string &strName); // for Tor addresses
58+
bool IsBindAny() const; // INADDR_ANY equivalent
5859
bool IsIPv4() const; // IPv4 mapped address (::FFFF:0:0/96, 0.0.0.0/0)
5960
bool IsIPv6() const; // IPv6 address (not mapped IPv4, not Tor)
6061
bool IsRFC1918() const; // IPv4 private networks (10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12)

0 commit comments

Comments
 (0)