Project

General

Profile

Actions

Bug #4692

closed

SAT>IP: Print external NAT ip and port

Added by Mono Polimorph over 7 years ago. Updated over 7 years ago.

Status:
Fixed
Priority:
Normal
Category:
SAT>IP
Target version:
-
Start date:
2017-10-26
Due date:
% Done:

100%

Estimated time:
Found in version:
last snapshot
Affected Versions:

Description

Hi,

After some weeks testing it, I publish here the last part of my patch for NAT support (it continues with #4617).

The remaining part it’s print the correct IP and PORT values when connecting over a NAT redirection. In this case, the used values need to be the external one. Furthermore, this patch fixes the NAT values not only with the PLAY command but too with the DESCRIBE cmd.

Some clients doesn’t interpret these values. However, some others check them and closes the connection when they aren’t correct.

So, please commit this patch!

diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c
index 7b366c8..a455628 100644
--- a/src/satip/rtsp.c
+++ b/src/satip/rtsp.c
@@ -92,6 +92,7 @@ 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";

 /*
  *
@@ -1322,9 +1323,9 @@ rtsp_process_describe(http_connection_t *hc)
   char *u = tvh_strdupa(hc->hc_url);
   session_t *rs;
   htsbuf_queue_t q;
-  char buf[96];
+  char buf[96], *used_ip = NULL;
   int r = HTTP_STATUS_BAD_REQUEST;
-  int stream, first = 1, valid;
+  int stream, first = 1, valid, used_port;

   htsbuf_queue_init(&q, 0);

@@ -1381,10 +1382,19 @@ rtsp_process_describe(http_connection_t *hc)
   http_arg_init(&args);
   if (hc->hc_session)
     http_arg_set(&args, "Session", hc->hc_session);
-  if (stream > 0)
-    snprintf(buf, sizeof(buf), "rtsp://%s/stream=%i", rtsp_ip, stream);
+  if (rtsp_nat_ip != NULL)
+    used_ip = (rtsp_nat_ip[0] == '*' || rtsp_nat_ip[0] == '\0')? any_ip : rtsp_nat_ip;
   else
-    snprintf(buf, sizeof(buf), "rtsp://%s", rtsp_ip);
+    used_ip = rtsp_ip;
+  used_port = (rtsp_nat_port <= 0) ? rtsp_port : rtsp_nat_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))
+    snprintf(buf, sizeof(buf), "rtsp://%s/stream=%i", used_ip, stream);
+  else if (used_port != 554)
+    snprintf(buf, sizeof(buf), "rtsp://%s:%d", used_ip, used_port);
+  else
+    snprintf(buf, sizeof(buf), "rtsp://%s", used_ip);
   http_arg_set(&args, "Content-Base", buf);
   http_send_begin(hc);
   http_send_header(hc, HTTP_STATUS_OK, "application/sdp", q.hq_size,
@@ -1408,8 +1418,8 @@ static int
 rtsp_process_play(http_connection_t *hc, int cmd)
 {
   session_t *rs;
-  int errcode = HTTP_STATUS_BAD_REQUEST, valid = 0, i, stream;
-  char buf[256], *u = tvh_strdupa(hc->hc_url);
+  int errcode = HTTP_STATUS_BAD_REQUEST, valid = 0, i, stream, used_port;
+  char buf[256], *u = tvh_strdupa(hc->hc_url), *used_ip = NULL;
   http_arg_list_t args;

   http_arg_init(&args);
@@ -1467,10 +1477,15 @@ 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 {
-    if (rtsp_port != 554)
-      snprintf(buf, sizeof(buf), "url=rtsp://%s:%d/stream=%d", rtsp_ip, rtsp_port, rs->stream);
+    if (rtsp_nat_ip != NULL)
+      used_ip = (rtsp_nat_ip[0] == '*' || rtsp_nat_ip[0] == '\0')? any_ip : rtsp_nat_ip;
+    else
+      used_ip = rtsp_ip;
+    used_port = (rtsp_nat_port <= 0) ? rtsp_port : rtsp_nat_port;
+    if (used_port != 554)
+      snprintf(buf, sizeof(buf), "url=rtsp://%s:%d/stream=%d", used_ip, used_port, rs->stream);
     else
-      snprintf(buf, sizeof(buf), "url=rtsp://%s/stream=%d", rtsp_ip, rs->stream);
+      snprintf(buf, sizeof(buf), "url=rtsp://%s/stream=%d", used_ip, rs->stream);
     http_arg_set(&args, "RTP-Info", buf);
   }

Regards and I'm sorry for posting a patch here instead of PR in GitHub!


Files

Actions

Also available in: Atom PDF