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

Function SplitHostPort

src/netbase.cpp:44–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44void SplitHostPort(string in, int& portOut, string& hostOut) {
45 size_t colon = in.find_last_of(':');
46 // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
47 bool fHaveColon = colon != in.npos;
48 bool fBracketed =
49 fHaveColon &&
50 (in[0] == '[' &&
51 in[colon - 1] == ']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe
52 bool fMultiColon = fHaveColon && (in.find_last_of(':', colon - 1) != in.npos);
53 if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) {
54 char* endp = nullptr;
55 int n = strtol(in.c_str() + colon + 1, &endp, 10);
56 if (endp && *endp == 0 && n >= 0) {
57 in = in.substr(0, colon);
58 if (n > 0 && n < 0x10000) portOut = n;
59 }
60 }
61 if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']')
62 hostOut = in.substr(1, in.size() - 2);
63 else
64 hostOut = in;
65}
66
67bool static LookupIntern(const char* pszName, vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup) {
68 vIP.clear();

Callers 4

LookupFunction · 0.85
ConnectSocketByNameFunction · 0.85
TestSplitHostFunction · 0.85
HTTPBindAddressesFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by 1

TestSplitHostFunction · 0.68