* @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() */
| 449 | * @see CNetAddr::IsRoutable() |
| 450 | */ |
| 451 | bool CNetAddr::IsValid() const |
| 452 | { |
| 453 | // unspecified IPv6 address (::/128) |
| 454 | unsigned char ipNone6[16] = {}; |
| 455 | if (IsIPv6() && memcmp(m_addr.data(), ipNone6, sizeof(ipNone6)) == 0) { |
| 456 | return false; |
| 457 | } |
| 458 | |
| 459 | // CJDNS addresses always start with 0xfc |
| 460 | if (IsCJDNS() && (m_addr[0] != 0xFC)) { |
| 461 | return false; |
| 462 | } |
| 463 | |
| 464 | // documentation IPv6 address |
| 465 | if (IsRFC3849()) |
| 466 | return false; |
| 467 | |
| 468 | if (IsInternal()) |
| 469 | return false; |
| 470 | |
| 471 | if (IsIPv4()) { |
| 472 | const uint32_t addr = ReadBE32(m_addr.data()); |
| 473 | if (addr == INADDR_ANY || addr == INADDR_NONE) { |
| 474 | return false; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | return true; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * @returns Whether or not this network address is publicly routable on the |