mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
check local address
This commit is contained in:
parent
05c7aacfa5
commit
a74f685a5d
|
@ -152,7 +152,8 @@ namespace i2p
|
|||
if (!yggaddress.empty ())
|
||||
{
|
||||
yggaddr = boost::asio::ip::address_v6::from_string (yggaddress);
|
||||
if (yggaddr.is_unspecified () || i2p::util::net::GetMTU (yggaddr) != 0xFFFF) // ygg's MTU is always 65535
|
||||
if (yggaddr.is_unspecified () || !i2p::util::net::IsYggdrasilAddress (yggaddr) ||
|
||||
!i2p::util::net::IsLocalAddress (yggaddr))
|
||||
{
|
||||
LogPrint(eLogWarning, "Daemon: Can't find Yggdrasil address ", yggaddress);
|
||||
ygg = false;
|
||||
|
|
|
@ -461,6 +461,17 @@ namespace net
|
|||
#endif
|
||||
}
|
||||
|
||||
bool IsLocalAddress (const boost::asio::ip::address& addr)
|
||||
{
|
||||
auto mtu = // TODO: implement better
|
||||
#ifdef _WIN32
|
||||
GetMTUWindows(addr, 0);
|
||||
#else
|
||||
GetMTUUnix(addr, 0);
|
||||
#endif
|
||||
return mtu > 0;
|
||||
}
|
||||
|
||||
bool IsInReservedRange (const boost::asio::ip::address& host)
|
||||
{
|
||||
// https://en.wikipedia.org/wiki/Reserved_IP_addresses
|
||||
|
|
|
@ -189,6 +189,7 @@ namespace util
|
|||
int GetMTU (const boost::asio::ip::address& localAddress);
|
||||
const boost::asio::ip::address GetInterfaceAddress (const std::string & ifname, bool ipv6=false);
|
||||
boost::asio::ip::address_v6 GetYggdrasilAddress ();
|
||||
bool IsLocalAddress (const boost::asio::ip::address& addr);
|
||||
bool IsInReservedRange (const boost::asio::ip::address& host);
|
||||
bool IsYggdrasilAddress (const boost::asio::ip::address& addr);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue