Allow binding address to be specified via --bindaddr flag.
This commit is contained in:
parent
c338802902
commit
a3fdc6f120
8 changed files with 25 additions and 13 deletions
|
@ -13,6 +13,10 @@ Media player.
|
|||
.SH OPTIONS
|
||||
All arguments are optional.
|
||||
.TP
|
||||
\fB\-b\fR \fIaddress\fR, \fB\-\-bindaddr\fR \fIaddress\fR
|
||||
Specify an interface IP address on which incoming HTTP and HTSP connections
|
||||
will be accepted. By default, connections are accepted on all interfaces.
|
||||
.TP
|
||||
\fB\-f
|
||||
Fork and become a background process (deamon). Default no.
|
||||
.TP
|
||||
|
|
|
@ -1966,12 +1966,12 @@ htsp_serve(int fd, void *opaque, struct sockaddr_storage *source,
|
|||
* Fire up HTSP server
|
||||
*/
|
||||
void
|
||||
htsp_init(void)
|
||||
htsp_init(const char *bindaddr)
|
||||
{
|
||||
extern int tvheadend_htsp_port_extra;
|
||||
htsp_server = tcp_server_create(tvheadend_htsp_port, htsp_serve, NULL);
|
||||
htsp_server = tcp_server_create(bindaddr, tvheadend_htsp_port, htsp_serve, NULL);
|
||||
if(tvheadend_htsp_port_extra)
|
||||
htsp_server_2 = tcp_server_create(tvheadend_htsp_port_extra, htsp_serve, NULL);
|
||||
htsp_server_2 = tcp_server_create(bindaddr, tvheadend_htsp_port_extra, htsp_serve, NULL);
|
||||
}
|
||||
|
||||
/* **************************************************************************
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "epg.h"
|
||||
#include "dvr/dvr.h"
|
||||
|
||||
void htsp_init(void);
|
||||
void htsp_init(const char *bindaddr);
|
||||
|
||||
void htsp_channel_update_current(channel_t *ch);
|
||||
|
||||
|
|
|
@ -816,7 +816,7 @@ http_serve(int fd, void *opaque, struct sockaddr_storage *peer,
|
|||
* Fire up HTTP server
|
||||
*/
|
||||
void
|
||||
http_server_init(void)
|
||||
http_server_init(const char *bindaddr)
|
||||
{
|
||||
http_server = tcp_server_create(tvheadend_webui_port, http_serve, NULL);
|
||||
http_server = tcp_server_create(bindaddr, tvheadend_webui_port, http_serve, NULL);
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ http_path_t *http_path_add(const char *path, void *opaque,
|
|||
|
||||
|
||||
|
||||
void http_server_init(void);
|
||||
void http_server_init(const char *bindaddr);
|
||||
|
||||
int http_access_verify(http_connection_t *hc, int mask);
|
||||
|
||||
|
|
|
@ -376,6 +376,7 @@ main(int argc, char **argv)
|
|||
*opt_dvb_raw = NULL,
|
||||
#endif
|
||||
*opt_rawts = NULL,
|
||||
*opt_bindaddr = NULL,
|
||||
*opt_subscribe = NULL;
|
||||
cmdline_opt_t cmdline_opts[] = {
|
||||
{ 0, NULL, "Generic Options", OPT_BOOL, NULL },
|
||||
|
@ -383,6 +384,7 @@ main(int argc, char **argv)
|
|||
{ 'v', "version", "Show version infomation", OPT_BOOL, &opt_version },
|
||||
|
||||
{ 0, NULL, "Service Configuration", OPT_BOOL, NULL },
|
||||
{ 'b', "bindaddr", "Specify bind address", OPT_STR, &opt_bindaddr},
|
||||
{ 'c', "config", "Alternate config path", OPT_STR, &opt_config },
|
||||
{ 'f', "fork", "Fork and run as daemon", OPT_BOOL, &opt_fork },
|
||||
{ 'u', "user", "Run as user", OPT_STR, &opt_user },
|
||||
|
@ -625,7 +627,7 @@ main(int argc, char **argv)
|
|||
#endif
|
||||
|
||||
tcp_server_init(opt_ipv6);
|
||||
http_server_init();
|
||||
http_server_init(opt_bindaddr);
|
||||
webui_init();
|
||||
|
||||
serviceprobe_init();
|
||||
|
@ -643,7 +645,7 @@ main(int argc, char **argv)
|
|||
|
||||
dvr_init();
|
||||
|
||||
htsp_init();
|
||||
htsp_init(opt_bindaddr);
|
||||
|
||||
if(opt_rawts != NULL)
|
||||
rawts_init(opt_rawts);
|
||||
|
|
12
src/tcp.c
12
src/tcp.c
|
@ -499,7 +499,7 @@ tcp_server_loop(void *aux)
|
|||
*
|
||||
*/
|
||||
void *
|
||||
tcp_server_create(int port, tcp_server_callback_t *start, void *opaque)
|
||||
tcp_server_create(const char *bindaddr, int port, tcp_server_callback_t *start, void *opaque)
|
||||
{
|
||||
int fd, x;
|
||||
struct epoll_event e;
|
||||
|
@ -515,14 +515,19 @@ tcp_server_create(int port, tcp_server_callback_t *start, void *opaque)
|
|||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
if (bindaddr != NULL)
|
||||
hints.ai_flags |= AI_NUMERICHOST;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
x = getaddrinfo(NULL, portBuf, &hints, &res);
|
||||
x = getaddrinfo(bindaddr, portBuf, &hints, &res);
|
||||
free(portBuf);
|
||||
|
||||
if(x != 0)
|
||||
if(x != 0) {
|
||||
fprintf(stderr, "getaddrinfo: %s: %s", bindaddr != NULL ? bindaddr : "*",
|
||||
x == EAI_SYSTEM ? strerror(errno) : gai_strerror(x));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ressave = res;
|
||||
while(res)
|
||||
|
@ -553,6 +558,7 @@ tcp_server_create(int port, tcp_server_callback_t *start, void *opaque)
|
|||
|
||||
if(x != 0)
|
||||
{
|
||||
fprintf(stderr, "bind: %s: %s", bindaddr != NULL ? bindaddr : "*", strerror(errno));
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ typedef void (tcp_server_callback_t)(int fd, void *opaque,
|
|||
struct sockaddr_storage *peer,
|
||||
struct sockaddr_storage *self);
|
||||
|
||||
void *tcp_server_create(int port, tcp_server_callback_t *start, void *opaque);
|
||||
void *tcp_server_create(const char *bindaddr, int port, tcp_server_callback_t *start, void *opaque);
|
||||
|
||||
int tcp_read(int fd, void *buf, size_t len);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue