[Olsr-dev] [PATCH v1 10/14] mdns: fix GCC 6 warnings

Ferry Huberts (spam-protected)
Wed Feb 24 00:46:19 CET 2016


From: Ferry Huberts <(spam-protected)>

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 <(spam-protected)>
---
 lib/mdns/src/NetworkInterfaces.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/lib/mdns/src/NetworkInterfaces.c b/lib/mdns/src/NetworkInterfaces.c
index c037003..0b01616 100644
--- a/lib/mdns/src/NetworkInterfaces.c
+++ b/lib/mdns/src/NetworkInterfaces.c
@@ -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) {
-- 
2.5.0




More information about the Olsr-dev mailing list