static void
iptobinstr (const int af, const void *addr, char *str)
{
- unsigned int i;
+ int i;
switch (af)
{
str += 31;
for (i = 31; i >= 0; i--)
{
- *str-- = (b & 1) + '0';
+ *str = (b & 1) + '0';
+ str--;
b >>= 1;
}
break;
}
case AF_INET6:
{
- struct in6_addr b = *(struct in6_addr *) addr;
+ struct in6_addr b = *(const struct in6_addr *) addr;
str[128] = '\0';
str += 127;
for (i = 127; i >= 0; i--)
{
- *str-- = (b.s6_addr[i / 8] & 1) + '0';
+ *str = (b.s6_addr[i / 8] & 1) + '0';
+ str--;
b.s6_addr[i / 8] >>= 1;
}
break;
if (1 != inet_pton (AF_INET, netmask, &a))
return 0;
-
- for (len = 32, t = htonl (~a.s_addr); t & 1; t >>= 1, len--) ;
-
+ len = 32;
+ for (t = htonl (~a.s_addr); 0 != t; t >>= 1)
+ len--;
return len;
}
pfxlen = ipv4netmasktoprefixlen (netmask);
iptobinstr (AF_INET, ip, rxstr);
rxstr[pfxlen] = '\0';
- strcat (rxstr, "(0|1)*");
+ if (pfxlen < 32)
+ strcat (rxstr, "(0|1)+");
}
* bytes long.
*/
void
-GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6,
- const unsigned int prefixlen, char *rxstr)
+GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
+ char *rxstr)
{
iptobinstr (AF_INET6, ipv6, rxstr);
rxstr[prefixlen] = '\0';
- strcat (rxstr, "(0|1)*");
+ if (prefixlen < 128)
+ strcat (rxstr, "(0|1)+");
}