diff options
| author | Roy Marples <roy@marples.name> | 2020-02-07 12:18:46 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2020-02-07 12:18:46 +0000 |
| commit | 8a5eb28f5c9fa530fb33cae3913795389b1d0059 (patch) | |
| tree | 99fbb0d34b5d2b837d570e21186f1f1c7fe51489 /src/ipv6.c | |
| parent | 864db0c88090ac3e01fb5981f8ef98a9fc3c4744 (diff) | |
| download | dhcpcd-8a5eb28f5c9fa530fb33cae3913795389b1d0059.tar.xz | |
inet6: Calculate the prefix in the canonical form
Rather than being clever and getting it wrong.
Diffstat (limited to 'src/ipv6.c')
| -rw-r--r-- | src/ipv6.c | 23 |
1 files changed, 6 insertions, 17 deletions
@@ -380,25 +380,14 @@ ipv6_makeaddr(struct in6_addr *addr, struct interface *ifp, static int ipv6_makeprefix(struct in6_addr *prefix, const struct in6_addr *addr, int len) { - int bytes, bits; + struct in6_addr mask; + size_t i; - if (len < 0 || len > 128) { - errno = EINVAL; + if (ipv6_mask(&mask, len) == -1) return -1; - } - - bytes = len / NBBY; - bits = len % NBBY; - memcpy(&prefix->s6_addr, &addr->s6_addr, (size_t)bytes); - if (bits != 0) { - /* Coverify false positive. - * bytelen cannot be 16 if bitlen is non zero */ - /* coverity[overrun-local] */ - prefix->s6_addr[bytes] = - (uint8_t)(prefix->s6_addr[bytes] >> (NBBY - bits)); - } - memset((char *)prefix->s6_addr + bytes, 0, - sizeof(prefix->s6_addr) - (size_t)bytes); + *prefix = *addr; + for (i = 0; i < sizeof(prefix->s6_addr); i++) + prefix->s6_addr[i] &= mask.s6_addr[i]; return 0; } |
