MCPcopy Create free account
hub / github.com/ElementsProject/elements / Discover

Function Discover

src/net.cpp:2461–2510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2459}
2460
2461void Discover()
2462{
2463 if (!fDiscover)
2464 return;
2465
2466#ifdef WIN32
2467 // Get local host IP
2468 char pszHostName[256] = "";
2469 if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR)
2470 {
2471 std::vector<CNetAddr> vaddr;
2472 if (LookupHost(pszHostName, vaddr, 0, true))
2473 {
2474 for (const CNetAddr &addr : vaddr)
2475 {
2476 if (AddLocal(addr, LOCAL_IF))
2477 LogPrintf("%s: %s - %s\n", __func__, pszHostName, addr.ToString());
2478 }
2479 }
2480 }
2481#elif (HAVE_DECL_GETIFADDRS && HAVE_DECL_FREEIFADDRS)
2482 // Get local host ip
2483 struct ifaddrs* myaddrs;
2484 if (getifaddrs(&myaddrs) == 0)
2485 {
2486 for (struct ifaddrs* ifa = myaddrs; ifa != nullptr; ifa = ifa->ifa_next)
2487 {
2488 if (ifa->ifa_addr == nullptr) continue;
2489 if ((ifa->ifa_flags & IFF_UP) == 0) continue;
2490 if (strcmp(ifa->ifa_name, "lo") == 0) continue;
2491 if (strcmp(ifa->ifa_name, "lo0") == 0) continue;
2492 if (ifa->ifa_addr->sa_family == AF_INET)
2493 {
2494 struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);
2495 CNetAddr addr(s4->sin_addr);
2496 if (AddLocal(addr, LOCAL_IF))
2497 LogPrintf("%s: IPv4 %s: %s\n", __func__, ifa->ifa_name, addr.ToString());
2498 }
2499 else if (ifa->ifa_addr->sa_family == AF_INET6)
2500 {
2501 struct sockaddr_in6* s6 = (struct sockaddr_in6*)(ifa->ifa_addr);
2502 CNetAddr addr(s6->sin6_addr);
2503 if (AddLocal(addr, LOCAL_IF))
2504 LogPrintf("%s: IPv6 %s: %s\n", __func__, ifa->ifa_name, addr.ToString());
2505 }
2506 }
2507 freeifaddrs(myaddrs);
2508 }
2509#endif
2510}
2511
2512void CConnman::SetNetworkActive(bool active)
2513{

Callers 1

AppInitMainFunction · 0.85

Calls 3

LookupHostFunction · 0.85
AddLocalFunction · 0.85
ToStringMethod · 0.45

Tested by

no test coverage detected