| 787 | } |
| 788 | |
| 789 | bool CNetAddr::IsValid() const |
| 790 | { |
| 791 | // Cleanup 3-byte shifted addresses caused by garbage in size field |
| 792 | // of addr messages from versions before 0.2.9 checksum. |
| 793 | // Two consecutive addr messages look like this: |
| 794 | // header20 vectorlen3 addr26 addr26 addr26 header20 vectorlen3 addr26 addr26 addr26... |
| 795 | // so if the first length field is garbled, it reads the second batch |
| 796 | // of addr misaligned by 3 bytes. |
| 797 | if (memcmp(ip, pchIPv4 + 3, sizeof(pchIPv4) - 3) == 0) |
| 798 | return false; |
| 799 | |
| 800 | // unspecified IPv6 address (::/128) |
| 801 | unsigned char ipNone6[16] = {}; |
| 802 | if (memcmp(ip, ipNone6, 16) == 0) |
| 803 | return false; |
| 804 | |
| 805 | // documentation IPv6 address |
| 806 | if (IsRFC3849()) |
| 807 | return false; |
| 808 | |
| 809 | if (IsIPv4()) { |
| 810 | // INADDR_NONE |
| 811 | uint32_t ipNone = INADDR_NONE; |
| 812 | if (memcmp(ip + 12, &ipNone, 4) == 0) |
| 813 | return false; |
| 814 | |
| 815 | // 0 |
| 816 | ipNone = 0; |
| 817 | if (memcmp(ip + 12, &ipNone, 4) == 0) |
| 818 | return false; |
| 819 | } |
| 820 | |
| 821 | return true; |
| 822 | } |
| 823 | |
| 824 | bool CNetAddr::IsRoutable() const |
| 825 | { |
no outgoing calls
no test coverage detected