]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Allow binding address to be specified via --bindaddr flag. 247/head
authorArchie L. Cobbs <archie@dellroad.org>
Sat, 16 Feb 2013 22:01:34 +0000 (16:01 -0600)
committerArchie L. Cobbs <archie@dellroad.org>
Sat, 16 Feb 2013 22:01:34 +0000 (16:01 -0600)
man/tvheadend.1
src/htsp_server.c
src/htsp_server.h
src/http.c
src/http.h
src/main.c
src/tcp.c
src/tcp.h

index 47fb3c5aabaca51ec6e17be342a6dca370ad53bc..7b1e03f3c4982aa002fd8a04c64e19069d36afd8 100644 (file)
@@ -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
index ad7bb1a3c72db2083dd5cfc1d01358628afe2639..7e5d8c0d2ba70cd88d54c3601df0d9b37652143c 100644 (file)
@@ -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);
 }
 
 /* **************************************************************************
index a82cca12b3c723c91cc7c6bcaeae7b71ce408efe..77002cac284af76f78e271132a380608983e4230 100644 (file)
@@ -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);
 
index c668a02f42b25c95bb0d1ac76eedfadfbd936075..98562d74149d90de002f5be4eb0f907a581d4b62 100644 (file)
@@ -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);
 }
index 9e3d061c0413fd7c5cbe36b8721c4e63805e58c1..08878b465ba044a5b1948682e802b982ed5d776b 100644 (file)
@@ -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);
 
index 33db93b746ee6e1cdd1002b4e8b9952937786c67..e163e0296e150341a24c75c0c1f40aac0a8994b2 100644 (file)
@@ -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);
index 5ccf1bacef45a9ac6e1c7bca55d7767c4543d370..0a9dbd7a59b645b67ae006e90464f20656c1b4e9 100644 (file)
--- a/src/tcp.c
+++ b/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;
   }
index 0c061e435506a08c3fb7ea3ba593aac9e6fc5384..98649f0bea161cf1df03b353d3dc39bf3323a95d 100644 (file)
--- a/src/tcp.h
+++ b/src/tcp.h
@@ -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);