]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
SAT>IP server: cleanups for addr/port send to clients (NAT)
authorJaroslav Kysela <perex@perex.cz>
Tue, 21 Nov 2017 10:02:17 +0000 (11:02 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 21 Nov 2017 10:02:17 +0000 (11:02 +0100)
src/satip/rtsp.c

index 5de4fdedbbdeb2f28049072e6d06c43fc7ce164e..6672df2a2e6ae7ad955939e6ab33067acd63a49e 100644 (file)
@@ -92,8 +92,6 @@ static pthread_mutex_t rtsp_lock;
 static void rtsp_close_session(session_t *rs);
 static void rtsp_free_session(session_t *rs);
 
-static char any_ip[] = "127.0.0.1\0";
-
 /*
  *
  */
@@ -317,41 +315,32 @@ rtsp_parse_args(http_connection_t *hc, char *u)
   return stream;
 }
 
-/*
- *
- */
-static inline int
-rtsp_announced_port(struct sockaddr_storage *peer, struct sockaddr_storage *self)
-{
-  int used_port = 0;
-
-  if (satip_server_conf.satip_nat_name_force || !ip_check_is_local_address(peer,self)) {
-    used_port = (rtsp_nat_port > 0)? rtsp_nat_port : rtsp_port;
-  } else {
-    used_port = rtsp_port;
-  }
-
-  return used_port;
-}
-
 /*
  *
  */
 static inline char *
-rtsp_announced_ip(struct sockaddr_storage *peer, struct sockaddr_storage *self)
+rtsp_conn_ip(http_connection_t *hc, char *buf, size_t buflen, int *port)
 {
-  char *used_ip;
-
-  if (satip_server_conf.satip_nat_name_force || !ip_check_is_local_address(peer,self)) {
+  char *used_ip = rtsp_ip;
+  int used_port = rtsp_port;
+
+  if (rtsp_nat_ip[0] == '\0')
+    return rtsp_ip;
+  used_ip = rtsp_ip;
+  used_port = rtsp_port;
+  if (satip_server_conf.satip_nat_name_force ||
+      !ip_check_is_local_address(hc->hc_peer, hc->hc_self)) {
     used_ip = rtsp_nat_ip;
-  } else {
-    used_ip = rtsp_ip;
+    if (rtsp_nat_port > 0)
+      used_port = rtsp_nat_port;
   }
 
   if (used_ip[0] == '*' || used_ip[0] == '\0' || used_ip == NULL) {
-    used_ip = any_ip;
+    tcp_get_str_from_ip(hc->hc_self, buf, buflen);
+    used_ip = buf;
   }
 
+  *port = used_port;
   return used_ip;
 }
 
@@ -1361,7 +1350,7 @@ rtsp_process_describe(http_connection_t *hc)
   char *u = tvh_strdupa(hc->hc_url);
   session_t *rs;
   htsbuf_queue_t q;
-  char buf[96], *used_ip = NULL;
+  char buf[96], buf1[46], *used_ip = NULL;
   int r = HTTP_STATUS_BAD_REQUEST;
   int stream, first = 1, valid, used_port;
 
@@ -1420,8 +1409,7 @@ rtsp_process_describe(http_connection_t *hc)
   http_arg_init(&args);
   if (hc->hc_session)
     http_arg_set(&args, "Session", hc->hc_session);
-  used_port = rtsp_announced_port(hc->hc_peer,hc->hc_self);
-  used_ip = rtsp_announced_ip(hc->hc_peer,hc->hc_self);
+  used_ip = rtsp_conn_ip(hc, buf1, sizeof(buf1), &used_port);
   if ((stream > 0) && (used_port != 554))
     snprintf(buf, sizeof(buf), "rtsp://%s:%d/stream=%i", used_ip, used_port, stream);
   else if ((stream > 0) && (used_port == 554))
@@ -1454,7 +1442,7 @@ rtsp_process_play(http_connection_t *hc, int cmd)
 {
   session_t *rs;
   int errcode = HTTP_STATUS_BAD_REQUEST, valid = 0, i, stream, used_port;
-  char buf[256], *u = tvh_strdupa(hc->hc_url), *used_ip = NULL;
+  char buf[256], buf1[46], *u = tvh_strdupa(hc->hc_url), *used_ip = NULL;
   http_arg_list_t args;
 
   http_arg_init(&args);
@@ -1512,8 +1500,7 @@ rtsp_process_play(http_connection_t *hc, int cmd)
     snprintf(buf, sizeof(buf), "%d", rs->stream);
     http_arg_set(&args, "com.ses.streamID", buf);
   } else {
-    used_port = rtsp_announced_port(hc->hc_peer,hc->hc_self);
-    used_ip = rtsp_announced_ip(hc->hc_peer,hc->hc_self);
+    used_ip = rtsp_conn_ip(hc, buf1, sizeof(buf1), &used_port);
     if (used_port != 554)
       snprintf(buf, sizeof(buf), "url=rtsp://%s:%d/stream=%d", used_ip, used_port, rs->stream);
     else