@@ -3684,8 +3684,8 @@ void my_get_callback( HTTPServer* hs, HTTPRequest const & req, HTTPResponse & re
3684
3684
}
3685
3685
}
3686
3686
3687
- int startHTTPServer ( unsigned short port ) {
3688
- HTTPServer server ( " " , port );
3687
+ int startHTTPServer ( std::string const & ip, unsigned short port ) {
3688
+ HTTPServer server ( ip , port );
3689
3689
try {
3690
3690
// HEAD is GET without body, we will remove the body in execute()
3691
3691
server.registerCallback ( HTTPRequestMethod::GET, my_get_callback );
@@ -3699,8 +3699,8 @@ int startHTTPServer( unsigned short port ) {
3699
3699
}
3700
3700
3701
3701
#if defined (USE_SSL)
3702
- int startHTTPSServer ( unsigned short port, std::string const & cFile, std::string const & pkFile) {
3703
- HTTPSServer server ( " " , port );
3702
+ int startHTTPSServer ( std::string const & ip, unsigned short port, std::string const & cFile, std::string const & pkFile) {
3703
+ HTTPSServer server ( ip , port );
3704
3704
try {
3705
3705
server.setPrivateKeyFile ( pkFile );
3706
3706
server.setCertificateFile ( cFile );
@@ -3724,6 +3724,7 @@ void printHelpText( std::string const & programName ) {
3724
3724
#if defined (USE_SSL)
3725
3725
std::cout << " -s : Use https protocol (default port " << DEFAULT_HTTPS_PORT << " )\n " ;
3726
3726
#endif
3727
+ std::cout << " -h bind ip : Bind to ip address. (default ip is 0.0.0.0)\n " ;
3727
3728
std::cout << " -p portnumber : Run on port <portnumber> (default port is " << DEFAULT_HTTP_PORT << " )\n " ;
3728
3729
std::cout << " -r|--reset : Reset programming of the performance counters.\n " ;
3729
3730
std::cout << " -D|--debug level : level = 0: no debug info, > 0 increase verbosity.\n " ;
@@ -3762,6 +3763,7 @@ int mainThrows(int argc, char * argv[]) {
3762
3763
#endif
3763
3764
bool forceRTMAbortMode = false ;
3764
3765
bool printTopology = false ;
3766
+ std::string host = " " ;
3765
3767
unsigned short port = 0 ;
3766
3768
unsigned short debug_level = 0 ;
3767
3769
std::string certificateFile;
@@ -3788,6 +3790,14 @@ int mainThrows(int argc, char * argv[]) {
3788
3790
for ( int i=1 ; i < argc; ++i ) {
3789
3791
if ( check_argument_equals ( argv[i], {" -d" } ) )
3790
3792
daemonMode = true ;
3793
+ else if ( check_argument_equals ( argv[i], {" -h" } ) )
3794
+ {
3795
+ if ( (++i) < argc ) {
3796
+ host = argv[i];
3797
+ } else {
3798
+ throw std::runtime_error ( " main: Error no bind ip argument given" );
3799
+ }
3800
+ }
3791
3801
else if ( check_argument_equals ( argv[i], {" -p" } ) )
3792
3802
{
3793
3803
if ( (++i) < argc ) {
@@ -4054,19 +4064,20 @@ int mainThrows(int argc, char * argv[]) {
4054
4064
deleteAndNullify ( tp );
4055
4065
exit ( 0 );
4056
4066
}
4067
+ const auto hostString = host.length () > 0 ? host : " localhost" ;
4057
4068
#if defined (USE_SSL)
4058
4069
if ( useSSL ) {
4059
4070
if ( port == 0 )
4060
4071
port = DEFAULT_HTTPS_PORT;
4061
- std::cerr << " Starting SSL enabled server on https://localhost :" << port << " /\n " ;
4062
- startHTTPSServer ( port, certificateFile, privateKeyFile );
4072
+ std::cerr << " Starting SSL enabled server on https://" << hostString << " :" << port << " /\n " ;
4073
+ startHTTPSServer ( host, port, certificateFile, privateKeyFile );
4063
4074
} else
4064
4075
#endif
4065
4076
{
4066
4077
if ( port == 0 )
4067
4078
port = DEFAULT_HTTP_PORT;
4068
- std::cerr << " Starting plain HTTP server on http://localhost :" << port << " /\n " ;
4069
- startHTTPServer ( port );
4079
+ std::cerr << " Starting plain HTTP server on http://" << hostString << " :" << port << " /\n " ;
4080
+ startHTTPServer ( host, port );
4070
4081
}
4071
4082
delete pcmInstance;
4072
4083
} else if ( pid > 0 ) {
0 commit comments