[farsight2/master] rawudp: Set the socklen to the right len per address family
Olivier Crête
olivier.crete at collabora.co.uk
Mon Aug 3 11:30:57 PDT 2009
---
tests/check/transmitter/stunalternd.c | 15 +++++++++++----
transmitters/rawudp/fs-rawudp-component.c | 19 +++++++++++++++++--
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/tests/check/transmitter/stunalternd.c b/tests/check/transmitter/stunalternd.c
index 19a8d95..80b119f 100644
--- a/tests/check/transmitter/stunalternd.c
+++ b/tests/check/transmitter/stunalternd.c
@@ -76,9 +76,11 @@ int listen_socket (int fam, int type, int proto, unsigned int port)
struct sockaddr_in6 in6;
struct sockaddr_storage storage;
} addr;
+ socklen_t socklen;
+
if (fd == -1)
{
- perror ("Error opening IP port");
+ perror ("Error creating socket");
return -1;
}
if (fd < 3)
@@ -91,16 +93,21 @@ int listen_socket (int fam, int type, int proto, unsigned int port)
{
case AF_INET:
addr.in.sin_port = htons (port);
+ socklen = sizeof (struct sockaddr_in);
break;
case AF_INET6:
addr.in6.sin6_port = htons (port);
+ socklen = sizeof (struct sockaddr_in6);
break;
+ default:
+ socklen = 0;
+ abort ();
}
- if (bind (fd, (struct sockaddr *)&addr, sizeof (addr)))
+ if (bind (fd, (struct sockaddr *)&addr, socklen))
{
- perror ("Error opening IP port");
+ perror ("Error binding to port");
goto error;
}
@@ -121,7 +128,7 @@ int listen_socket (int fam, int type, int proto, unsigned int port)
{
if (listen (fd, INT_MAX))
{
- perror ("Error opening IP port");
+ perror ("Error listening on port");
goto error;
}
}
diff --git a/transmitters/rawudp/fs-rawudp-component.c b/transmitters/rawudp/fs-rawudp-component.c
index 7338c61..a698e76 100644
--- a/transmitters/rawudp/fs-rawudp-component.c
+++ b/transmitters/rawudp/fs-rawudp-component.c
@@ -1236,11 +1236,26 @@ fs_rawudp_component_gather_local_candidates (FsRawUdpComponent *self,
static gboolean
fs_rawudp_component_send_stun_locked (FsRawUdpComponent *self, GError **error)
{
+ socklen_t socklen = 0;
+
+ switch (self->priv->stun_sockaddr.ss_family)
+ {
+ case AF_INET:
+ socklen = sizeof(struct sockaddr_in);
+ break;
+ case AF_INET6:
+ socklen = sizeof(struct sockaddr_in6);
+ break;
+ default:
+ g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
+ "Unknown address family for stun server");
+ return FALSE;
+ }
+
return fs_rawudp_transmitter_udpport_sendto (self->priv->udpport,
(gchar*) self->priv->stun_buffer,
stun_message_length (&self->priv->stun_message),
- (const struct sockaddr *)&self->priv->stun_sockaddr,
- sizeof (self->priv->stun_sockaddr), error);
+ (const struct sockaddr *)&self->priv->stun_sockaddr, socklen, error);
}
static gboolean
--
1.5.6.5
More information about the farsight-commits
mailing list