mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
net: Use GetLocalAddresses in Discover
This has the same code, it's unnecessary to duplicate it.
This commit is contained in:
parent
e02030432b
commit
d72df63d16
2 changed files with 4 additions and 40 deletions
43
src/net.cpp
43
src/net.cpp
|
@ -28,6 +28,7 @@
|
||||||
#include <random.h>
|
#include <random.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <util/fs.h>
|
#include <util/fs.h>
|
||||||
|
#include <util/netif.h>
|
||||||
#include <util/sock.h>
|
#include <util/sock.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/thread.h>
|
#include <util/thread.h>
|
||||||
|
@ -3118,46 +3119,10 @@ void Discover()
|
||||||
if (!fDiscover)
|
if (!fDiscover)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef WIN32
|
for (const CNetAddr &addr: GetLocalAddresses()) {
|
||||||
// Get local host IP
|
if (AddLocal(addr, LOCAL_IF))
|
||||||
char pszHostName[256] = "";
|
LogPrintf("%s: %s\n", __func__, addr.ToStringAddr());
|
||||||
if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR)
|
|
||||||
{
|
|
||||||
const std::vector<CNetAddr> addresses{LookupHost(pszHostName, 0, true)};
|
|
||||||
for (const CNetAddr& addr : addresses)
|
|
||||||
{
|
|
||||||
if (AddLocal(addr, LOCAL_IF))
|
|
||||||
LogPrintf("%s: %s - %s\n", __func__, pszHostName, addr.ToStringAddr());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#elif (HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS)
|
|
||||||
// Get local host ip
|
|
||||||
struct ifaddrs* myaddrs;
|
|
||||||
if (getifaddrs(&myaddrs) == 0)
|
|
||||||
{
|
|
||||||
for (struct ifaddrs* ifa = myaddrs; ifa != nullptr; ifa = ifa->ifa_next)
|
|
||||||
{
|
|
||||||
if (ifa->ifa_addr == nullptr) continue;
|
|
||||||
if ((ifa->ifa_flags & IFF_UP) == 0) continue;
|
|
||||||
if ((ifa->ifa_flags & IFF_LOOPBACK) != 0) continue;
|
|
||||||
if (ifa->ifa_addr->sa_family == AF_INET)
|
|
||||||
{
|
|
||||||
struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);
|
|
||||||
CNetAddr addr(s4->sin_addr);
|
|
||||||
if (AddLocal(addr, LOCAL_IF))
|
|
||||||
LogPrintf("%s: IPv4 %s: %s\n", __func__, ifa->ifa_name, addr.ToStringAddr());
|
|
||||||
}
|
|
||||||
else if (ifa->ifa_addr->sa_family == AF_INET6)
|
|
||||||
{
|
|
||||||
struct sockaddr_in6* s6 = (struct sockaddr_in6*)(ifa->ifa_addr);
|
|
||||||
CNetAddr addr(s6->sin6_addr);
|
|
||||||
if (AddLocal(addr, LOCAL_IF))
|
|
||||||
LogPrintf("%s: IPv6 %s: %s\n", __func__, ifa->ifa_name, addr.ToStringAddr());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
freeifaddrs(myaddrs);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnman::SetNetworkActive(bool active)
|
void CConnman::SetNetworkActive(bool active)
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
//! Returns std::nullopt if it cannot be found, or there is no support for this OS.
|
//! Returns std::nullopt if it cannot be found, or there is no support for this OS.
|
||||||
std::optional<CNetAddr> QueryDefaultGateway(Network network);
|
std::optional<CNetAddr> QueryDefaultGateway(Network network);
|
||||||
|
|
||||||
// TODO share with Discover()
|
|
||||||
//! Return all local non-loopback IPv4 and IPv6 network addresses.
|
//! Return all local non-loopback IPv4 and IPv6 network addresses.
|
||||||
std::vector<CNetAddr> GetLocalAddresses();
|
std::vector<CNetAddr> GetLocalAddresses();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue