Commit dd0904d4 authored by Jakub Adam's avatar Jakub Adam Committed by Olivier Crête

Set local address of TCP-BSD socket

parent 2f319ad9
...@@ -1949,6 +1949,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -1949,6 +1949,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
{ {
CandidateDiscovery *cdisco; CandidateDiscovery *cdisco;
Component *component = stream_find_component_by_id (stream, component_id); Component *component = stream_find_component_by_id (stream, component_id);
NiceAddress local_address;
/* note: no need to check for redundant candidates, as this is /* note: no need to check for redundant candidates, as this is
* done later on in the process */ * done later on in the process */
...@@ -2008,6 +2009,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -2008,6 +2009,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
return; return;
} }
local_address = nicesock->addr;
nicesock = NULL; nicesock = NULL;
/* TODO: add support for turn-tcp RFC 6062 */ /* TODO: add support for turn-tcp RFC 6062 */
...@@ -2016,7 +2018,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -2016,7 +2018,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
nice_address_set_from_string (&proxy_server, agent->proxy_ip)) { nice_address_set_from_string (&proxy_server, agent->proxy_ip)) {
nice_address_set_port (&proxy_server, agent->proxy_port); nice_address_set_port (&proxy_server, agent->proxy_port);
nicesock = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server, nicesock = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server,
reliable_tcp); &local_address, reliable_tcp);
if (nicesock) { if (nicesock) {
_priv_set_socket_tos (agent, nicesock, stream->tos); _priv_set_socket_tos (agent, nicesock, stream->tos);
...@@ -2035,7 +2037,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -2035,7 +2037,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
} }
if (nicesock == NULL) { if (nicesock == NULL) {
nicesock = nice_tcp_bsd_socket_new (agent->main_context, &turn->server, nicesock = nice_tcp_bsd_socket_new (agent->main_context, &turn->server,
reliable_tcp); &local_address, reliable_tcp);
if (nicesock) if (nicesock)
_priv_set_socket_tos (agent, nicesock, stream->tos); _priv_set_socket_tos (agent, nicesock, stream->tos);
......
...@@ -109,7 +109,8 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock, ...@@ -109,7 +109,8 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
} }
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, gboolean reliable) nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr,
NiceAddress *local_addr, gboolean reliable)
{ {
union { union {
struct sockaddr_storage storage; struct sockaddr_storage storage;
...@@ -120,7 +121,6 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, gboolean r ...@@ -120,7 +121,6 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, gboolean r
GError *gerr = NULL; GError *gerr = NULL;
gboolean gret = FALSE; gboolean gret = FALSE;
GSocketAddress *gaddr; GSocketAddress *gaddr;
NiceAddress local_addr;
if (remote_addr == NULL) { if (remote_addr == NULL) {
/* We can't connect a tcp socket with no destination address */ /* We can't connect a tcp socket with no destination address */
...@@ -172,18 +172,17 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, gboolean r ...@@ -172,18 +172,17 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, gboolean r
g_error_free (gerr); g_error_free (gerr);
} }
gaddr = g_socket_get_local_address (gsock, NULL); nice_address_copy_to_sockaddr (local_addr, &name.addr);
if (gaddr == NULL || gaddr = g_socket_address_new_from_native (&name.addr, sizeof (name));
!g_socket_address_to_native (gaddr, &name.addr, sizeof (name), NULL)) { if (gaddr == NULL) {
g_socket_close (gsock, NULL); g_socket_close (gsock, NULL);
g_object_unref (gsock); g_object_unref (gsock);
return NULL; return NULL;
} }
g_socket_bind (gsock, gaddr, FALSE, NULL);
g_object_unref (gaddr); g_object_unref (gaddr);
nice_address_set_from_sockaddr (&local_addr, &name.addr); sock = nice_tcp_bsd_socket_new_from_gsock (ctx, gsock, local_addr, remote_addr,
sock = nice_tcp_bsd_socket_new_from_gsock (ctx, gsock, &local_addr, remote_addr,
reliable); reliable);
g_object_unref (gsock); g_object_unref (gsock);
......
...@@ -43,7 +43,8 @@ G_BEGIN_DECLS ...@@ -43,7 +43,8 @@ G_BEGIN_DECLS
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, gboolean reliable); nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr,
NiceAddress *local_addr, gboolean reliable);
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock, nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment