Skip to content

Commit 69561a9

Browse files
committed
blink1-tiny-server: fixed host arg
1 parent 41a7f18 commit 69561a9

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

server/blink1-tiny-server.c

+9-12
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ const char* blink1_server_version = BLINK1_VERSION;
4040

4141
static bool show_html = true;
4242

43-
static char http_listen_host[120] = "localhost";
43+
static char http_listen_host[120] = "localhost"; // or 0.0.0.0 for any
4444
static int http_listen_port = 8000;
45-
static char http_listen_address[100]; // will be "http://localhost:8000"
45+
static char http_listen_url[100]; // will be "http://localhost:8000"
4646

4747
typedef struct cache_info_ {
4848
blink1_device* dev; // device, if opened, NULL otherwise
@@ -87,12 +87,12 @@ void usage()
8787
" %s [options]\n"
8888
"where [options] can be:\n"
8989
" --port port, -p port port to listen on (default %d)\n"
90-
" --baseurl url, -U url set baseurl to listen in (default http://%s:%d)\n"
90+
" --host host, -H host host to listen on ('127.0.0.1' or '0.0.0.0')\n"
9191
" --no-html do not serve static HTML help\n"
9292
" --version version of this program\n"
9393
" --help, -h this help page\n"
9494
"\n",
95-
blink1_server_name, http_listen_port, http_listen_host, http_listen_port);
95+
blink1_server_name, http_listen_port);
9696

9797
fprintf(stderr,
9898
"Supported URIs:\n");
@@ -542,11 +542,11 @@ int main(int argc, char *argv[]) {
542542

543543
// parse options
544544
int option_index = 0, opt;
545-
char* opt_str = "qvhp:U:A:";
545+
char* opt_str = "qvhp:H:U:A:";
546546
static struct option loptions[] = {
547547
//{"verbose", optional_argument, 0, 'v'},
548548
//{"quiet", optional_argument, 0, 'q'},
549-
{"baseurl", required_argument, 0, 'U'},
549+
//{"baseurl", required_argument, 0, 'U'},
550550
{"host", required_argument, 0, 'H'},
551551
{"port", required_argument, 0, 'p'},
552552
{"no-html", no_argument, 0, 'N'},
@@ -572,9 +572,6 @@ int main(int argc, char *argv[]) {
572572
case 'N':
573573
show_html = false;
574574
break;
575-
case 'U':
576-
strncpy(http_listen_address, optarg, sizeof(http_listen_address));
577-
break;
578575
case 'H':
579576
strncpy(http_listen_host, optarg, sizeof(http_listen_host));
580577
break;
@@ -606,7 +603,7 @@ int main(int argc, char *argv[]) {
606603
blink1_server_name, blink1_server_version, http_listen_host,
607604
http_listen_port, (show_html) ? "html help enabeld": "no html help");
608605

609-
snprintf(http_listen_address, sizeof(http_listen_address), "http://%s:%d/",
606+
snprintf(http_listen_url, sizeof(http_listen_url), "http://%s:%d/",
610607
http_listen_host, http_listen_port);
611608

612609
// if( s_http_server_opts.document_root ) {
@@ -621,8 +618,8 @@ int main(int argc, char *argv[]) {
621618

622619
mg_mgr_init(&mgr);
623620

624-
if ((c = mg_http_listen(&mgr, http_listen_address, ev_handler, &mgr)) == NULL) {
625-
LOG(LL_ERROR, ("Cannot listen on %s. http_listen_address", http_listen_address));
621+
if ((c = mg_http_listen(&mgr, http_listen_url, ev_handler, &mgr)) == NULL) {
622+
LOG(LL_ERROR, ("Cannot listen on %s.", http_listen_url));
626623
exit(EXIT_FAILURE);
627624
}
628625

0 commit comments

Comments
 (0)