fr_inaddr_mask fix 0 prefix
authorSam Hartman <hartmans@debian.org>
Thu, 10 Jul 2014 13:42:18 +0000 (09:42 -0400)
committerSam Hartman <hartmans@debian.org>
Thu, 10 Jul 2014 13:42:18 +0000 (09:42 -0400)
Don't depend on the behavior of shifting by 32-bits on a 32-bit type.

src/lib/misc.c

index 84d1624..af0616c 100644 (file)
@@ -961,7 +961,9 @@ struct in_addr fr_inaddr_mask(struct in_addr const *ipaddr, uint8_t prefix)
                return *ipaddr;
        }
 
-       ret = htonl(~((0x00000001UL << (32 - prefix)) - 1)) & ipaddr->s_addr;
+       if (prefix == 0)
+               ret = 0;
+       else ret = htonl(~((0x00000001UL << (32 - prefix)) - 1)) & ipaddr->s_addr;
        return (*(struct in_addr *)&ret);
 }