From 14da0d6e048bcb4e5d5ddfa5709a4bb82d0d2ba2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Sun, 28 Jul 2019 11:33:16 -0400 Subject: [PATCH] udp-bsd: Use sockaddr_storage union to ensure big enough socket The IPv6 struct sockaddr variant is bigger than the IPv4 one, so use the storage struct to ensure that the size is big enough. --- socket/udp-bsd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/socket/udp-bsd.c b/socket/udp-bsd.c index 8f65e76..cad3b32 100644 --- a/socket/udp-bsd.c +++ b/socket/udp-bsd.c @@ -293,20 +293,23 @@ socket_send_message (NiceSocket *sock, const NiceAddress *to, if (g_error_matches (child_error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { len = 0; } else if (nice_debug_is_verbose()) { - struct sockaddr sa; + union { + struct sockaddr_storage ss; + struct sockaddr sa; + } sa; GSocketAddress *gsocket; NiceAddress local_addr; NiceAddress remote_addr; char remote_addr_str[INET6_ADDRSTRLEN]; char local_addr_str[INET6_ADDRSTRLEN]; - g_socket_address_to_native (gaddr, &sa, sizeof (sa), NULL); - nice_address_set_from_sockaddr (&remote_addr, &sa); + g_socket_address_to_native (gaddr, &sa.sa, sizeof (sa), NULL); + nice_address_set_from_sockaddr (&remote_addr, &sa.sa); nice_address_to_string (&remote_addr, remote_addr_str); gsocket = g_socket_get_local_address (sock->fileno, NULL); - g_socket_address_to_native (gsocket, &sa, sizeof (sa), NULL); - nice_address_set_from_sockaddr (&local_addr, &sa); + g_socket_address_to_native (gsocket, &sa.sa, sizeof (sa), NULL); + nice_address_set_from_sockaddr (&local_addr, &sa.sa); nice_address_to_string (&local_addr, local_addr_str); g_object_unref (gsocket); -- 2.7.4