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

Function LookupIntern

src/netbase.cpp:87–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87bool static LookupIntern(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
88{
89 vIP.clear();
90
91 {
92 CNetAddr addr;
93 if (addr.SetSpecial(std::string(pszName))) {
94 vIP.push_back(addr);
95 return true;
96 }
97 }
98
99#ifdef HAVE_GETADDRINFO_A
100 struct in_addr ipv4_addr;
101#ifdef HAVE_INET_PTON
102 if (inet_pton(AF_INET, pszName, &ipv4_addr) > 0) {
103 vIP.push_back(CNetAddr(ipv4_addr));
104 return true;
105 }
106
107 struct in6_addr ipv6_addr;
108 if (inet_pton(AF_INET6, pszName, &ipv6_addr) > 0) {
109 vIP.push_back(CNetAddr(ipv6_addr));
110 return true;
111 }
112#else
113 ipv4_addr.s_addr = inet_addr(pszName);
114 if (ipv4_addr.s_addr != INADDR_NONE) {
115 vIP.push_back(CNetAddr(ipv4_addr));
116 return true;
117 }
118#endif
119#endif
120
121 struct addrinfo aiHint;
122 memset(&aiHint, 0, sizeof(struct addrinfo));
123 aiHint.ai_socktype = SOCK_STREAM;
124 aiHint.ai_protocol = IPPROTO_TCP;
125 aiHint.ai_family = AF_UNSPEC;
126#ifdef WIN32
127 aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST;
128#else
129 aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST;
130#endif
131
132 struct addrinfo *aiRes = NULL;
133#ifdef HAVE_GETADDRINFO_A
134 struct gaicb gcb, *query = &gcb;
135 memset(query, 0, sizeof(struct gaicb));
136 gcb.ar_name = pszName;
137 gcb.ar_request = &aiHint;
138 int nErr = getaddrinfo_a(GAI_NOWAIT, &query, 1, NULL);
139 if (nErr)
140 return false;
141
142 do {
143 // Should set the timeout limit to a resonable value to avoid
144 // generating unnecessary checking call during the polling loop,

Callers 2

LookupHostFunction · 0.85
LookupFunction · 0.85

Calls 5

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

Tested by

no test coverage detected