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

Function CheckHostPortOptions

src/init.cpp:1234–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1232}
1233
1234bool CheckHostPortOptions(const ArgsManager& args) {
1235 for (const std::string port_option : {
1236 "-port",
1237 "-rpcport",
1238 }) {
1239 if (const auto port{args.GetArg(port_option)}) {
1240 const auto n{ToIntegral<uint16_t>(*port)};
1241 if (!n || *n == 0) {
1242 return InitError(InvalidPortErrMsg(port_option, *port));
1243 }
1244 }
1245 }
1246
1247 for ([[maybe_unused]] const auto& [param_name, unix, suffix_allowed] : std::vector<std::tuple<std::string, bool, bool>>{
1248 // arg name UNIX socket support =suffix allowed
1249 {"-i2psam", false, false},
1250 {"-onion", true, false},
1251 {"-proxy", true, true},
1252 {"-bind", false, true},
1253 {"-rpcbind", false, false},
1254 {"-torcontrol", false, false},
1255 {"-whitebind", false, false},
1256 {"-zmqpubhashblock", true, false},
1257 {"-zmqpubhashtx", true, false},
1258 {"-zmqpubrawblock", true, false},
1259 {"-zmqpubrawtx", true, false},
1260 {"-zmqpubsequence", true, false},
1261 }) {
1262 for (const std::string& param_value : args.GetArgs(param_name)) {
1263 const std::string param_value_hostport{
1264 suffix_allowed ? param_value.substr(0, param_value.rfind('=')) : param_value};
1265 std::string host_out;
1266 uint16_t port_out{0};
1267 if (!SplitHostPort(param_value_hostport, port_out, host_out)) {
1268#ifdef HAVE_SOCKADDR_UN
1269 // Allow unix domain sockets for some options e.g. unix:/some/file/path
1270 if (!unix || !param_value.starts_with(ADDR_PREFIX_UNIX)) {
1271 return InitError(InvalidPortErrMsg(param_name, param_value));
1272 }
1273#else
1274 return InitError(InvalidPortErrMsg(param_name, param_value));
1275#endif
1276 }
1277 }
1278 }
1279
1280 return true;
1281}
1282
1283/**
1284 * @brief Checks for duplicate bindings across all binding configurations.

Callers 1

AppInitMainFunction · 0.85

Calls 5

InitErrorFunction · 0.85
InvalidPortErrMsgFunction · 0.85
SplitHostPortFunction · 0.85
GetArgMethod · 0.80
GetArgsMethod · 0.80

Tested by

no test coverage detected