@@ -132,14 +132,9 @@ std::vector<std::string> GetNetworkNames(bool append_unroutable)
132
132
return names;
133
133
}
134
134
135
- static bool LookupIntern (const std::string& name, std::vector<CNetAddr>& vIP , unsigned int nMaxSolutions, bool fAllowLookup , DNSLookupFn dns_lookup_function)
135
+ static std::vector<CNetAddr> LookupIntern (const std::string& name, unsigned int nMaxSolutions, bool fAllowLookup , DNSLookupFn dns_lookup_function)
136
136
{
137
- vIP.clear ();
138
-
139
- if (!ContainsNoNUL (name)) {
140
- return false ;
141
- }
142
-
137
+ if (!ContainsNoNUL (name)) return {};
143
138
{
144
139
CNetAddr addr;
145
140
// From our perspective, onion addresses are not hostnames but rather
@@ -148,26 +143,25 @@ static bool LookupIntern(const std::string& name, std::vector<CNetAddr>& vIP, un
148
143
// getaddrinfo to decode them and it wouldn't make sense to resolve
149
144
// them, we return a network address representing it instead. See
150
145
// CNetAddr::SetSpecial(const std::string&) for more details.
151
- if (addr.SetSpecial (name)) {
152
- vIP.push_back (addr);
153
- return true ;
154
- }
146
+ if (addr.SetSpecial (name)) return {addr};
155
147
}
156
148
149
+ std::vector<CNetAddr> addresses;
150
+
157
151
for (const CNetAddr& resolved : dns_lookup_function (name, fAllowLookup )) {
158
- if (nMaxSolutions > 0 && vIP .size () >= nMaxSolutions) {
152
+ if (nMaxSolutions > 0 && addresses .size () >= nMaxSolutions) {
159
153
break ;
160
154
}
161
155
/* Never allow resolving to an internal address. Consider any such result invalid */
162
156
if (!resolved.IsInternal ()) {
163
- vIP .push_back (resolved);
157
+ addresses .push_back (resolved);
164
158
}
165
159
}
166
160
167
- return (vIP. size () > 0 ) ;
161
+ return addresses ;
168
162
}
169
163
170
- bool LookupHost (const std::string& name, std::vector<CNetAddr>& vIP , unsigned int nMaxSolutions, bool fAllowLookup , DNSLookupFn dns_lookup_function)
164
+ bool LookupHost (const std::string& name, std::vector<CNetAddr>& addresses , unsigned int nMaxSolutions, bool fAllowLookup , DNSLookupFn dns_lookup_function)
171
165
{
172
166
if (!ContainsNoNUL (name)) {
173
167
return false ;
@@ -179,7 +173,8 @@ bool LookupHost(const std::string& name, std::vector<CNetAddr>& vIP, unsigned in
179
173
strHost = strHost.substr (1 , strHost.size () - 2 );
180
174
}
181
175
182
- return LookupIntern (strHost, vIP, nMaxSolutions, fAllowLookup , dns_lookup_function);
176
+ addresses = LookupIntern (strHost, nMaxSolutions, fAllowLookup , dns_lookup_function);
177
+ return addresses.size () > 0 ;
183
178
}
184
179
185
180
bool LookupHost (const std::string& name, CNetAddr& addr, bool fAllowLookup , DNSLookupFn dns_lookup_function)
@@ -204,13 +199,12 @@ bool Lookup(const std::string& name, std::vector<CService>& vAddr, uint16_t port
204
199
std::string hostname;
205
200
SplitHostPort (name, port, hostname);
206
201
207
- std::vector<CNetAddr> vIP;
208
- bool fRet = LookupIntern (hostname, vIP, nMaxSolutions, fAllowLookup , dns_lookup_function);
209
- if (!fRet )
202
+ const std::vector<CNetAddr> addresses{LookupIntern (hostname, nMaxSolutions, fAllowLookup , dns_lookup_function)};
203
+ if (addresses.empty ())
210
204
return false ;
211
- vAddr.resize (vIP .size ());
212
- for (unsigned int i = 0 ; i < vIP .size (); i++)
213
- vAddr[i] = CService (vIP [i], port);
205
+ vAddr.resize (addresses .size ());
206
+ for (unsigned int i = 0 ; i < addresses .size (); i++)
207
+ vAddr[i] = CService (addresses [i], port);
214
208
return true ;
215
209
}
216
210
0 commit comments