From ef8281b3a2a9a4f42b2ce2f77521cb98b42417dc Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Sat, 29 Aug 2015 15:12:32 +0200 Subject: [PATCH] recorder: support HTTP host:port for binding to specific interface --- ot-recorder.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ot-recorder.c b/ot-recorder.c index ca08cda..e37bab1 100644 --- a/ot-recorder.c +++ b/ot-recorder.c @@ -652,6 +652,7 @@ void usage(char *prog) printf(" --host -H MQTT host (localhost)\n"); printf(" --port -p MQTT port (1883)\n"); #ifdef HAVE_HTTP + printf(" --http-host HTTP addr to bind to (localhost)\n"); printf(" --http-port -A HTTP port (8083)\n"); printf(" --doc-root document root (./wdocs)\n"); #endif @@ -673,6 +674,7 @@ int main(int argc, char **argv) #ifdef HAVE_HTTP int http_port = 8083; char *doc_root = "./wdocs"; + char *http_host = "localhost"; #endif #ifdef HAVE_REDIS struct timeval timeout = { 1, 500000 }; // 1.5 seconds @@ -724,6 +726,7 @@ int main(int argc, char **argv) { "port", required_argument, 0, 'p'}, { "storage", required_argument, 0, 'S'}, #ifdef HAVE_HTTP + { "http-host", required_argument, 0, 3}, { "http-port", required_argument, 0, 'A'}, { "doc-root", required_argument, 0, 2}, #endif @@ -744,6 +747,9 @@ int main(int argc, char **argv) doc_root = strdup(optarg); /* FIXME: check if isdir() */ break; + case 3: /* no short char */ + http_host = strdup(optarg); + break; #endif case 'D': ud->skipdemo = FALSE; @@ -885,7 +891,11 @@ int main(int argc, char **argv) #ifdef HAVE_HTTP if (http_port) { - mg_set_option(udata.server, "listening_port", "127.0.0.1:8083"); + char address[BUFSIZ]; + + sprintf(address, "%s:%d", http_host, http_port); + + mg_set_option(udata.server, "listening_port", address); // mg_set_option(udata.server, "listening_port", "8090,ssl://8091:cert.pem"); // mg_set_option(udata.server, "ssl_certificate", "cert.pem");