From 4826ec4e4d40dd3c793d3dda9d0aedb9b4c39d46 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 4 Apr 2013 12:16:47 +0200 Subject: rtsp: calculate the local ip address in accept Calculate the local IP address in the accept call. We need to place this IP address in the GET reply in the X-Server-IP-Address header so that the client knows where to send the POST to in case of tunneled RTSP. Before this patch it used the client IP address, which would make the client send the POST request to itself and fail. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=697092 --- gst-libs/gst/rtsp/gstrtspconnection.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/gst-libs/gst/rtsp/gstrtspconnection.c b/gst-libs/gst/rtsp/gstrtspconnection.c index 84d79b5f0..2214fff38 100644 --- a/gst-libs/gst/rtsp/gstrtspconnection.c +++ b/gst-libs/gst/rtsp/gstrtspconnection.c @@ -246,6 +246,9 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip, GstRTSPConnection *newconn = NULL; GstRTSPUrl *url; GstRTSPResult res; + GSocketAddress *addr; + GError *err = NULL; + gchar *localip; g_return_val_if_fail (G_IS_SOCKET (socket), GST_RTSP_EINVAL); g_return_val_if_fail (ip != NULL, GST_RTSP_EINVAL); @@ -254,6 +257,15 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip, /* set to non-blocking mode so that we can cancel the communication */ g_socket_set_blocking (socket, FALSE); + /* get local address */ + addr = g_socket_get_local_address (socket, &err); + if (!addr) + goto getnameinfo_failed; + + localip = g_inet_address_to_string (g_inet_socket_address_get_address + (G_INET_SOCKET_ADDRESS (addr))); + g_object_unref (addr); + /* create a url for the client address */ url = g_new0 (GstRTSPUrl, 1); url->host = g_strdup (ip); @@ -267,9 +279,7 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip, newconn->socket0 = G_SOCKET (g_object_ref (socket)); newconn->socket1 = G_SOCKET (g_object_ref (socket)); newconn->write_socket = newconn->read_socket = newconn->socket0; - - newconn->ip = g_strdup (ip); - + newconn->ip = localip; newconn->initial_buffer = g_strdup (initial_buffer); *conn = newconn; @@ -277,8 +287,16 @@ gst_rtsp_connection_create_from_socket (GSocket * socket, const gchar * ip, return GST_RTSP_OK; /* ERRORS */ +getnameinfo_failed: + { + GST_ERROR ("failed to get local address: %s", err->message); + g_clear_error (&err); + return GST_RTSP_ERROR; + } newconn_failed: { + GST_ERROR ("failed to make connection"); + g_free (localip); gst_rtsp_url_free (url); return res; } -- cgit v1.2.3