mdns: fix GCC 6 warnings
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Feb 2016 18:46:20 +0000 (19:46 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 25 Feb 2016 12:39:33 +0000 (13:39 +0100)
src/NetworkInterfaces.c: In function ‘CreateRouterElectionSocket’:
src/NetworkInterfaces.c:288:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   ipv4_addr = ((struct sockaddr_in *)(void *) &req.ifr_addr)->sin_addr;
                                                           ^
src/NetworkInterfaces.c: In function ‘CreateHelloSocket’:
src/NetworkInterfaces.c:383:59: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   ipv4_addr = ((struct sockaddr_in *)(void *) &req.ifr_addr)->sin_addr;
                                                           ^
src/NetworkInterfaces.c: In function ‘CreateInterface’:
src/NetworkInterfaces.c:541:49: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
       newIf->intAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(&ifr.ifr_addr))->sin_addr;
                                                 ^
src/NetworkInterfaces.c:554:51: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
       newIf->broadAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(&ifr.ifr_broadaddr))->sin_addr;
                                                   ^
src/NetworkInterfaces.c: In function ‘CreateBmfNetworkInterfaces’:
src/NetworkInterfaces.c:662:39: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
     ipAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(&ifr->ifr_addr))->sin_addr;
                                       ^

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/mdns/src/NetworkInterfaces.c

index c037003..0b01616 100644 (file)
@@ -285,7 +285,10 @@ CreateRouterElectionSocket(const char *ifName)
                        BmfPError("Could not get ipv4 address of %s interface", ifName);
                        goto bail;
                }
-               ipv4_addr = ((struct sockaddr_in *)(void *) &req.ifr_addr)->sin_addr;
+               {
+      struct sockaddr* ifra = &req.ifr_addr;
+                 ipv4_addr = ((struct sockaddr_in *)(void *) ifra)->sin_addr;
+               }
                mc_settings.imr_interface = ipv4_addr;
                errno = 0;
                if (setsockopt(rxSocket, ipProtoSetting, ipAddMembershipSetting,
@@ -380,7 +383,10 @@ static int CreateHelloSocket(const char *ifName) {
                        BmfPError("Could not get ipv4 address of %s interface", ifName);
                        goto bail;
                }
-               ipv4_addr = ((struct sockaddr_in *)(void *) &req.ifr_addr)->sin_addr;
+               {
+      struct sockaddr * ifra = &req.ifr_addr;
+      ipv4_addr = ((struct sockaddr_in *)(void *) ifra)->sin_addr;
+               }
                address.in4.sin_addr = ipv4_addr;
                address.in4.sin_family = ipFamilySetting;
                address.in4.sin_port = ipPort;
@@ -538,7 +544,8 @@ CreateInterface(const char *ifName, struct interface_olsr *olsrIntf)
       newIf->intAddr.v4.s_addr = inet_addr("0.0.0.0");
     } else {
       /* Downcast to correct sockaddr subtype */
-      newIf->intAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(&ifr.ifr_addr))->sin_addr;
+      struct sockaddr* ifra = &ifr.ifr_addr;
+      newIf->intAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(ifra))->sin_addr;
     }
 
     /* For a non-OLSR interface, retrieve the IP broadcast address ourselves */
@@ -551,7 +558,8 @@ CreateInterface(const char *ifName, struct interface_olsr *olsrIntf)
       newIf->broadAddr.v4.s_addr = inet_addr("0.0.0.0");
     } else {
       /* Downcast to correct sockaddr subtype */
-      newIf->broadAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(&ifr.ifr_broadaddr))->sin_addr;
+      struct sockaddr* ifrb = &ifr.ifr_broadaddr;
+      newIf->broadAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(ifrb))->sin_addr;
     }
   }
 
@@ -659,7 +667,10 @@ CreateBmfNetworkInterfaces(struct interface_olsr *skipThisIntf)
     //}
 
     /* ...find the OLSR interface structure, if any */
-    ipAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(&ifr->ifr_addr))->sin_addr;
+    {
+      struct sockaddr* ifra = &ifr->ifr_addr;
+      ipAddr.v4 = ((struct sockaddr_in *)ARM_NOWARN_ALIGN(ifra))->sin_addr;
+    }
     olsrIntf = if_ifwithaddr(&ipAddr);
 
     if (skipThisIntf != NULL && olsrIntf == skipThisIntf) {