changeset 5798:2af44abfbfe8 libavformat

RTSP: Resolve and use the actual IP address of the peer we're connected to, instead of using the original host name, since the RTP (and UDP) protocols may choose another IP address if the host name resolves into several different addresses.
author mstorsjo
date Tue, 09 Mar 2010 14:59:40 +0000
parents e0e1ddbfca1a
children 821155aecf2a
files rtsp.c
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rtsp.c	Tue Mar 09 12:37:13 2010 +0000
+++ b/rtsp.c	Tue Mar 09 14:59:40 2010 +0000
@@ -1381,10 +1381,12 @@
     char host[1024], path[1024], tcpname[1024], cmd[2048], auth[128];
     char *option_list, *option, *filename;
     URLContext *rtsp_hd;
-    int port, err;
+    int port, err, tcp_fd;
     RTSPMessageHeader reply1, *reply = &reply1;
     int lower_transport_mask = 0;
     char real_challenge[64];
+    struct sockaddr_storage peer;
+    socklen_t peer_len = sizeof(peer);
 
     if (!ff_network_init())
         return AVERROR(EIO);
@@ -1455,6 +1457,12 @@
     rt->rtsp_hd = rtsp_hd;
     rt->seq = 0;
 
+    tcp_fd = url_get_file_handle(rtsp_hd);
+    if (!getpeername(tcp_fd, (struct sockaddr*) &peer, &peer_len)) {
+        getnameinfo((struct sockaddr*) &peer, peer_len, host, sizeof(host),
+                    NULL, 0, NI_NUMERICHOST);
+    }
+
     /* request options supported by the server; this also detects server
      * type */
     av_strlcpy(rt->control_uri, s->filename,