* @returns True if this subnet is valid, the specified address is valid, and * the specified address belongs in this subnet. */
| 1148 | * the specified address belongs in this subnet. |
| 1149 | */ |
| 1150 | bool CSubNet::Match(const CNetAddr &addr) const |
| 1151 | { |
| 1152 | if (!valid || !addr.IsValid() || network.m_net != addr.m_net) |
| 1153 | return false; |
| 1154 | |
| 1155 | switch (network.m_net) { |
| 1156 | case NET_IPV4: |
| 1157 | case NET_IPV6: |
| 1158 | break; |
| 1159 | case NET_ONION: |
| 1160 | case NET_I2P: |
| 1161 | case NET_CJDNS: |
| 1162 | case NET_INTERNAL: |
| 1163 | return addr == network; |
| 1164 | case NET_UNROUTABLE: |
| 1165 | case NET_MAX: |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
| 1169 | assert(network.m_addr.size() == addr.m_addr.size()); |
| 1170 | for (size_t x = 0; x < addr.m_addr.size(); ++x) { |
| 1171 | if ((addr.m_addr[x] & netmask[x]) != network.m_addr[x]) { |
| 1172 | return false; |
| 1173 | } |
| 1174 | } |
| 1175 | return true; |
| 1176 | } |
| 1177 | |
| 1178 | std::string CSubNet::ToString() const |
| 1179 | { |
no test coverage detected