Commit 68ff86f9 authored by Olivier Crête's avatar Olivier Crête

stun: Use unions fix alignment issues

This makes clang happy.
parent f1e24432
......@@ -448,12 +448,15 @@ static StunMessageReturn
stun_message_append_ms_connection_id(StunMessage *msg,
uint8_t *ms_connection_id, uint32_t ms_sequence_num)
{
uint8_t buf[24];
union {
uint8_t buf8[24];
uint32_t buf32[24/4];
} buf;
memcpy(buf, ms_connection_id, 20);
*(uint32_t*)(buf + 20) = htonl(ms_sequence_num);
memcpy(buf.buf8, ms_connection_id, 20);
buf.buf32[5] = htonl(ms_sequence_num);
return stun_message_append_bytes (msg, STUN_ATTRIBUTE_MS_SEQUENCE_NUMBER,
buf, 24);
buf.buf8, 24);
}
static void
......
......@@ -99,6 +99,12 @@ StunUsageBindReturn stun_usage_bind_process (StunMessage *msg,
{
int code = -1;
StunMessageReturn val;
union {
struct sockaddr *sa;
struct sockaddr_storage *sas;
} sa;
sa.sa = addr;
if (stun_message_get_method (msg) != STUN_BINDING)
return STUN_USAGE_BIND_RETURN_INVALID;
......@@ -124,9 +130,15 @@ StunUsageBindReturn stun_usage_bind_process (StunMessage *msg,
/* ALTERNATE-SERVER mechanism */
if ((code / 100) == 3) {
union {
struct sockaddr *sa;
struct sockaddr_storage *sas;
} alternate_sa;
alternate_sa.sa = alternate_server;
if (alternate_server && alternate_server_len) {
if (stun_message_find_addr (msg, STUN_ATTRIBUTE_ALTERNATE_SERVER,
(struct sockaddr_storage *) alternate_server,
alternate_sa.sas,
alternate_server_len) != STUN_MESSAGE_RETURN_SUCCESS) {
stun_debug (" Unexpectedly missing ALTERNATE-SERVER attribute");
return STUN_USAGE_BIND_RETURN_ERROR;
......@@ -152,13 +164,13 @@ StunUsageBindReturn stun_usage_bind_process (StunMessage *msg,
stun_debug ("Received %u-bytes STUN message", stun_message_length (msg));
val = stun_message_find_xor_addr (msg,
STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, (struct sockaddr_storage *)addr,
STUN_ATTRIBUTE_XOR_MAPPED_ADDRESS, sa.sas,
addrlen);
if (val != STUN_MESSAGE_RETURN_SUCCESS)
{
stun_debug (" No XOR-MAPPED-ADDRESS: %d", val);
val = stun_message_find_addr (msg,
STUN_ATTRIBUTE_MAPPED_ADDRESS, (struct sockaddr_storage *)addr,
STUN_ATTRIBUTE_MAPPED_ADDRESS, sa.sas,
addrlen);
if (val != STUN_MESSAGE_RETURN_SUCCESS)
{
......
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