Browse Source

get local yggdrasil ipv6 address

pull/1626/head
orignal 4 years ago
parent
commit
07282ec39f
  1. 30
      libi2pd/util.cpp
  2. 1
      libi2pd/util.h

30
libi2pd/util.cpp

@ -416,6 +416,36 @@ namespace net @@ -416,6 +416,36 @@ namespace net
#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) {
// https://en.wikipedia.org/wiki/Reserved_IP_addresses
if(host.is_v4())

1
libi2pd/util.h

@ -188,6 +188,7 @@ namespace util @@ -188,6 +188,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 IsInReservedRange (const boost::asio::ip::address& host);
}
}

Loading…
Cancel
Save