src/httpserver.cpp
static bool HTTPBindAddresses(struct evhttp* http)
{
    int http_port = gArgs.GetArg("-rpcport", BaseParams().RPCPort());
    std::vector<std::pair<std::string, uint16_t> > endpoints;

    // Determine what addresses to bind to
    if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { // Default to loopback if not allowing external IPs
        endpoints.push_back(std::make_pair("::1", http_port));
        endpoints.push_back(std::make_pair("127.0.0.1", http_port));
        if (gArgs.IsArgSet("-rpcallowip")) {
            LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
        }
        if (gArgs.IsArgSet("-rpcbind")) {
            LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
        }
    } else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address
        for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) {
            int port = http_port;
            std::string host;
            SplitHostPort(strRPCBind, port, host);
            endpoints.push_back(std::make_pair(host, port));
        }
    }

    // Bind addresses
    for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
        LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second);
        evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second);
        if (bind_handle) {
            CNetAddr addr;
            if (i->first.empty() || (LookupHost(i->first, addr, false) && addr.IsBindAny())) {
                LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n");
            }
            boundSockets.push_back(bind_handle);
        } else {
            LogPrintf("Binding RPC on address %s port %i failed.\n", i->first, i->second);
        }
    }
    return !boundSockets.empty();
}
/** Bind HTTP server to specified addresses */
Bind HTTP server to specified addresses
Bind HTTP server to specified addresses
static bool HTTPBindAddresses(struct evhttp* http)
{
    int http_port = gArgs.GetArg("-rpcport", BaseParams().RPCPort());
    std::vector<std::pair<std::string, uint16_t> > endpoints;
    if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-rpcbind"))) { 
        endpoints.push_back(std::make_pair("::1", http_port));
        endpoints.push_back(std::make_pair("127.0.0.1", http_port));
        if (gArgs.IsArgSet("-rpcallowip")) {
            LogPrintf("WARNING: option -rpcallowip was specified without -rpcbind; this doesn't usually make sense\n");
        }
        if (gArgs.IsArgSet("-rpcbind")) {
            LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
        }
    } else if (gArgs.IsArgSet("-rpcbind")) { 
        for (const std::string& strRPCBind : gArgs.GetArgs("-rpcbind")) {
            int port = http_port;
            std::string host;
            SplitHostPort(strRPCBind, port, host);
            endpoints.push_back(std::make_pair(host, port));
        }
    }
    for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
        LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second);
        evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? nullptr : i->first.c_str(), i->second);
        if (bind_handle) {
            CNetAddr addr;
            if (i->first.empty() || (LookupHost(i->first, addr, false) && addr.IsBindAny())) {
                LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n");
            }
            boundSockets.push_back(bind_handle);
        } else {
            LogPrintf("Binding RPC on address %s port %i failed.\n", i->first, i->second);
        }
    }
    return !boundSockets.empty();
}
static bool HTTPBindAddresses ( struct evhttp * http ) { int http_port = gArgs . GetArg ( " " , BaseParams ( ) . RPCPort ( ) ) ; std :: vector < std :: pair < std :: string , uint16_t > > endpoints ; if ( ! ( gArgs . IsArgSet ( " " ) && gArgs . IsArgSet ( " " ) ) ) { endpoints . push_back ( std :: make_pair ( " " , http_port ) ) ; endpoints . push_back ( std :: make_pair ( " " , http_port ) ) ; if ( gArgs . IsArgSet ( " " ) ) { LogPrintf ( " \n " ) ; } if ( gArgs . IsArgSet ( " " ) ) { LogPrintf ( " \n " ) ; } } else if ( gArgs . IsArgSet ( " " ) ) { for ( const std :: string & strRPCBind : gArgs . GetArgs ( " " ) ) { int port = http_port ; std :: string host ; SplitHostPort ( strRPCBind , port , host ) ; endpoints . push_back ( std :: make_pair ( host , port ) ) ; } } for ( std :: vector < std :: pair < std :: string , uint16_t > > :: iterator i = endpoints . begin ( ) ; i != endpoints . end ( ) ; ++ i ) { LogPrint ( BCLog :: HTTP , " \n " , i -> first , i -> second ) ; evhttp_bound_socket * bind_handle = evhttp_bind_socket_with_handle ( http , i -> first . empty ( ) ? nullptr : i -> first . c_str ( ) , i -> second ) ; if ( bind_handle ) { CNetAddr addr ; if ( i -> first . empty ( ) || ( LookupHost ( i -> first , addr , false ) && addr . IsBindAny ( ) ) ) { LogPrintf ( " \n " ) ; } boundSockets . push_back ( bind_handle ) ; } else { LogPrintf ( " \n " , i -> first , i -> second ) ; } } return ! boundSockets . empty ( ) ; }
Bind HTTP server to specified addresses
Bind HTTP server to specified addresses
// Determine what addresses to bind to // Default to loopback if not allowing external IPs // Specific bind address // Bind addresses