Fix unaligned aliasing warning in raw socket
authorMartin Willi <martin@revosec.ch>
Wed, 16 Nov 2011 13:45:19 +0000 (13:45 +0000)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:30:41 +0000 (17:30 +0100)
src/libcharon/plugins/socket_raw/socket_raw_socket.c

index f371ed5..ae37d8f 100644 (file)
@@ -442,23 +442,22 @@ static int open_send_socket(private_socket_raw_socket_t *this,
        int skt;
 
        memset(&addr, 0, sizeof(addr));
+       addr.ss_family = family;
        /* precalculate constants depending on address family */
        switch (family)
        {
                case AF_INET:
                {
                        struct sockaddr_in *sin = (struct sockaddr_in *)&addr;
-                       sin->sin_family = AF_INET;
-                       sin->sin_addr.s_addr = INADDR_ANY;
-                       sin->sin_port = htons(port);
+                       htoun32(&sin->sin_addr.s_addr, INADDR_ANY);
+                       htoun16(&sin->sin_port, port);
                        break;
                }
                case AF_INET6:
                {
                        struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&addr;
-                       sin6->sin6_family = AF_INET6;
                        memcpy(&sin6->sin6_addr, &in6addr_any, sizeof(in6addr_any));
-                       sin6->sin6_port = htons(port);
+                       htoun16(&sin6->sin6_port, port);
                        break;
                }
                default: