MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / Discover

Function Discover

src/net.cpp:2149–2198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2147}
2148
2149void Discover()
2150{
2151 if (!fDiscover)
2152 return;
2153
2154#ifdef WIN32
2155 // Get local host IP
2156 char pszHostName[256] = "";
2157 if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR)
2158 {
2159 std::vector<CNetAddr> vaddr;
2160 if (LookupHost(pszHostName, vaddr, 0, true))
2161 {
2162 for (const CNetAddr &addr : vaddr)
2163 {
2164 if (AddLocal(addr, LOCAL_IF))
2165 LogPrintf("%s: %s - %s\n", __func__, pszHostName, addr.ToString());
2166 }
2167 }
2168 }
2169#else
2170 // Get local host ip
2171 struct ifaddrs* myaddrs;
2172 if (getifaddrs(&myaddrs) == 0)
2173 {
2174 for (struct ifaddrs* ifa = myaddrs; ifa != nullptr; ifa = ifa->ifa_next)
2175 {
2176 if (ifa->ifa_addr == nullptr) continue;
2177 if ((ifa->ifa_flags & IFF_UP) == 0) continue;
2178 if (strcmp(ifa->ifa_name, "lo") == 0) continue;
2179 if (strcmp(ifa->ifa_name, "lo0") == 0) continue;
2180 if (ifa->ifa_addr->sa_family == AF_INET)
2181 {
2182 struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);
2183 CNetAddr addr(s4->sin_addr);
2184 if (AddLocal(addr, LOCAL_IF))
2185 LogPrintf("%s: IPv4 %s: %s\n", __func__, ifa->ifa_name, addr.ToString());
2186 }
2187 else if (ifa->ifa_addr->sa_family == AF_INET6)
2188 {
2189 struct sockaddr_in6* s6 = (struct sockaddr_in6*)(ifa->ifa_addr);
2190 CNetAddr addr(s6->sin6_addr);
2191 if (AddLocal(addr, LOCAL_IF))
2192 LogPrintf("%s: IPv6 %s: %s\n", __func__, ifa->ifa_name, addr.ToString());
2193 }
2194 }
2195 freeifaddrs(myaddrs);
2196 }
2197#endif
2198}
2199
2200void CConnman::SetNetworkActive(bool active)
2201{

Callers 1

AppInitMainFunction · 0.85

Calls 3

LookupHostFunction · 0.85
AddLocalFunction · 0.85
ToStringMethod · 0.45

Tested by

no test coverage detected