From e8a13c44b011a73ea037b573e415032ce0fccca1 Mon Sep 17 00:00:00 2001 From: Bruno Bigras Date: Thu, 13 Feb 2014 12:06:10 -0500 Subject: [PATCH] Fix a strict-aliasing with type-punning Fixes #880 --- src/ip.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ip.cpp b/src/ip.cpp index a9559715..8d03f71d 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -145,7 +145,14 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_) return 0; ip_addr_ = host; - return (int) ((struct sockaddr *) &ss)->sa_family; + + union { + struct sockaddr sa; + struct sockaddr_storage sa_stor; + } u; + + u.sa_stor = ss; + return (int) u.sa.sa_family; } void zmq::set_ip_type_of_service (fd_t s_, int iptos)