net/utils: Fix the wrong mask calculation in net_ipv6_pref2mask

This commit is contained in:
Xiang Xiao 2020-01-30 16:22:18 +08:00 committed by Gregory Nutt
parent 174df6b793
commit b80fb6befc
3 changed files with 3 additions and 8 deletions

View File

@ -39,9 +39,6 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h>
#include <arpa/inet.h>
#include "utils/utils.h" #include "utils/utils.h"
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
@ -71,7 +68,7 @@ static const uint8_t g_nibblemap[16] =
static inline uint8_t net_msbits4(uint8_t nibble) static inline uint8_t net_msbits4(uint8_t nibble)
{ {
/* Return the number of leading zeroes: 0-4) */ /* Return the number of leading ones: 0-4) */
return g_nibblemap[nibble]; return g_nibblemap[nibble];
} }

View File

@ -41,8 +41,6 @@
#include <nuttx/net/ip.h> #include <nuttx/net/ip.h>
#include "utils/utils.h"
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
/**************************************************************************** /****************************************************************************

View File

@ -101,12 +101,12 @@ void net_ipv6_pref2mask(uint8_t preflen, net_ipv6addr_t mask)
else else
{ {
/* Eg. preflen = 38, bit = {32} /* Eg. preflen = 38, bit = {32}
* bit - preflen = 6 * preflen - bit = 6
* mask = 0xffff << (16-6) * mask = 0xffff << (16-6)
* = 0xfc00 * = 0xfc00
*/ */
mask[i] = 0xffff << (16 - (bit - preflen)); mask[i] = 0xffff << (16 - (preflen - bit));
} }
} }
else else