summaryrefslogtreecommitdiff
path: root/socket
diff options
context:
space:
mode:
authorJakub Adam <jakub.adam@ktknet.cz>2014-04-24 13:12:26 +0200
committerOlivier CrĂȘte <olivier.crete@collabora.com>2014-05-17 00:22:36 -0400
commitdd0904d4a52e7bb66be01efb63465bd79abff0af (patch)
treea798868e205f6d0954ecdb605a2a037a4c06442e /socket
parent2f319ad9876287c0ea1c14b4e118e7aa5b206801 (diff)
downloadlibnice-dd0904d4a52e7bb66be01efb63465bd79abff0af.tar.gz
Set local address of TCP-BSD socket
Diffstat (limited to 'socket')
-rw-r--r--socket/tcp-bsd.c15
-rw-r--r--socket/tcp-bsd.h3
2 files changed, 9 insertions, 9 deletions
diff --git a/socket/tcp-bsd.c b/socket/tcp-bsd.c
index fac2419..45ba714 100644
--- a/socket/tcp-bsd.c
+++ b/socket/tcp-bsd.c
@@ -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);
diff --git a/socket/tcp-bsd.h b/socket/tcp-bsd.h
index f206c9a..6b1bb53 100644
--- a/socket/tcp-bsd.h
+++ b/socket/tcp-bsd.h
@@ -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,