net/icmpv6: Fix net mask logic in icmpv6_setaddresses

1. Both IPv6 addresses and net masks should be stored in network byte
   order
2. Fix last 2 bytes of mask applying (although it seldom triggers)

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2023-10-24 17:09:01 +08:00 committed by Alan Carvalho de Assis
parent 6e9cd74e81
commit ef1ad691c3
2 changed files with 2 additions and 2 deletions

View File

@ -110,7 +110,7 @@ void icmpv6_setaddresses(FAR struct net_driver_s *dev,
/* Copy prefix to the current IPv6 address, applying the mask */
for (i = 0; i < 7; i++)
for (i = 0; i < 8; i++)
{
dev->d_ipv6addr[i] = (dev->d_ipv6addr[i] & ~dev->d_ipv6netmask[i]) |
(prefix[i] & dev->d_ipv6netmask[i]);

View File

@ -91,7 +91,7 @@ void net_ipv6_pref2mask(uint8_t preflen, net_ipv6addr_t mask)
* = 0xfc00
*/
mask[i] = 0xffff << (16 - (preflen - bit));
mask[i] = HTONS(0xffff << (16 - (preflen - bit)));
}
}
else