summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDenis Ovsienko <infrastation@yandex.ru>2012-01-01 16:33:12 +0400
committerDenis Ovsienko <infrastation@yandex.ru>2012-01-01 16:37:39 +0400
commitbf19277c341e6c1b94046c628c0e6d0f0b20d536 (patch)
treed25071a4826b9966bfca1e13c29e1c913ba18723 /lib
parent7b0d1c6d31d50fbf74f84cb60daaedd904b35171 (diff)
Revert "lib: optimize apply_mask_ipv6()"
Experience with IPv4 counterpart of this function suggests, that this way of type-punning is likely to cause errors.
Diffstat (limited to 'lib')
-rw-r--r--lib/prefix.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index 54b9bc8a..f4b0c4f1 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -660,13 +660,23 @@ masklen2ip6 (const int masklen, struct in6_addr *netmask)
void
apply_mask_ipv6 (struct prefix_ipv6 *p)
{
- assert (p->prefixlen >= 0 && p->prefixlen <= IPV6_MAX_BITLEN);
- u_int32_t *addr_word = (u_int32_t *) &p->prefix;
- u_int32_t *mask_word = (u_int32_t *) (maskbytes6 + p->prefixlen);
- *addr_word++ &= *mask_word++;
- *addr_word++ &= *mask_word++;
- *addr_word++ &= *mask_word++;
- *addr_word &= *mask_word;
+ u_char *pnt;
+ int index;
+ int offset;
+
+ index = p->prefixlen / 8;
+
+ if (index < 16)
+ {
+ pnt = (u_char *) &p->prefix;
+ offset = p->prefixlen % 8;
+
+ pnt[index] &= maskbit[offset];
+ index++;
+
+ while (index < 16)
+ pnt[index++] = 0;
+ }
}
void