Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
satip server: implement --satip_bindaddr
  • Loading branch information
perexg committed May 11, 2016
1 parent 02ac9c9 commit 93c0180
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/main.c
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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+");
Expand Down
20 changes: 13 additions & 7 deletions src/satip/server.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/satip/server.h
Expand Up @@ -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);

Expand Down
20 changes: 20 additions & 0 deletions src/tcp.c
Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions src/tcp.h
Expand Up @@ -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);
Expand Down

0 comments on commit 93c0180

Please sign in to comment.