diff options
author | Denis Ovsienko <infrastation@yandex.ru> | 2011-12-16 16:25:02 +0400 |
---|---|---|
committer | Denis Ovsienko <infrastation@yandex.ru> | 2012-01-02 17:10:55 +0400 |
commit | ce77002e908e8c9eeff780a6a34143af6758a17f (patch) | |
tree | 76fed1f3dd8861625469f1ec9bba7c00e0cac894 /lib/prefix.c | |
parent | e1fabbb86c2558b336b83de443a4fde4b2a8db90 (diff) |
lib: fix type-punning in ip_masklen()
ip_masklen() was likely to return incorrect results after being compiled
with -fstrict-aliasing (-O2, -O3, -Os)
Diffstat (limited to 'lib/prefix.c')
-rw-r--r-- | lib/prefix.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index 19a52610..23202b62 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -2592,8 +2592,13 @@ masklen2ip (const int masklen, struct in_addr *netmask) u_char ip_masklen (struct in_addr netmask) { - u_int16_t * int16 = (u_int16_t *) &netmask.s_addr; - return map64kto17_nbo[int16[0]] + map64kto17_nbo[int16[1]]; + union + { + u_int32_t int32; + u_int16_t int16[2]; + } u; + u.int32 = netmask.s_addr; + return map64kto17_nbo[u.int16[0]] + map64kto17_nbo[u.int16[1]]; } /* Apply mask to IPv4 prefix (network byte order). */ |