From e82080a5f62991e2892b88dce108537f64960e55 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 7 Nov 2013 11:00:19 +0100 Subject: [BB#63] conf: Allow multiple Listen statements in the config. This introduces a list (vector) of addresses instead of having just one address string. Signed-off-by: Michael Adam --- src/child.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/child.c') diff --git a/src/child.c b/src/child.c index c7490fd..01ef178 100644 --- a/src/child.c +++ b/src/child.c @@ -522,9 +522,16 @@ void child_kill_children (int sig) } } -int child_listening_sock (const char *addr, uint16_t port) + +/** + * Listen on the various configured interfaces + */ +int child_listening_sockets(vector_t listen_addrs, uint16_t port) { int ret; + ssize_t i; + + assert (port > 0); if (listen_fds == NULL) { listen_fds = vector_create(); @@ -535,8 +542,34 @@ int child_listening_sock (const char *addr, uint16_t port) } } - ret = listen_sock (addr, port, listen_fds); - return ret; + if ((listen_addrs == NULL) || + (vector_length(config.listen_addrs) == 0)) + { + /* + * no Listen directive: + * listen on the wildcard address(es) + */ + ret = listen_sock(NULL, port, listen_fds); + return ret; + } + + for (i = 0; i < vector_length(config.listen_addrs); i++) { + const char *addr; + + addr = (char *)vector_getentry(config.listen_addrs, i, NULL); + if (addr == NULL) { + log_message(LOG_WARNING, + "got NULL from listen_addrs - skipping"); + continue; + } + + ret = listen_sock(addr, port, listen_fds); + if (ret != 0) { + return ret; + } + } + + return 0; } void child_close_sock (void) -- cgit v1.2.3