From: Jaroslav Kysela Date: Wed, 11 May 2016 18:48:13 +0000 (+0200) Subject: satip server: implement --satip_bindaddr X-Git-Tag: v4.2.1~540 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=93c01801ff8470da31ed88e1aad938376fce8795;p=thirdparty%2Ftvheadend.git satip server: implement --satip_bindaddr --- diff --git a/src/main.c b/src/main.c index 0248a716b..cb439f6ea 100644 --- a/src/main.c +++ b/src/main.c @@ -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+"); diff --git a/src/satip/server.c b/src/satip/server.c index fd41679b8..967cd2e9c 100644 --- a/src/satip/server.c +++ b/src/satip/server.c @@ -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); } diff --git a/src/satip/server.h b/src/satip/server.h index 6c36a80ee..0d5d02c9c 100644 --- a/src/satip/server.h +++ b/src/satip/server.h @@ -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); diff --git a/src/tcp.c b/src/tcp.c index abd595a8b..357b68cec 100644 --- 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 */ diff --git a/src/tcp.h b/src/tcp.h index cefb9ee24..1c4024055 100644 --- 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);