diff --git a/binaries/aarch64/ip2net b/binaries/aarch64/ip2net index 04241d2..05512f7 100755 Binary files a/binaries/aarch64/ip2net and b/binaries/aarch64/ip2net differ diff --git a/binaries/arm/ip2net b/binaries/arm/ip2net index 1f876fd..22f89a9 100755 Binary files a/binaries/arm/ip2net and b/binaries/arm/ip2net differ diff --git a/binaries/mips32r1-lsb/ip2net b/binaries/mips32r1-lsb/ip2net index 696e422..bc1f354 100755 Binary files a/binaries/mips32r1-lsb/ip2net and b/binaries/mips32r1-lsb/ip2net differ diff --git a/binaries/mips32r1-msb/ip2net b/binaries/mips32r1-msb/ip2net index 368fdf7..e367abf 100755 Binary files a/binaries/mips32r1-msb/ip2net and b/binaries/mips32r1-msb/ip2net differ diff --git a/binaries/mips64r2-msb/ip2net b/binaries/mips64r2-msb/ip2net index ffc362f..408ec4d 100755 Binary files a/binaries/mips64r2-msb/ip2net and b/binaries/mips64r2-msb/ip2net differ diff --git a/binaries/ppc/ip2net b/binaries/ppc/ip2net index 5b856eb..7c92ecb 100755 Binary files a/binaries/ppc/ip2net and b/binaries/ppc/ip2net differ diff --git a/binaries/x86/ip2net b/binaries/x86/ip2net index 32d53dc..1dfe3b8 100755 Binary files a/binaries/x86/ip2net and b/binaries/x86/ip2net differ diff --git a/binaries/x86_64/ip2net b/binaries/x86_64/ip2net index ef9fd6b..e15c7c6 100755 Binary files a/binaries/x86_64/ip2net and b/binaries/x86_64/ip2net differ diff --git a/ip2net/ip2net.c b/ip2net/ip2net.c index 2a83e34..6243a47 100644 --- a/ip2net/ip2net.c +++ b/ip2net/ip2net.c @@ -79,7 +79,7 @@ static uint32_t unique6(struct in6_addr *pu, uint32_t ct) } return i; } -static void mask_from_bitcount6(uint32_t zct, struct in6_addr *a) +static void mask_from_bitcount6_make(uint32_t zct, struct in6_addr *a) { if (zct >= 128) memset(a->s6_addr,0x00,16); @@ -91,6 +91,17 @@ static void mask_from_bitcount6(uint32_t zct, struct in6_addr *a) a->s6_addr[n] = ~((1 << (zct & 7)) - 1); } } +static struct in6_addr ip6_mask[129]; +static void mask_from_bitcount6_prepare() +{ + for (int zct=0;zct<=128;zct++) mask_from_bitcount6_make(zct, ip6_mask+zct); +} +static inline const struct in6_addr *mask_from_bitcount6(uint32_t zct) +{ + return ip6_mask+zct; +} + + // result = a & b static void ip6_and(const struct in6_addr *a, const struct in6_addr *b, struct in6_addr *result) { @@ -264,6 +275,7 @@ int main(int argc, char **argv) } gnu_quicksort(iplist, ipct, sizeof(*iplist), cmp6, NULL); ipct = unique6(iplist, ipct); + mask_from_bitcount6_prepare(); /* for(uint32_t i=0;i= params.zct_min; zct--) { - mask_from_bitcount6(zct, &mask); - ip6_and(iplist + pos, &mask, &ip_start); + mask = mask_from_bitcount6(zct); + ip6_and(iplist + pos, mask, &ip_start); for (p = pos + 1, ip_ct = 1; p < ipct; p++, ip_ct++) { - ip6_and(iplist + p, &mask, &ip); + ip6_and(iplist + p, mask, &ip); if (memcmp(&ip_start, &ip, sizeof(ip))) break; } @@ -303,11 +316,8 @@ int main(int argc, char **argv) } } if (zct_best) - { // network was found - mask_from_bitcount6(zct_best, &mask); - ip6_and(iplist + pos, &mask, &ip_start); - } + ip6_and(iplist + pos, mask_from_bitcount6(zct_best), &ip_start); else ip_start = iplist[pos], pos_end = pos + 1; // network not found, use single ip inet_ntop(AF_INET6, &ip_start, str, sizeof(str));