Browse Source

cast pthread name to char* for apple sdk

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/1727/head
R4SAS 3 years ago
parent
commit
ac25649425
  1. 36
      libi2pd/util.cpp

36
libi2pd/util.cpp

@ -124,7 +124,7 @@ namespace util
void SetThreadName (const char *name) { void SetThreadName (const char *name) {
#if defined(__APPLE__) #if defined(__APPLE__)
pthread_setname_np(name); pthread_setname_np((char*)name);
#elif defined(__FreeBSD__) || defined(__OpenBSD__) #elif defined(__FreeBSD__) || defined(__OpenBSD__)
pthread_set_name_np(pthread_self(), name); pthread_set_name_np(pthread_self(), name);
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
@ -384,12 +384,13 @@ namespace net
return boost::asio::ip::address::from_string("127.0.0.1"); return boost::asio::ip::address::from_string("127.0.0.1");
#else #else
int af = (ipv6 ? AF_INET6 : AF_INET); int af = (ipv6 ? AF_INET6 : AF_INET);
ifaddrs *addrs, *cur = nullptr; ifaddrs *addrs;
if(getifaddrs(&addrs) == 0) try
{
ifaddrs *addrs;
if (!getifaddrs(&addrs))
{ {
// got ifaddrs for (auto cur = addrs; cur; cur = cur->ifa_next)
cur = addrs;
while(cur)
{ {
std::string cur_ifname(cur->ifa_name); std::string cur_ifname(cur->ifa_name);
if (cur_ifname == ifname && cur->ifa_addr && cur->ifa_addr->sa_family == af) if (cur_ifname == ifname && cur->ifa_addr && cur->ifa_addr->sa_family == af)
@ -405,9 +406,14 @@ namespace net
std::string cur_ifaddr(addr); std::string cur_ifaddr(addr);
return boost::asio::ip::address::from_string(cur_ifaddr); return boost::asio::ip::address::from_string(cur_ifaddr);
} }
cur = cur->ifa_next;
} }
} }
}
catch (std::exception& ex)
{
LogPrint(eLogError, "NetIface: Exception while searching address using ifaddr: ", ex);
}
if(addrs) freeifaddrs(addrs); if(addrs) freeifaddrs(addrs);
std::string fallback; std::string fallback;
if(ipv6) if(ipv6)
@ -483,12 +489,12 @@ namespace net
FREE(pAddresses); FREE(pAddresses);
return boost::asio::ip::address_v6 (); return boost::asio::ip::address_v6 ();
#else #else
ifaddrs *addrs, *cur = nullptr; ifaddrs *addrs;
auto err = getifaddrs(&addrs); try
if (!err) {
if (!getifaddrs(&addrs))
{ {
cur = addrs; for (auto cur = addrs; cur; cur = cur->ifa_next)
while(cur)
{ {
if (cur->ifa_addr && cur->ifa_addr->sa_family == AF_INET6) if (cur->ifa_addr && cur->ifa_addr->sa_family == AF_INET6)
{ {
@ -501,9 +507,13 @@ namespace net
return boost::asio::ip::address_v6 (bytes); return boost::asio::ip::address_v6 (bytes);
} }
} }
cur = cur->ifa_next;
} }
} }
}
catch (std::exception& ex)
{
LogPrint(eLogError, "NetIface: Exception while searching Yggdrasill address using ifaddr: ", ex);
}
LogPrint(eLogWarning, "NetIface: Interface with Yggdrasil network address not found"); LogPrint(eLogWarning, "NetIface: Interface with Yggdrasil network address not found");
if(addrs) freeifaddrs(addrs); if(addrs) freeifaddrs(addrs);
return boost::asio::ip::address_v6 (); return boost::asio::ip::address_v6 ();

Loading…
Cancel
Save