MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / LookupIntern

Function LookupIntern

src/netbase.cpp:67–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67bool static LookupIntern(const char* pszName, vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup) {
68 vIP.clear();
69
70 {
71 CNetAddr addr;
72 if (addr.SetSpecial(string(pszName))) {
73 vIP.push_back(addr);
74 return true;
75 }
76 }
77
78 struct addrinfo aiHint;
79 memset(&aiHint, 0, sizeof(struct addrinfo));
80
81 aiHint.ai_socktype = SOCK_STREAM;
82 aiHint.ai_protocol = IPPROTO_TCP;
83 aiHint.ai_family = AF_UNSPEC;
84#ifdef WIN32
85 aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
86#else
87 aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
88#endif
89 struct addrinfo* aiRes = nullptr;
90 int nErr = getaddrinfo(pszName, nullptr, &aiHint, &aiRes);
91 if (nErr)
92 return false;
93
94 struct addrinfo* aiTrav = aiRes;
95 while (aiTrav != nullptr && (nMaxSolutions == 0 || vIP.size() < nMaxSolutions)) {
96 if (aiTrav->ai_family == AF_INET) {
97 assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in));
98 vIP.push_back(CNetAddr(((struct sockaddr_in*)(aiTrav->ai_addr))->sin_addr));
99 }
100
101 if (aiTrav->ai_family == AF_INET6) {
102 assert(aiTrav->ai_addrlen >= sizeof(sockaddr_in6));
103 vIP.push_back(CNetAddr(((struct sockaddr_in6*)(aiTrav->ai_addr))->sin6_addr));
104 }
105
106 aiTrav = aiTrav->ai_next;
107 }
108
109 freeaddrinfo(aiRes);
110
111 return (vIP.size() > 0);
112}
113
114bool LookupHost(const char* pszName, vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup) {
115 string strHost(pszName);

Callers 2

LookupHostFunction · 0.85
LookupFunction · 0.85

Calls 5

SetSpecialMethod · 0.80
push_backMethod · 0.80
CNetAddrClass · 0.70
clearMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected