From: bert hubert Date: Fri, 4 Sep 2015 11:29:14 +0000 (+0200) Subject: clean up a bit, plus optimize /32 and /128 cases X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~59^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ecd43f08afc42ba4166797e1131e06104074f6c7;p=pdns clean up a bit, plus optimize /32 and /128 cases --- diff --git a/pdns/iputils.cc b/pdns/iputils.cc index 6e6020909..d54257dc8 100644 --- a/pdns/iputils.cc +++ b/pdns/iputils.cc @@ -166,19 +166,18 @@ void ComboAddress::truncate(unsigned int bits) uint8_t* start; int len=4; if(sin4.sin_family==AF_INET) { - if(bits > 32) + if(bits >= 32) return; start = (uint8_t*)&sin4.sin_addr.s_addr; len=4; } else { - if(bits > 128) + if(bits >= 128) return; start = (uint8_t*)&sin6.sin6_addr.s6_addr; len=16; } - auto tozero= len*8 - bits; // if set to 22, this will clear 1 byte, as it should memset(start + len - tozero/8, 0, tozero/8); // blot out the whole bytes on the right @@ -188,8 +187,5 @@ void ComboAddress::truncate(unsigned int bits) // a b c d, to truncate to 22 bits, we just zeroed 'd' and need to zero 2 bits from c // so and by '11111100', which is ~((1<<2)-1) = ~3 uint8_t* place = start + len - 1 - tozero/8; - - - *place &= (~((1<