Skip to content

Commit

Permalink
CNetAddr: Add IsBindAny method to check for INADDR_ANY
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr authored and furszy committed Aug 10, 2021
1 parent 4fdfa45 commit 2a6abd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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 m_net == NET_IPV4; }

bool CNetAddr::IsIPv6() const { return m_net == NET_IPV6; }
Expand Down
1 change: 1 addition & 0 deletions src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,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)
Expand Down

0 comments on commit 2a6abd8

Please sign in to comment.