mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
get local yggdrasil ipv6 address
This commit is contained in:
parent
2d998aba43
commit
07282ec39f
@ -416,6 +416,36 @@ namespace net
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boost::asio::ip::address_v6 GetYggdrasilAddress ()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
// TODO: implement
|
||||||
|
return boost::asio::ip::address_v6 ();
|
||||||
|
#else
|
||||||
|
ifaddrs * addrs = nullptr;
|
||||||
|
auto err = getifaddrs(&addrs);
|
||||||
|
if (!err)
|
||||||
|
{
|
||||||
|
ifaddrs * cur = addrs;
|
||||||
|
while(cur)
|
||||||
|
{
|
||||||
|
if (cur->ifa_addr && cur->ifa_addr->sa_family == AF_INET6)
|
||||||
|
{
|
||||||
|
sockaddr_in6* sa = (sockaddr_in6*)cur->ifa_addr;
|
||||||
|
if (sa->sin6_addr.s6_addr[0] == 0x02 || sa->sin6_addr.s6_addr[0] == 0x03)
|
||||||
|
{
|
||||||
|
boost::asio::ip::address_v6::bytes_type bytes;
|
||||||
|
memcpy (bytes.data (), &sa->sin6_addr, 16);
|
||||||
|
return boost::asio::ip::address_v6 (bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cur = cur->ifa_next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return boost::asio::ip::address_v6 ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool IsInReservedRange (const boost::asio::ip::address& host) {
|
bool IsInReservedRange (const boost::asio::ip::address& host) {
|
||||||
// https://en.wikipedia.org/wiki/Reserved_IP_addresses
|
// https://en.wikipedia.org/wiki/Reserved_IP_addresses
|
||||||
if(host.is_v4())
|
if(host.is_v4())
|
||||||
|
@ -188,6 +188,7 @@ namespace util
|
|||||||
{
|
{
|
||||||
int GetMTU (const boost::asio::ip::address& localAddress);
|
int GetMTU (const boost::asio::ip::address& localAddress);
|
||||||
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 ();
|
||||||
bool IsInReservedRange (const boost::asio::ip::address& host);
|
bool IsInReservedRange (const boost::asio::ip::address& host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user