diff --git a/llarp/net.hpp b/llarp/net.hpp index 55a88d919..8aceb8c36 100644 --- a/llarp/net.hpp +++ b/llarp/net.hpp @@ -192,11 +192,27 @@ namespace llarp && port() == other.port(); } + bool + sameAddr(const Addr& other) const + { + return memcmp(addr6(), other.addr6(), 16) == 0; + } + bool operator!=(const Addr& other) const { return !(*this == other); } + + bool isPrivate() + { + in_addr_t addr = this->addr4()->s_addr; + unsigned byte = ntohl(addr); + unsigned byte1 = byte >> 24 & 0xff; + unsigned byte2 = byte >> 16 & 0xff; + return (byte1 == 10 || (byte1 == 192 && byte2 == 168) || (byte1 == 172 && (byte2 & 0xf0) == 16)); + } + }; struct addrhash