1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-02-02 19:24:14 +00:00

IsYggdrasilAddress added

This commit is contained in:
orignal 2021-01-29 13:27:49 -05:00
parent 1ba5d25819
commit 82649ab2a7
2 changed files with 15 additions and 2 deletions

View File

@ -418,6 +418,17 @@ namespace net
#endif #endif
} }
static bool IsYggdrasilAddress (const uint8_t addr[16])
{
return addr[0] == 0x02 || addr[0] == 0x03;
}
bool IsYggdrasilAddress (const boost::asio::ip::address& addr)
{
if (!addr.is_v6 ()) return false;
return IsYggdrasilAddress (addr.to_v6 ().to_bytes ().data ());
}
boost::asio::ip::address_v6 GetYggdrasilAddress () boost::asio::ip::address_v6 GetYggdrasilAddress ()
{ {
#if (defined(_WIN32) || defined(ANDROID)) #if (defined(_WIN32) || defined(ANDROID))
@ -434,7 +445,7 @@ namespace net
if (cur->ifa_addr && cur->ifa_addr->sa_family == AF_INET6) if (cur->ifa_addr && cur->ifa_addr->sa_family == AF_INET6)
{ {
sockaddr_in6* sa = (sockaddr_in6*)cur->ifa_addr; sockaddr_in6* sa = (sockaddr_in6*)cur->ifa_addr;
if (sa->sin6_addr.s6_addr[0] == 0x02 || sa->sin6_addr.s6_addr[0] == 0x03) if (IsYggdrasilAddress(sa->sin6_addr.s6_addr))
{ {
boost::asio::ip::address_v6::bytes_type bytes; boost::asio::ip::address_v6::bytes_type bytes;
memcpy (bytes.data (), &sa->sin6_addr, 16); memcpy (bytes.data (), &sa->sin6_addr, 16);
@ -444,6 +455,7 @@ namespace net
cur = cur->ifa_next; cur = cur->ifa_next;
} }
} }
if(addrs) freeifaddrs(addrs);
return boost::asio::ip::address_v6 (); return boost::asio::ip::address_v6 ();
#endif #endif
} }
@ -489,7 +501,7 @@ namespace net
if (ipv6_address >= it.first && ipv6_address <= it.second) if (ipv6_address >= it.first && ipv6_address <= it.second)
return true; return true;
} }
if (checkYggdrasil && (ipv6_address[0] == 0x02 || ipv6_address[0] == 0x03)) // yggdrasil? if (checkYggdrasil && IsYggdrasilAddress (ipv6_address.data ())) // yggdrasil?
return true; return true;
} }
return false; return false;

View File

@ -190,6 +190,7 @@ namespace util
const boost::asio::ip::address GetInterfaceAddress (const std::string & ifname, bool ipv6=false); const boost::asio::ip::address GetInterfaceAddress (const std::string & ifname, bool ipv6=false);
boost::asio::ip::address_v6 GetYggdrasilAddress (); boost::asio::ip::address_v6 GetYggdrasilAddress ();
bool IsInReservedRange (const boost::asio::ip::address& host, bool checkYggdrasil = true); bool IsInReservedRange (const boost::asio::ip::address& host, bool checkYggdrasil = true);
bool IsYggdrasilAddress (const boost::asio::ip::address& addr);
} }
} }
} }