MCPcopy Create free account
hub / github.com/LUX-Core/lux / SplitHostPort

Function SplitHostPort

src/netbase.cpp:79–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void SplitHostPort(std::string in, int& portOut, std::string& hostOut)
80{
81 size_t colon = in.find_last_of(':');
82 // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
83 bool fHaveColon = colon != in.npos;
84 bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is safe
85 bool fMultiColon = fHaveColon && (in.find_last_of(':', colon - 1) != in.npos);
86 if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) {
87 int32_t n;
88 if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) {
89 in = in.substr(0, colon);
90 portOut = n;
91 }
92 }
93 if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']')
94 hostOut = in.substr(1, in.size() - 2);
95 else
96 hostOut = in;
97}
98
99bool static LookupIntern(const char* pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions, bool fAllowLookup)
100{

Callers 5

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

Calls 2

ParseInt32Function · 0.85
sizeMethod · 0.45

Tested by 1

TestSplitHostFunction · 0.68