]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Use type-punning to avoid breaking strict aliasing rules
authorJouni Malinen <jouni.malinen@atheros.com>
Thu, 5 Nov 2009 10:11:49 +0000 (12:11 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 5 Nov 2009 10:11:49 +0000 (12:11 +0200)
While the actual use here would be unlikely to be broken by any C
optimization, it is better to use explicit union construction to let
gcc know about the aliasing and avoid warnings from gcc 4.4.

src/radius/radius_server.c

index 1fb09c07bf5d86ae9eb29393f8ed84619c72a4df..2d1259b93c49a9ec15fa7257a1a006562089a039 100644 (file)
@@ -667,7 +667,13 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
 {
        struct radius_server_data *data = eloop_ctx;
        u8 *buf = NULL;
-       struct sockaddr_storage from;
+       union {
+               struct sockaddr_storage ss;
+               struct sockaddr_in sin;
+#ifdef CONFIG_IPV6
+               struct sockaddr_in6 sin6;
+#endif /* CONFIG_IPV6 */
+       } from;
        socklen_t fromlen;
        int len;
        struct radius_client *client = NULL;
@@ -682,7 +688,7 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
 
        fromlen = sizeof(from);
        len = recvfrom(sock, buf, RADIUS_MAX_MSG_LEN, 0,
-                      (struct sockaddr *) &from, &fromlen);
+                      (struct sockaddr *) &from.ss, &fromlen);
        if (len < 0) {
                perror("recvfrom[radius_server]");
                goto fail;
@@ -690,28 +696,26 @@ static void radius_server_receive_auth(int sock, void *eloop_ctx,
 
 #ifdef CONFIG_IPV6
        if (data->ipv6) {
-               struct sockaddr_in6 *from6 = (struct sockaddr_in6 *) &from;
-               if (inet_ntop(AF_INET6, &from6->sin6_addr, abuf, sizeof(abuf))
-                   == NULL)
+               if (inet_ntop(AF_INET6, &from.sin6.sin6_addr, abuf,
+                             sizeof(abuf)) == NULL)
                        abuf[0] = '\0';
-               from_port = ntohs(from6->sin6_port);
+               from_port = ntohs(from.sin6.sin6_port);
                RADIUS_DEBUG("Received %d bytes from %s:%d",
                             len, abuf, from_port);
 
                client = radius_server_get_client(data,
                                                  (struct in_addr *)
-                                                 &from6->sin6_addr, 1);
+                                                 &from.sin6.sin6_addr, 1);
        }
 #endif /* CONFIG_IPV6 */
 
        if (!data->ipv6) {
-               struct sockaddr_in *from4 = (struct sockaddr_in *) &from;
-               os_strlcpy(abuf, inet_ntoa(from4->sin_addr), sizeof(abuf));
-               from_port = ntohs(from4->sin_port);
+               os_strlcpy(abuf, inet_ntoa(from.sin.sin_addr), sizeof(abuf));
+               from_port = ntohs(from.sin.sin_port);
                RADIUS_DEBUG("Received %d bytes from %s:%d",
                             len, abuf, from_port);
 
-               client = radius_server_get_client(data, &from4->sin_addr, 0);
+               client = radius_server_get_client(data, &from.sin.sin_addr, 0);
        }
 
        RADIUS_DUMP("Received data", buf, len);