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

Function SplitHostPort

src/util/strencodings.cpp:71–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69template std::optional<std::vector<uint8_t>> TryParseHex(std::string_view);
70
71bool SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut)
72{
73 bool valid = false;
74 size_t colon = in.find_last_of(':');
75 // if a : is found, and it either follows a [...], or no other : is in the string, treat it as port separator
76 bool fHaveColon = colon != in.npos;
77 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
78 bool fMultiColon{fHaveColon && colon != 0 && (in.find_last_of(':', colon - 1) != in.npos)};
79 if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) {
80 if (const auto n{ToIntegral<uint16_t>(in.substr(colon + 1))}) {
81 in = in.substr(0, colon);
82 portOut = *n;
83 valid = (portOut != 0);
84 }
85 } else {
86 valid = true;
87 }
88 if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') {
89 hostOut = in.substr(1, in.size() - 2);
90 } else {
91 hostOut = in;
92 }
93
94 return valid;
95}
96
97std::string EncodeBase64(std::span<const unsigned char> input)
98{

Callers 10

GetBindAddressesFunction · 0.85
CallRPCFunction · 0.85
LookupFunction · 0.85
CheckHostPortOptionsFunction · 0.85
AppInitMainFunction · 0.85
ConnectNodeMethod · 0.85
TestSplitHostFunction · 0.85
FUZZ_TARGETFunction · 0.85
ParseProxyStringFunction · 0.85
validateMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by 2

TestSplitHostFunction · 0.68
FUZZ_TARGETFunction · 0.68