* @returns Whether or not this network address is a valid address that @a could * be used to refer to an actual host. * * @note A valid address may or may not be publicly routable on the global * internet. As in, the set of valid addresses is a superset of the set of * publicly routable addresses. * * @see CNetAddr::IsRoutable() */
| 422 | * @see CNetAddr::IsRoutable() |
| 423 | */ |
| 424 | bool CNetAddr::IsValid() const |
| 425 | { |
| 426 | // unspecified IPv6 address (::/128) |
| 427 | unsigned char ipNone6[16] = {}; |
| 428 | if (IsIPv6() && memcmp(m_addr.data(), ipNone6, sizeof(ipNone6)) == 0) { |
| 429 | return false; |
| 430 | } |
| 431 | |
| 432 | if (IsCJDNS() && !HasCJDNSPrefix()) { |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | // documentation IPv6 address |
| 437 | if (IsRFC3849()) |
| 438 | return false; |
| 439 | |
| 440 | if (IsInternal()) |
| 441 | return false; |
| 442 | |
| 443 | if (IsIPv4()) { |
| 444 | const uint32_t addr = ReadBE32(m_addr.data()); |
| 445 | if (addr == INADDR_ANY || addr == INADDR_NONE) { |
| 446 | return false; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | return true; |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * @returns Whether or not this network address is publicly routable on the |