counting: Let get_range_size return double

This commit is contained in:
Cheer Xiao 2013-01-08 22:57:33 +08:00
parent afd9f77051
commit 9c4184bd9a
2 changed files with 5 additions and 5 deletions

View file

@ -205,7 +205,7 @@ int parse_ipaddr(const char *restrict src, union ipaddr_t *restrict dst);
void copy_ipaddr(union ipaddr_t *restrict dst, void copy_ipaddr(union ipaddr_t *restrict dst,
const union ipaddr_t *restrict src); const union ipaddr_t *restrict src);
const char *ntop_ipaddr(const union ipaddr_t *ip); const char *ntop_ipaddr(const union ipaddr_t *ip);
unsigned long get_range_size(const struct range_t *r); double get_range_size(const struct range_t *r);
int xstrstr(const char *__restrict a, const char *__restrict b, int len) int xstrstr(const char *__restrict a, const char *__restrict b, int len)
__attribute__ ((nonnull(1, 2))) __attribute__ ((nonnull(1, 2)))
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)

View file

@ -125,17 +125,17 @@ const char *ntop_ipaddr(const union ipaddr_t *ip)
* and last IP in the range. * and last IP in the range.
* \return Size of a range. * \return Size of a range.
*/ */
unsigned long get_range_size(const struct range_t *r) double get_range_size(const struct range_t *r)
{ {
if (config.dhcp_version == VERSION_6) { if (config.dhcp_version == VERSION_6) {
unsigned long size = 0; double size = 0;
int i; int i;
/* When calculating the size of an IPv6 range overflow may /* When calculating the size of an IPv6 range overflow may
* occur. In that case only the last LONG_BIT bits are * occur. In that case only the last LONG_BIT bits are
* preserved, thus we just skip the first (16 - LONG_BIT) * preserved, thus we just skip the first (16 - LONG_BIT)
* bits... */ * bits... */
for (i = LONG_BIT / 8 < 16 ? 16 - LONG_BIT / 8 : 0; i < 16; i++) { for (i = 0; i < 16; i++) {
size <<= 8; size *= 256;
size += (int)r->last_ip.v6[i] - (int)r->first_ip.v6[i]; size += (int)r->last_ip.v6[i] - (int)r->first_ip.v6[i];
} }
return size + 1; return size + 1;