Changeset View
Changeset View
Standalone View
Standalone View
src/netbase.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | switch (net) { | ||||
return "ipv6"; | return "ipv6"; | ||||
case NET_TOR: | case NET_TOR: | ||||
return "onion"; | return "onion"; | ||||
default: | default: | ||||
return ""; | return ""; | ||||
} | } | ||||
} | } | ||||
void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { | |||||
size_t colon = in.find_last_of(':'); | |||||
// if a : is found, and it either follows a [...], or no other : is in the | |||||
// string, treat it as port separator | |||||
bool fHaveColon = colon != in.npos; | |||||
// if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is | |||||
// safe | |||||
bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); | |||||
bool fMultiColon = | |||||
fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); | |||||
if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { | |||||
int32_t n; | |||||
if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { | |||||
in = in.substr(0, colon); | |||||
portOut = n; | |||||
} | |||||
} | |||||
if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') { | |||||
hostOut = in.substr(1, in.size() - 2); | |||||
} else { | |||||
hostOut = in; | |||||
} | |||||
} | |||||
static bool LookupIntern(const char *pszName, std::vector<CNetAddr> &vIP, | static bool LookupIntern(const char *pszName, std::vector<CNetAddr> &vIP, | ||||
unsigned int nMaxSolutions, bool fAllowLookup) { | unsigned int nMaxSolutions, bool fAllowLookup) { | ||||
vIP.clear(); | vIP.clear(); | ||||
{ | { | ||||
CNetAddr addr; | CNetAddr addr; | ||||
if (addr.SetSpecial(std::string(pszName))) { | if (addr.SetSpecial(std::string(pszName))) { | ||||
vIP.push_back(addr); | vIP.push_back(addr); | ||||
▲ Show 20 Lines • Show All 654 Lines • Show Last 20 Lines |