diff options
author | Linus Nordberg <linus@nordu.net> | 2011-10-05 09:11:29 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2011-10-05 09:11:29 +0200 |
commit | ccf7d904d87c9097cee7471445e4a09876cb051a (patch) | |
tree | 808207de177a7b54d95d084cc8a359b28608ebb4 | |
parent | 59c3dd89f38fd34091ae909e47d7cc71650ce672 (diff) |
Get rid of warning for strict aliasing breakage.
-rw-r--r-- | lib/rsp_util.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/rsp_util.c b/lib/rsp_util.c index 7960eae..c2966b8 100644 --- a/lib/rsp_util.c +++ b/lib/rsp_util.c @@ -88,22 +88,26 @@ struct sockaddr *addr_copy(struct sockaddr *in) { } char *addr2string(struct sockaddr *addr) { - struct sockaddr_in6 *sa6; + union { + struct sockaddr *sa; + struct sockaddr_in *sa4; + struct sockaddr_in6 *sa6; + } u; struct sockaddr_in sa4; static char addr_buf[2][INET6_ADDRSTRLEN]; static int i = 0; i = !i; - if (addr->sa_family == AF_INET6) { - sa6 = (struct sockaddr_in6 *)addr; - if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr)) { + u.sa = addr; + if (u.sa->sa_family == AF_INET6) { + if (IN6_IS_ADDR_V4MAPPED(&u.sa6->sin6_addr)) { memset(&sa4, 0, sizeof(sa4)); sa4.sin_family = AF_INET; - sa4.sin_port = sa6->sin6_port; - memcpy(&sa4.sin_addr, &sa6->sin6_addr.s6_addr[12], 4); - addr = (struct sockaddr *)&sa4; + sa4.sin_port = u.sa6->sin6_port; + memcpy(&sa4.sin_addr, &u.sa6->sin6_addr.s6_addr[12], 4); + u.sa4 = &sa4; } } - if (getnameinfo(addr, SOCKADDRP_SIZE(addr), addr_buf[i], sizeof(addr_buf[i]), + if (getnameinfo(u.sa, SOCKADDRP_SIZE(u.sa), addr_buf[i], sizeof(addr_buf[i]), NULL, 0, NI_NUMERICHOST)) { debug(DBG_WARN, "getnameinfo failed"); return "getnameinfo_failed"; |