* @returns True if this subnet is valid, the specified address is valid, and * the specified address belongs in this subnet. */
| 1017 | * the specified address belongs in this subnet. |
| 1018 | */ |
| 1019 | bool CSubNet::Match(const CNetAddr &addr) const |
| 1020 | { |
| 1021 | if (!valid || !addr.IsValid() || network.m_net != addr.m_net) |
| 1022 | return false; |
| 1023 | |
| 1024 | switch (network.m_net) { |
| 1025 | case NET_IPV4: |
| 1026 | case NET_IPV6: |
| 1027 | break; |
| 1028 | case NET_ONION: |
| 1029 | case NET_I2P: |
| 1030 | case NET_CJDNS: |
| 1031 | case NET_INTERNAL: |
| 1032 | return addr == network; |
| 1033 | case NET_UNROUTABLE: |
| 1034 | case NET_MAX: |
| 1035 | return false; |
| 1036 | } |
| 1037 | |
| 1038 | assert(network.m_addr.size() == addr.m_addr.size()); |
| 1039 | for (size_t x = 0; x < addr.m_addr.size(); ++x) { |
| 1040 | if ((addr.m_addr[x] & netmask[x]) != network.m_addr[x]) { |
| 1041 | return false; |
| 1042 | } |
| 1043 | } |
| 1044 | return true; |
| 1045 | } |
| 1046 | |
| 1047 | std::string CSubNet::ToString() const |
| 1048 | { |
no test coverage detected