You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/01/30 13:39:39 UTC

[incubator-nuttx] 03/03: Fix the wrong mask calculation in net_ipv6_pref2mask

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr185
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 5b3c16f77d6865537d78ad7f13305d7a6e9391de
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Jan 30 16:22:18 2020 +0800

    Fix the wrong mask calculation in net_ipv6_pref2mask
    
    Change-Id: Id1a281a3f4d4e4c182848a9de96752ab72ad4529
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 net/utils/net_ipv6_mask2pref.c | 5 +----
 net/utils/net_ipv6_maskcmp.c   | 2 --
 net/utils/net_ipv6_pref2mask.c | 4 ++--
 3 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/net/utils/net_ipv6_mask2pref.c b/net/utils/net_ipv6_mask2pref.c
index 7800900..562fe40 100644
--- a/net/utils/net_ipv6_mask2pref.c
+++ b/net/utils/net_ipv6_mask2pref.c
@@ -39,9 +39,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdint.h>
-#include <arpa/inet.h>
-
 #include "utils/utils.h"
 
 #ifdef CONFIG_NET_IPv6
@@ -71,7 +68,7 @@ static const uint8_t g_nibblemap[16] =
 
 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];
 }
diff --git a/net/utils/net_ipv6_maskcmp.c b/net/utils/net_ipv6_maskcmp.c
index 34d86e1..e8f7e00 100644
--- a/net/utils/net_ipv6_maskcmp.c
+++ b/net/utils/net_ipv6_maskcmp.c
@@ -41,8 +41,6 @@
 
 #include <nuttx/net/ip.h>
 
-#include "utils/utils.h"
-
 #ifdef CONFIG_NET_IPv6
 
 /****************************************************************************
diff --git a/net/utils/net_ipv6_pref2mask.c b/net/utils/net_ipv6_pref2mask.c
index 56dc444..f7521f6 100644
--- a/net/utils/net_ipv6_pref2mask.c
+++ b/net/utils/net_ipv6_pref2mask.c
@@ -101,12 +101,12 @@ void net_ipv6_pref2mask(uint8_t preflen, net_ipv6addr_t mask)
           else
             {
               /* Eg. preflen = 38, bit = {32}
-               *     bit - preflen = 6
+               *     preflen - bit = 6
                *     mask = 0xffff << (16-6)
                *          = 0xfc00
                */
 
-              mask[i]  = 0xffff << (16 - (bit - preflen));
+              mask[i] = 0xffff << (16 - (preflen - bit));
             }
         }
       else