Commit 972eb35f authored by Olivier Crête's avatar Olivier Crête

stun: Use struct sockaddr_storage * for any pointer that we write to

Some platforms have a larger alignment requirement for struct sockaddr_* than
for plain struct sockaddr, in that case, we need to make sure that the incoming pointer
has the right alignement before taking it in.
parent 23545569
...@@ -2124,7 +2124,7 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, Stream * ...@@ -2124,7 +2124,7 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, Stream *
if (memcmp (discovery_id, response_id, sizeof(StunTransactionId)) == 0) { if (memcmp (discovery_id, response_id, sizeof(StunTransactionId)) == 0) {
res = stun_usage_ice_conncheck_process (resp, res = stun_usage_ice_conncheck_process (resp,
&sockaddr.addr, &socklen, &sockaddr.storage, &socklen,
agent_to_ice_compatibility (agent)); agent_to_ice_compatibility (agent));
nice_debug ("Agent %p : stun_bind_process/conncheck for %p res %d " nice_debug ("Agent %p : stun_bind_process/conncheck for %p res %d "
"(controlling=%d).", agent, p, (int)res, agent->controlling_mode); "(controlling=%d).", agent, p, (int)res, agent->controlling_mode);
...@@ -2175,7 +2175,7 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, Stream * ...@@ -2175,7 +2175,7 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, Stream *
" conncheck %p SUCCEEDED.", agent, p); " conncheck %p SUCCEEDED.", agent, p);
priv_conn_check_unfreeze_related (agent, stream, p); priv_conn_check_unfreeze_related (agent, stream, p);
} else { } else {
ok_pair = priv_process_response_check_for_peer_reflexive(agent, ok_pair = priv_process_response_check_for_peer_reflexive (agent,
stream, component, p, sockptr, &sockaddr.addr, stream, component, p, sockptr, &sockaddr.addr,
local_candidate, remote_candidate); local_candidate, remote_candidate);
} }
...@@ -2265,8 +2265,8 @@ static gboolean priv_map_reply_to_discovery_request (NiceAgent *agent, StunMessa ...@@ -2265,8 +2265,8 @@ static gboolean priv_map_reply_to_discovery_request (NiceAgent *agent, StunMessa
stun_message_id (&d->stun_message, discovery_id); stun_message_id (&d->stun_message, discovery_id);
if (memcmp (discovery_id, response_id, sizeof(StunTransactionId)) == 0) { if (memcmp (discovery_id, response_id, sizeof(StunTransactionId)) == 0) {
res = stun_usage_bind_process (resp, &sockaddr.addr, res = stun_usage_bind_process (resp, &sockaddr.storage,
&socklen, &alternate.addr, &alternatelen); &socklen, &alternate.storage, &alternatelen);
nice_debug ("Agent %p : stun_bind_process/disc for %p res %d.", nice_debug ("Agent %p : stun_bind_process/disc for %p res %d.",
agent, d, (int)res); agent, d, (int)res);
...@@ -2395,9 +2395,9 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage * ...@@ -2395,9 +2395,9 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
if (memcmp (discovery_id, response_id, sizeof(StunTransactionId)) == 0) { if (memcmp (discovery_id, response_id, sizeof(StunTransactionId)) == 0) {
res = stun_usage_turn_process (resp, res = stun_usage_turn_process (resp,
&relayaddr.addr, &relayaddrlen, &relayaddr.storage, &relayaddrlen,
&sockaddr.addr, &socklen, &sockaddr.storage, &socklen,
&alternate.addr, &alternatelen, &alternate.storage, &alternatelen,
&bandwidth, &lifetime, agent_to_turn_compatibility (agent)); &bandwidth, &lifetime, agent_to_turn_compatibility (agent));
nice_debug ("Agent %p : stun_turn_process/disc for %p res %d.", nice_debug ("Agent %p : stun_turn_process/disc for %p res %d.",
agent, d, (int)res); agent, d, (int)res);
...@@ -2956,7 +2956,7 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -2956,7 +2956,7 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
rbuf_len = sizeof (rbuf); rbuf_len = sizeof (rbuf);
res = stun_usage_ice_conncheck_create_reply (&agent->stun_agent, &req, res = stun_usage_ice_conncheck_create_reply (&agent->stun_agent, &req,
&msg, rbuf, &rbuf_len, &sockaddr.addr, sizeof (sockaddr), &msg, rbuf, &rbuf_len, &sockaddr.storage, sizeof (sockaddr),
&control, agent->tie_breaker, &control, agent->tie_breaker,
agent_to_ice_compatibility (agent)); agent_to_ice_compatibility (agent));
......
...@@ -642,7 +642,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to, ...@@ -642,7 +642,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
buffer, sizeof(buffer), STUN_IND_SEND)) buffer, sizeof(buffer), STUN_IND_SEND))
goto send; goto send;
if (stun_message_append_xor_addr (&msg, STUN_ATTRIBUTE_PEER_ADDRESS, if (stun_message_append_xor_addr (&msg, STUN_ATTRIBUTE_PEER_ADDRESS,
&sa.addr, sizeof(sa)) != &sa.storage, sizeof(sa)) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
goto send; goto send;
} else { } else {
...@@ -660,7 +660,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to, ...@@ -660,7 +660,7 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to,
goto send; goto send;
} }
if (stun_message_append_addr (&msg, STUN_ATTRIBUTE_DESTINATION_ADDRESS, if (stun_message_append_addr (&msg, STUN_ATTRIBUTE_DESTINATION_ADDRESS,
&sa.addr, sizeof(sa)) != &sa.storage, sizeof(sa)) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
goto send; goto send;
...@@ -852,7 +852,7 @@ priv_binding_expired_timeout (gpointer data) ...@@ -852,7 +852,7 @@ priv_binding_expired_timeout (gpointer data)
/* look up binding associated with peer */ /* look up binding associated with peer */
stun_message_find_xor_addr ( stun_message_find_xor_addr (
&priv->current_binding_msg->message, &priv->current_binding_msg->message,
STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &sa.addr, &sa_len); STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &sa.storage, &sa_len);
nice_address_set_from_sockaddr (&to, &sa.addr); nice_address_set_from_sockaddr (&to, &sa.addr);
/* If the binding is being refreshed, then move it to /* If the binding is being refreshed, then move it to
...@@ -1071,7 +1071,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -1071,7 +1071,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
/* look up binding associated with peer */ /* look up binding associated with peer */
stun_message_find_xor_addr ( stun_message_find_xor_addr (
&priv->current_binding_msg->message, &priv->current_binding_msg->message,
STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &sa.addr, &sa_len); STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &sa.storage, &sa_len);
nice_address_set_from_sockaddr (&to, &sa.addr); nice_address_set_from_sockaddr (&to, &sa.addr);
for (i = priv->channels; i; i = i->next) { for (i = priv->channels; i; i = i->next) {
...@@ -1174,7 +1174,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -1174,7 +1174,7 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
nice_debug ("got response for CreatePermission"); nice_debug ("got response for CreatePermission");
stun_message_find_xor_addr ( stun_message_find_xor_addr (
&current_create_permission_msg->message, &current_create_permission_msg->message,
STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &peer.addr, &peer_len); STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &peer.storage, &peer_len);
nice_address_set_from_sockaddr (&to, &peer.addr); nice_address_set_from_sockaddr (&to, &peer.addr);
/* unathorized => resend with realm and nonce */ /* unathorized => resend with realm and nonce */
...@@ -1255,12 +1255,12 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -1255,12 +1255,12 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 || if (priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_DRAFT9 ||
priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) { priv->compatibility == NICE_TURN_SOCKET_COMPATIBILITY_RFC5766) {
if (stun_message_find_xor_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS, if (stun_message_find_xor_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS,
&sa.addr, &from_len) != &sa.storage, &from_len) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
goto recv; goto recv;
} else { } else {
if (stun_message_find_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS, if (stun_message_find_addr (&msg, STUN_ATTRIBUTE_REMOTE_ADDRESS,
&sa.addr, &from_len) != &sa.storage, &from_len) !=
STUN_MESSAGE_RETURN_SUCCESS) STUN_MESSAGE_RETURN_SUCCESS)
goto recv; goto recv;
} }
...@@ -1440,7 +1440,7 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv, GList *lis ...@@ -1440,7 +1440,7 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv, GList *lis
stun_agent_forget_transaction (&priv->agent, id); stun_agent_forget_transaction (&priv->agent, id);
stun_message_find_xor_addr ( stun_message_find_xor_addr (
&current_create_permission_msg->message, &current_create_permission_msg->message,
STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &addr.addr, &addr_len); STUN_ATTRIBUTE_XOR_PEER_ADDRESS, &addr.storage, &addr_len);
nice_address_set_from_sockaddr (&to, &addr.addr); nice_address_set_from_sockaddr (&to, &addr.addr);
priv_remove_sent_permission_for_peer (priv, &to); priv_remove_sent_permission_for_peer (priv, &to);
...@@ -1647,7 +1647,7 @@ priv_send_create_permission(TurnPriv *priv, StunMessage *resp, ...@@ -1647,7 +1647,7 @@ priv_send_create_permission(TurnPriv *priv, StunMessage *resp,
priv->password_len, priv->password_len,
realm, realm_len, realm, realm_len,
nonce, nonce_len, nonce, nonce_len,
&addr.addr, &addr.storage,
STUN_USAGE_TURN_COMPATIBILITY_RFC5766); STUN_USAGE_TURN_COMPATIBILITY_RFC5766);
if (msg_buf_len > 0) { if (msg_buf_len > 0) {
...@@ -1699,7 +1699,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp, ...@@ -1699,7 +1699,7 @@ priv_send_channel_bind (TurnPriv *priv, StunMessage *resp,
} }
if (stun_message_append_xor_addr (&msg->message, STUN_ATTRIBUTE_PEER_ADDRESS, if (stun_message_append_xor_addr (&msg->message, STUN_ATTRIBUTE_PEER_ADDRESS,
&sa.addr, &sa.storage,
sizeof(sa)) sizeof(sa))
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
...@@ -1829,7 +1829,7 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer) ...@@ -1829,7 +1829,7 @@ priv_add_channel_binding (TurnPriv *priv, const NiceAddress *peer)
if (stun_message_append_addr (&msg->message, if (stun_message_append_addr (&msg->message,
STUN_ATTRIBUTE_DESTINATION_ADDRESS, STUN_ATTRIBUTE_DESTINATION_ADDRESS,
&sa.addr, sizeof(sa)) &sa.storage, sizeof(sa))
!= STUN_MESSAGE_RETURN_SUCCESS) { != STUN_MESSAGE_RETURN_SUCCESS) {
g_free (msg); g_free (msg);
return FALSE; return FALSE;
......
...@@ -223,7 +223,7 @@ stun_message_find_string (const StunMessage *msg, StunAttribute type, ...@@ -223,7 +223,7 @@ stun_message_find_string (const StunMessage *msg, StunAttribute type,
StunMessageReturn StunMessageReturn
stun_message_find_addr (const StunMessage *msg, StunAttribute type, stun_message_find_addr (const StunMessage *msg, StunAttribute type,
struct sockaddr *addr, socklen_t *addrlen) struct sockaddr_storage *addr, socklen_t *addrlen)
{ {
const uint8_t *ptr; const uint8_t *ptr;
uint16_t len = 0; uint16_t len = 0;
...@@ -284,8 +284,7 @@ stun_message_find_addr (const StunMessage *msg, StunAttribute type, ...@@ -284,8 +284,7 @@ stun_message_find_addr (const StunMessage *msg, StunAttribute type,
StunMessageReturn StunMessageReturn
stun_message_find_xor_addr (const StunMessage *msg, StunAttribute type, stun_message_find_xor_addr (const StunMessage *msg, StunAttribute type,
struct sockaddr *addr, struct sockaddr_storage *addr, socklen_t *addrlen)
socklen_t *addrlen)
{ {
StunMessageReturn val = stun_message_find_addr (msg, type, addr, addrlen); StunMessageReturn val = stun_message_find_addr (msg, type, addr, addrlen);
if (val) if (val)
...@@ -296,8 +295,7 @@ stun_message_find_xor_addr (const StunMessage *msg, StunAttribute type, ...@@ -296,8 +295,7 @@ stun_message_find_xor_addr (const StunMessage *msg, StunAttribute type,
StunMessageReturn StunMessageReturn
stun_message_find_xor_addr_full (const StunMessage *msg, StunAttribute type, stun_message_find_xor_addr_full (const StunMessage *msg, StunAttribute type,
struct sockaddr *addr, socklen_t *addrlen, struct sockaddr_storage *addr, socklen_t *addrlen, uint32_t magic_cookie)
uint32_t magic_cookie)
{ {
StunMessageReturn val = stun_message_find_addr (msg, type, addr, addrlen); StunMessageReturn val = stun_message_find_addr (msg, type, addr, addrlen);
if (val) if (val)
...@@ -422,7 +420,7 @@ stun_message_append_string (StunMessage * msg, StunAttribute type, ...@@ -422,7 +420,7 @@ stun_message_append_string (StunMessage * msg, StunAttribute type,
StunMessageReturn StunMessageReturn
stun_message_append_addr (StunMessage *msg, StunAttribute type, stun_message_append_addr (StunMessage *msg, StunAttribute type,
const struct sockaddr *addr, socklen_t addrlen) const struct sockaddr_storage *addr, socklen_t addrlen)
{ {
const void *pa; const void *pa;
uint8_t *ptr; uint8_t *ptr;
...@@ -432,7 +430,7 @@ stun_message_append_addr (StunMessage *msg, StunAttribute type, ...@@ -432,7 +430,7 @@ stun_message_append_addr (StunMessage *msg, StunAttribute type,
if ((size_t) addrlen < sizeof (struct sockaddr)) if ((size_t) addrlen < sizeof (struct sockaddr))
return STUN_MESSAGE_RETURN_INVALID; return STUN_MESSAGE_RETURN_INVALID;
switch (addr->sa_family) switch (addr->ss_family)
{ {
case AF_INET: case AF_INET:
{ {
...@@ -475,48 +473,42 @@ stun_message_append_addr (StunMessage *msg, StunAttribute type, ...@@ -475,48 +473,42 @@ stun_message_append_addr (StunMessage *msg, StunAttribute type,
StunMessageReturn StunMessageReturn
stun_message_append_xor_addr (StunMessage *msg, StunAttribute type, stun_message_append_xor_addr (StunMessage *msg, StunAttribute type,
const struct sockaddr *addr, socklen_t addrlen) const struct sockaddr_storage *addr, socklen_t addrlen)
{ {
StunMessageReturn val; StunMessageReturn val;
/* Must be big enough to hold any supported address: */ /* Must be big enough to hold any supported address: */
union { struct sockaddr_storage tmpaddr;
struct sockaddr_storage storage;
struct sockaddr addr;
} xor;
if ((size_t) addrlen > sizeof (xor)) if ((size_t) addrlen > sizeof (tmpaddr))
addrlen = sizeof (xor); addrlen = sizeof (tmpaddr);
memcpy (&xor.storage, addr, addrlen); memcpy (&tmpaddr, addr, addrlen);
val = stun_xor_address (msg, &xor.addr, addrlen, val = stun_xor_address (msg, &tmpaddr, addrlen,
STUN_MAGIC_COOKIE); STUN_MAGIC_COOKIE);
if (val) if (val)
return val; return val;
return stun_message_append_addr (msg, type, &xor.addr, addrlen); return stun_message_append_addr (msg, type, &tmpaddr, addrlen);
} }
StunMessageReturn StunMessageReturn
stun_message_append_xor_addr_full (StunMessage *msg, StunAttribute type, stun_message_append_xor_addr_full (StunMessage *msg, StunAttribute type,
const struct sockaddr *addr, socklen_t addrlen, const struct sockaddr_storage *addr, socklen_t addrlen,
uint32_t magic_cookie) uint32_t magic_cookie)
{ {
StunMessageReturn val; StunMessageReturn val;
/* Must be big enough to hold any supported address: */ /* Must be big enough to hold any supported address: */
union { struct sockaddr_storage tmpaddr;
struct sockaddr_storage storage;
struct sockaddr addr;
} xor;
if ((size_t) addrlen > sizeof (xor)) if ((size_t) addrlen > sizeof (tmpaddr))
addrlen = sizeof (xor); addrlen = sizeof (tmpaddr);
memcpy (&xor.storage, addr, addrlen); memcpy (&tmpaddr, addr, addrlen);
val = stun_xor_address (msg, &xor.addr, addrlen, magic_cookie); val = stun_xor_address (msg, &tmpaddr, addrlen, magic_cookie);
if (val) if (val)
return val; return val;
return stun_message_append_addr (msg, type, &xor.addr, addrlen); return stun_message_append_addr (msg, type, &tmpaddr, addrlen);
} }
......
...@@ -645,7 +645,7 @@ StunMessageReturn stun_message_find_string (const StunMessage *msg, ...@@ -645,7 +645,7 @@ StunMessageReturn stun_message_find_string (const StunMessage *msg,
* %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown. * %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown.
*/ */
StunMessageReturn stun_message_find_addr (const StunMessage *msg, StunMessageReturn stun_message_find_addr (const StunMessage *msg,
StunAttribute type, struct sockaddr *addr, socklen_t *addrlen); StunAttribute type, struct sockaddr_storage *addr, socklen_t *addrlen);
/** /**
* stun_message_find_xor_addr: * stun_message_find_xor_addr:
...@@ -664,7 +664,7 @@ StunMessageReturn stun_message_find_addr (const StunMessage *msg, ...@@ -664,7 +664,7 @@ StunMessageReturn stun_message_find_addr (const StunMessage *msg,
* %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown. * %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown.
*/ */
StunMessageReturn stun_message_find_xor_addr (const StunMessage *msg, StunMessageReturn stun_message_find_xor_addr (const StunMessage *msg,
StunAttribute type, struct sockaddr *addr, socklen_t *addrlen); StunAttribute type, struct sockaddr_storage *addr, socklen_t *addrlen);
/** /**
* stun_message_find_xor_addr_full: * stun_message_find_xor_addr_full:
...@@ -684,7 +684,7 @@ StunMessageReturn stun_message_find_xor_addr (const StunMessage *msg, ...@@ -684,7 +684,7 @@ StunMessageReturn stun_message_find_xor_addr (const StunMessage *msg,
* %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown. * %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown.
*/ */
StunMessageReturn stun_message_find_xor_addr_full (const StunMessage *msg, StunMessageReturn stun_message_find_xor_addr_full (const StunMessage *msg,
StunAttribute type, struct sockaddr *addr, StunAttribute type, struct sockaddr_storage *addr,
socklen_t *addrlen, uint32_t magic_cookie); socklen_t *addrlen, uint32_t magic_cookie);
...@@ -795,7 +795,7 @@ StunMessageReturn stun_message_append_string (StunMessage *msg, ...@@ -795,7 +795,7 @@ StunMessageReturn stun_message_append_string (StunMessage *msg,
* %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown. * %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown.
*/ */
StunMessageReturn stun_message_append_addr (StunMessage * msg, StunMessageReturn stun_message_append_addr (StunMessage * msg,
StunAttribute type, const struct sockaddr *addr, socklen_t addrlen); StunAttribute type, const struct sockaddr_storage *addr, socklen_t addrlen);
/** /**
* stun_message_append_xor_addr: * stun_message_append_xor_addr:
...@@ -811,7 +811,7 @@ StunMessageReturn stun_message_append_addr (StunMessage * msg, ...@@ -811,7 +811,7 @@ StunMessageReturn stun_message_append_addr (StunMessage * msg,
* %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown. * %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown.
*/ */
StunMessageReturn stun_message_append_xor_addr (StunMessage * msg, StunMessageReturn stun_message_append_xor_addr (StunMessage * msg,
StunAttribute type, const struct sockaddr *addr, socklen_t addrlen); StunAttribute type, const struct sockaddr_storage *addr, socklen_t addrlen);
/** /**
* stun_message_append_xor_addr_full: * stun_message_append_xor_addr_full:
...@@ -828,7 +828,7 @@ StunMessageReturn stun_message_append_xor_addr (StunMessage * msg, ...@@ -828,7 +828,7 @@ StunMessageReturn stun_message_append_xor_addr (StunMessage * msg,
* %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown. * %STUN_MESSAGE_RETURN_UNSUPPORTED_ADDRESS if the address family is unknown.
*/ */
StunMessageReturn stun_message_append_xor_addr_full (StunMessage * msg, StunMessageReturn stun_message_append_xor_addr_full (StunMessage * msg,
StunAttribute type, const struct sockaddr *addr, socklen_t addrlen, StunAttribute type, const struct sockaddr_storage *addr, socklen_t addrlen,
uint32_t magic_cookie); uint32_t magic_cookie);
/** /**
......
...@@ -102,7 +102,8 @@ static int listen_dgram (void) ...@@ -102,7 +102,8 @@ static int listen_dgram (void)
/** Incorrect socket family test */ /** Incorrect socket family test */
static void bad_family (void) static void bad_family (void)
{ {
struct sockaddr addr, dummy; struct sockaddr addr;
struct sockaddr_storage dummy;
int val; int val;
socklen_t dummylen = sizeof(dummy); socklen_t dummylen = sizeof(dummy);
...@@ -121,7 +122,8 @@ static void bad_family (void) ...@@ -121,7 +122,8 @@ static void bad_family (void)
/** Too small socket address test */ /** Too small socket address test */
static void small_srv_addr (void) static void small_srv_addr (void)
{ {
struct sockaddr addr, dummy; struct sockaddr addr;
struct sockaddr_storage dummy;
int val; int val;
socklen_t dummylen = sizeof(dummy); socklen_t dummylen = sizeof(dummy);
...@@ -141,7 +143,7 @@ static void small_srv_addr (void) ...@@ -141,7 +143,7 @@ static void small_srv_addr (void)
static void big_srv_addr (void) static void big_srv_addr (void)
{ {
uint8_t buf[sizeof (struct sockaddr_storage) + 16]; uint8_t buf[sizeof (struct sockaddr_storage) + 16];
struct sockaddr dummy; struct sockaddr_storage dummy;
int val; int val;
socklen_t dummylen = sizeof(dummy); socklen_t dummylen = sizeof(dummy);
...@@ -156,8 +158,7 @@ static void big_srv_addr (void) ...@@ -156,8 +158,7 @@ static void big_srv_addr (void)
/** Timeout test */ /** Timeout test */
static void timeout (void) static void timeout (void)
{ {
struct sockaddr_storage srv; struct sockaddr_storage srv, dummy;
struct sockaddr dummy;
socklen_t srvlen = sizeof (srv); socklen_t srvlen = sizeof (srv);
socklen_t dummylen = sizeof(dummy); socklen_t dummylen = sizeof(dummy);
int val; int val;
...@@ -231,8 +232,7 @@ static void bad_responses (void) ...@@ -231,8 +232,7 @@ static void bad_responses (void)
assert (stun_agent_validate (&agent, &msg, buf, len, NULL, NULL) assert (stun_agent_validate (&agent, &msg, buf, len, NULL, NULL)
== STUN_VALIDATION_SUCCESS); == STUN_VALIDATION_SUCCESS);
val = stun_usage_bind_process (&msg, val = stun_usage_bind_process (&msg, &addr, &addrlen, &addr, &addrlen);
(struct sockaddr *)&addr, &addrlen, (struct sockaddr *)&addr, &addrlen);
assert (val == STUN_USAGE_BIND_RETURN_INVALID); assert (val == STUN_USAGE_BIND_RETURN_INVALID);
/* Send response with wrong request type */ /* Send response with wrong request type */
...@@ -241,8 +241,7 @@ static void bad_responses (void) ...@@ -241,8 +241,7 @@ static void bad_responses (void)
/* Send error response without ERROR-CODE */ /* Send error response without ERROR-CODE */
buf[1] |= 0x10; buf[1] |= 0x10;
val = stun_usage_bind_process (&msg, val = stun_usage_bind_process (&msg, &addr, &addrlen, &addr, &addrlen);
(struct sockaddr *)&addr, &addrlen, (struct sockaddr *)&addr, &addrlen);
assert (val == STUN_USAGE_BIND_RETURN_INVALID); assert (val == STUN_USAGE_BIND_RETURN_INVALID);
close (fd); close (fd);
...@@ -311,8 +310,7 @@ static void responses (void) ...@@ -311,8 +310,7 @@ static void responses (void)
val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen); val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen);
assert (val == 0); assert (val == 0);
val = stun_usage_bind_process (&msg, val = stun_usage_bind_process (&msg, &addr, &addrlen, &addr, &addrlen);
(struct sockaddr *)&addr, &addrlen, (struct sockaddr *)&addr, &addrlen);
assert (val == STUN_USAGE_BIND_RETURN_ERROR); assert (val == STUN_USAGE_BIND_RETURN_ERROR);
/* Send response with a no mapped address at all */ /* Send response with a no mapped address at all */
...@@ -342,8 +340,7 @@ static void responses (void) ...@@ -342,8 +340,7 @@ static void responses (void)
val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen); val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen);
assert (val == 0); assert (val == 0);
val = stun_usage_bind_process (&msg, val = stun_usage_bind_process (&msg, &addr, &addrlen, &addr, &addrlen);
(struct sockaddr *)&addr, &addrlen, (struct sockaddr *)&addr, &addrlen);
assert (val == STUN_USAGE_BIND_RETURN_ERROR); assert (val == STUN_USAGE_BIND_RETURN_ERROR);
/* Send old-style response */ /* Send old-style response */
...@@ -365,7 +362,7 @@ static void responses (void) ...@@ -365,7 +362,7 @@ static void responses (void)
stun_agent_init_response (&agent, &msg, buf, sizeof (buf), &msg); stun_agent_init_response (&agent, &msg, buf, sizeof (buf), &msg);
assert (stun_message_append_addr (&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS, assert (stun_message_append_addr (&msg, STUN_ATTRIBUTE_MAPPED_ADDRESS,
(struct sockaddr *)&addr, addrlen) == STUN_MESSAGE_RETURN_SUCCESS); &addr, addrlen) == STUN_MESSAGE_RETURN_SUCCESS);
len = stun_agent_finish_message (&agent, &msg, NULL, 0); len = stun_agent_finish_message (&agent, &msg, NULL, 0);
assert (len > 0); assert (len > 0);
...@@ -375,8 +372,7 @@ static void responses (void) ...@@ -375,8 +372,7 @@ static void responses (void)
val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen); val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen);
assert (val == 0); assert (val == 0);
val = stun_usage_bind_process (&msg, val = stun_usage_bind_process (&msg, &addr, &addrlen, &addr, &addrlen);
(struct sockaddr *)&addr, &addrlen, (struct sockaddr *)&addr, &addrlen);
assert (val == STUN_USAGE_BIND_RETURN_SUCCESS); assert (val == STUN_USAGE_BIND_RETURN_SUCCESS);
/* End */ /* End */
......
...@@ -67,7 +67,11 @@ ...@@ -67,7 +67,11 @@
int main (void) int main (void)
{ {
struct sockaddr_in ip4; union {
struct sockaddr sa;
struct sockaddr_storage storage;
struct sockaddr_in ip4;
} addr;
uint8_t req_buf[STUN_MAX_MESSAGE_SIZE]; uint8_t req_buf[STUN_MAX_MESSAGE_SIZE];
uint8_t resp_buf[STUN_MAX_MESSAGE_SIZE]; uint8_t resp_buf[STUN_MAX_MESSAGE_SIZE];
const const uint64_t tie = 0x8000000000000000LL; const const uint64_t tie = 0x8000000000000000LL;
...@@ -95,13 +99,13 @@ int main (void) ...@@ -95,13 +99,13 @@ int main (void)
STUN_AGENT_USAGE_USE_FINGERPRINT | STUN_AGENT_USAGE_USE_FINGERPRINT |
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS); STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS);
memset (&ip4, 0, sizeof (ip4)); memset (&addr, 0, sizeof (addr));
ip4.sin_family = AF_INET; addr.ip4.sin_family = AF_INET;
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
ip4.sin_len = sizeof (addr); addr.ip4.sin_len = sizeof (addr);
#endif #endif
ip4.sin_port = htons (12345); addr.ip4.sin_port = htons (12345);
ip4.sin_addr.s_addr = htonl (0x7f000001); addr.ip4.sin_addr.s_addr = htonl (0x7f000001);
/* Incorrect message class */ /* Incorrect message class */
assert (stun_agent_init_request (&agent, &req, req_buf, sizeof(req_buf), STUN_BINDING)); assert (stun_agent_init_request (&agent, &req, req_buf, sizeof(req_buf), STUN_BINDING));
...@@ -112,8 +116,8 @@ int main (void) ...@@ -112,8 +116,8 @@ int main (void)
len = sizeof (resp_buf); len = sizeof (resp_buf);
val2 = stun_usage_ice_conncheck_create_reply (&agent, &req, val2 = stun_usage_ice_conncheck_create_reply (&agent, &req,
&resp, resp_buf, &len, (struct sockaddr *)&ip4, &resp, resp_buf, &len, &addr.storage,
sizeof (ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245); sizeof (addr.ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245);
assert (val2 == STUN_USAGE_ICE_RETURN_INVALID_REQUEST); assert (val2 == STUN_USAGE_ICE_RETURN_INVALID_REQUEST);
assert (len == 0); assert (len == 0);
...@@ -126,8 +130,8 @@ int main (void) ...@@ -126,8 +130,8 @@ int main (void)
len = sizeof (resp_buf); len = sizeof (resp_buf);
val2 = stun_usage_ice_conncheck_create_reply (&agent, &req, val2 = stun_usage_ice_conncheck_create_reply (&agent, &req,
&resp, resp_buf, &len, (struct sockaddr *)&ip4, &resp, resp_buf, &len, &addr.storage,
sizeof (ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245); sizeof (addr.ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245);
assert (val2 == STUN_USAGE_ICE_RETURN_INVALID_METHOD); assert (val2 == STUN_USAGE_ICE_RETURN_INVALID_METHOD);
assert (len > 0); assert (len > 0);
...@@ -181,8 +185,8 @@ int main (void) ...@@ -181,8 +185,8 @@ int main (void)
len = sizeof (resp_buf); len = sizeof (resp_buf);
val2 = stun_usage_ice_conncheck_create_reply (&agent, &req, val2 = stun_usage_ice_conncheck_create_reply (&agent, &req,
&resp, resp_buf, &len, (struct sockaddr *)&ip4, &resp, resp_buf, &len, &addr.storage,
sizeof (ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245); sizeof (addr.ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245);
assert (val2 == STUN_USAGE_ICE_RETURN_SUCCESS); assert (val2 == STUN_USAGE_ICE_RETURN_SUCCESS);
assert (len > 0); assert (len > 0);
assert (stun_agent_validate (&agent, &resp, resp_buf, len, assert (stun_agent_validate (&agent, &resp, resp_buf, len,
...@@ -198,15 +202,15 @@ int main (void) ...@@ -198,15 +202,15 @@ int main (void)
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len); rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0); assert (rlen > 0);
ip4.sin_family = AF_UNSPEC; addr.ip4.sin_family = AF_UNSPEC;
len = sizeof (resp_buf); len = sizeof (resp_buf);
val2 = stun_usage_ice_conncheck_create_reply (&agent, &req, val2 = stun_usage_ice_conncheck_create_reply (&agent, &req,
&resp, resp_buf, &len, (struct sockaddr *)&ip4, &resp, resp_buf, &len, &addr.storage,
sizeof (ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245); sizeof (addr.ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245);
assert (val2 == STUN_USAGE_ICE_RETURN_INVALID_ADDRESS); assert (val2 == STUN_USAGE_ICE_RETURN_INVALID_ADDRESS);
assert (len == 0); assert (len == 0);
ip4.sin_family = AF_INET; addr.ip4.sin_family = AF_INET;
/* Lost role conflict */ /* Lost role conflict */
assert (stun_agent_init_request (&agent, &req, req_buf, sizeof(req_buf), STUN_BINDING)); assert (stun_agent_init_request (&agent, &req, req_buf, sizeof(req_buf), STUN_BINDING));
...@@ -221,8 +225,8 @@ int main (void) ...@@ -221,8 +225,8 @@ int main (void)
len = sizeof (resp_buf); len = sizeof (resp_buf);
control = true; control = true;
val2 = stun_usage_ice_conncheck_create_reply (&agent, &req, val2 = stun_usage_ice_conncheck_create_reply (&agent, &req,
&resp, resp_buf, &len, (struct sockaddr *)&ip4, &resp, resp_buf, &len, &addr.storage,
sizeof (ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245); sizeof (addr.ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245);
assert (val2 == STUN_USAGE_ICE_RETURN_ROLE_CONFLICT); assert (val2 == STUN_USAGE_ICE_RETURN_ROLE_CONFLICT);
assert (len > 0); assert (len > 0);
assert (control == false); assert (control == false);
...@@ -242,8 +246,8 @@ int main (void) ...@@ -242,8 +246,8 @@ int main (void)
len = sizeof (resp_buf); len = sizeof (resp_buf);
control = false; control = false;
val2 = stun_usage_ice_conncheck_create_reply (&agent, &req, val2 = stun_usage_ice_conncheck_create_reply (&agent, &req,
&resp, resp_buf, &len, (struct sockaddr *)&ip4, &resp, resp_buf, &len, &addr.storage,
sizeof (ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245); sizeof (addr.ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245);
assert (val2 == STUN_USAGE_ICE_RETURN_SUCCESS); assert (val2 == STUN_USAGE_ICE_RETURN_SUCCESS);