]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
satip server: implement --satip_bindaddr
authorJaroslav Kysela <perex@perex.cz>
Wed, 11 May 2016 18:48:13 +0000 (20:48 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 11 May 2016 18:48:13 +0000 (20:48 +0200)
src/main.c
src/satip/server.c
src/satip/server.h
src/tcp.c
src/tcp.h

index 0248a716b6284ae4055acfc3475066f52c399a21..cb439f6eab263c68b8372e90038c9e5a9a5461ca 100644 (file)
@@ -787,7 +787,8 @@ main(int argc, char **argv)
 #endif
              *opt_bindaddr     = NULL,
              *opt_subscribe    = NULL,
-             *opt_user_agent   = NULL;
+             *opt_user_agent   = NULL,
+             *opt_satip_bindaddr = NULL;
   str_list_t  opt_satip_xml    = { .max = 10, .num = 0, .str = calloc(10, sizeof(char*)) };
   str_list_t  opt_tsfile       = { .max = 10, .num = 0, .str = calloc(10, sizeof(char*)) };
   cmdline_opt_t cmdline_opts[] = {
@@ -819,6 +820,8 @@ main(int argc, char **argv)
       OPT_STR, &opt_dvb_adapters },
 #endif
 #if ENABLE_SATIP_SERVER
+    {   0, "satip_bindaddr", N_("Specify bind address for SAT>IP server"),
+      OPT_STR, &opt_satip_bindaddr },
     {   0, "satip_rtsp", N_("SAT>IP RTSP port number for server\n"
                             "(default: -1 = disable, 0 = webconfig, standard port is 554)"),
       OPT_INT, &opt_satip_rtsp },
@@ -1059,7 +1062,7 @@ main(int argc, char **argv)
   tcp_server_preinit(opt_ipv6);
   http_server_init(opt_bindaddr);    // bind to ports only
   htsp_init(opt_bindaddr);          // bind to ports only
-  satip_server_init(opt_satip_rtsp); // bind to ports only
+  satip_server_init(opt_satip_bindaddr, opt_satip_rtsp); // bind to ports only
 
   if (opt_fork)
     pidfile = tvh_fopen(opt_pidpath, "w+");
index fd41679b8fcac0546eb76c5a66a9b7043588f3a5..967cd2e9c2ddc7d16535a062d4b826b3b3e2a645 100644 (file)
@@ -30,6 +30,7 @@ static char *http_server_ip;
 static int http_server_port;
 static int satip_server_deviceid;
 static time_t satip_server_bootid;
+static char *satip_server_bindaddr;
 static int satip_server_rtsp_port;
 static int satip_server_rtsp_port_locked;
 static upnp_service_t *satips_upnp_discovery;
@@ -526,12 +527,11 @@ static void satip_server_info(const char *prefix, int descramble, int muxcnf)
   int fe, findex;
   const char *ftype;
 
-  tvhinfo("satips", "SAT>IP Server %sinitialized "
-                    "(HTTP %s:%d, RTSP %s:%d, "
-                    "descramble %d, muxcnf %d)",
-              prefix,
+  tvhinfo("satips", "SAT>IP Server %sinitialized", prefix);
+  tvhinfo("satips", "  HTTP %s:%d, RTSP %s:%d",
               http_server_ip, http_server_port,
-              http_server_ip, satip_server_rtsp_port,
+              http_server_ip, satip_server_rtsp_port);
+  tvhinfo("satips", "  descramble %d, muxcnf %d",
               descramble, muxcnf);
   for (fe = 1; fe <= 128; fe++) {
     if (satip_rtsp_delsys(fe, &findex, &ftype) == DVB_TYPE_NONE)
@@ -751,12 +751,16 @@ static void satip_server_init_common(const char *prefix, int announce)
   char *nat_ip;
 
   if (http_server_ip == NULL) {
+    if (tcp_server_onall(http_server) && satip_server_bindaddr == NULL) {
+      tvherror("satips", "use --satip_bindaddr parameter to select the local IP for SAT>IP");
+      tvherror("satips", "using Google lookup (might block the task until timeout)");
+    }
     if (tcp_server_bound(http_server, &http, PF_INET) < 0) {
       tvherror("satips", "Unable to determine the HTTP/RTSP address");
       return;
     }
     tcp_get_str_from_ip((const struct sockaddr *)&http, http_ip, sizeof(http_ip));
-    http_server_ip = strdup(http_ip);
+    http_server_ip = strdup(satip_server_bindaddr ?: http_ip);
     http_server_port = ntohs(IP_PORT(http));
   }
 
@@ -810,7 +814,7 @@ static void satip_server_save(void)
  * Initialization
  */
 
-void satip_server_init(int rtsp_port)
+void satip_server_init(const char *bindaddr, int rtsp_port)
 {
   pthread_mutex_init(&satip_server_reinit, NULL);
 
@@ -820,6 +824,7 @@ void satip_server_init(int rtsp_port)
   satip_server_bootid = time(NULL);
   satip_server_conf.satip_deviceid = 1;
 
+  satip_server_bindaddr = bindaddr ? strdup(bindaddr) : NULL;
   satip_server_rtsp_port_locked = rtsp_port > 0;
   satip_server_rtsp_port = rtsp_port;
   satips_rtsp_port(rtsp_port);
@@ -891,4 +896,5 @@ void satip_server_done(void)
   http_server_ip = NULL;
   free(satip_server_conf.satip_uuid);
   satip_server_conf.satip_uuid = NULL;
+  free(satip_server_bindaddr);
 }
index 6c36a80ee77fa669a053722858e60e0efdfa4bae..0d5d02c9cc809a2770e97428448d28aafd88f7e8 100644 (file)
@@ -95,7 +95,7 @@ int satip_server_http_page(http_connection_t *hc,
 
 int satip_server_match_uuid(const char *uuid);
 
-void satip_server_init(int rtsp_port);
+void satip_server_init(const char *bindaddr, int rtsp_port);
 void satip_server_register(void);
 void satip_server_done(void);
 
index abd595a8b0ccf51a580e9360066dd291705d1327..357b68cec28b792b1a18df1956edafb67e16d78c 100644 (file)
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -1030,6 +1030,26 @@ tcp_server_bound ( void *server, struct sockaddr_storage *bound, int family )
   return 0;
 }
 
+/**
+ *
+ */
+int
+tcp_server_onall ( void *server )
+{
+  tcp_server_t *ts = server;
+  int i, len;
+  uint8_t *ptr;
+
+  if (server == NULL) return 0;
+
+  len = IP_IN_ADDRLEN(ts->bound);
+  ptr = (uint8_t *)IP_IN_ADDR(ts->bound);
+  for (i = 0; i < len; i++)
+    if (ptr[0])
+      break;
+  return i >= len;
+}
+
 /*
  * Connections status
  */
index cefb9ee24629be097d9e590024d4fe1eba5c5532..1c4024055ac96692659f0e05e4efc3e029b6b108 100644 (file)
--- a/src/tcp.h
+++ b/src/tcp.h
@@ -79,6 +79,8 @@ int tcp_default_ip_addr(struct sockaddr_storage *deflt, int family);
 
 int tcp_server_bound(void *server, struct sockaddr_storage *bound, int family);
 
+int tcp_server_onall(void *server);
+
 int tcp_read(int fd, void *buf, size_t len);
 
 char *tcp_read_line(int fd, htsbuf_queue_t *spill);