summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorAzat Khuzhin <azat@libevent.org>2020-10-27 01:22:59 +0300
committerAzat Khuzhin <azat@libevent.org>2020-10-27 01:23:33 +0300
commiteb822ac751dd2559b9ea3a04ec4978fe2733f6ce (patch)
treeb90906fb9059bf2484c0a6ccad0bf33d920089d7 /sample
parent6135248a0cf4610ce4dbcbc1f7f4c1d53c3e170c (diff)
downloadlibevent-eb822ac751dd2559b9ea3a04ec4978fe2733f6ce.tar.gz
http-server: add -H option to change listen address
Diffstat (limited to 'sample')
-rw-r--r--sample/http-server.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/sample/http-server.c b/sample/http-server.c
index cf928437..b006891e 100644
--- a/sample/http-server.c
+++ b/sample/http-server.c
@@ -107,6 +107,7 @@ struct options {
int unlink;
const char *unixsock;
+ const char *bind;
const char *docroot;
};
@@ -351,6 +352,7 @@ print_usage(FILE *out, const char *prog, int exit_code)
"Syntax: %s [ OPTS ] <docroot>\n"
" -p - port\n"
" -U - bind to unix socket\n"
+ " -H - address to bind (default: 0.0.0.0)\n"
" -u - unlink unix socket before bind\n"
" -I - IOCP\n"
" -m - max body size\n"
@@ -365,7 +367,7 @@ parse_opts(int argc, char **argv)
memset(&o, 0, sizeof(o));
- while ((opt = getopt(argc, argv, "hp:U:m:uIv")) != -1) {
+ while ((opt = getopt(argc, argv, "hp:U:m:uIvH:")) != -1) {
switch (opt) {
case 'p': o.port = atoi(optarg); break;
case 'U': o.unixsock = optarg; break;
@@ -373,6 +375,7 @@ parse_opts(int argc, char **argv)
case 'I': o.iocp = 1; break;
case 'm': o.max_body_size = atoi(optarg); break;
case 'v': ++o.verbose; break;
+ case 'H': o.bind = optarg; break;
case 'h': print_usage(stdout, argv[0], 0); break;
default : fprintf(stderr, "Unknown option %c\n", opt); break;
}
@@ -548,9 +551,9 @@ main(int argc, char **argv)
#endif /* EVENT__HAVE_STRUCT_SOCKADDR_UN */
}
else {
- handle = evhttp_bind_socket_with_handle(http, "0.0.0.0", o.port);
+ handle = evhttp_bind_socket_with_handle(http, o.bind, o.port);
if (!handle) {
- fprintf(stderr, "couldn't bind to port %d. Exiting.\n", o.port);
+ fprintf(stderr, "couldn't bind to %s:%d. Exiting.\n", o.bind, o.port);
ret = 1;
goto err;
}