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,
{
CandidateDiscovery *cdisco;
Component *component = stream_find_component_by_id (stream, component_id);
NiceAddress local_address;
/* note: no need to check for redundant candidates, as this is
* done later on in the process */
......@@ -2008,6 +2009,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
return;
}
local_address = nicesock->addr;
nicesock = NULL;
/* TODO: add support for turn-tcp RFC 6062 */
......@@ -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_port (&proxy_server, agent->proxy_port);
nicesock = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server,
reliable_tcp);
&local_address, reliable_tcp);
if (nicesock) {
_priv_set_socket_tos (agent, nicesock, stream->tos);
......@@ -2035,7 +2037,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
}
if (nicesock == NULL) {
nicesock = nice_tcp_bsd_socket_new (agent->main_context, &turn->server,
reliable_tcp);
&local_address, reliable_tcp);
if (nicesock)
_priv_set_socket_tos (agent, nicesock, stream->tos);
......
......@@ -109,7 +109,8 @@ nice_tcp_bsd_socket_new_from_gsock (GMainContext *ctx, GSocket *gsock,
}
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 {
struct sockaddr_storage storage;
......@@ -120,7 +121,6 @@ nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *remote_addr, gboolean r
GError *gerr = NULL;
gboolean gret = FALSE;
GSocketAddress *gaddr;
NiceAddress local_addr;
if (remote_addr == NULL) {
/* 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
g_error_free (gerr);
}
gaddr = g_socket_get_local_address (gsock, NULL);
if (gaddr == NULL ||
!g_socket_address_to_native (gaddr, &name.addr, sizeof (name), NULL)) {
nice_address_copy_to_sockaddr (local_addr, &name.addr);
gaddr = g_socket_address_new_from_native (&name.addr, sizeof (name));
if (gaddr == NULL) {
g_socket_close (gsock, NULL);
g_object_unref (gsock);
return NULL;
}
g_socket_bind (gsock, gaddr, FALSE, NULL);
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);
g_object_unref (gsock);
......
......@@ -43,7 +43,8 @@ G_BEGIN_DECLS
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 *
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