]> granicus.if.org Git - libnl/commitdiff
Fix mask calculation in nl_addr_cmp_prefix()
authorThomas Graf <tgraf@suug.ch>
Thu, 31 Jan 2013 09:59:10 +0000 (10:59 +0100)
committerThomas Graf <tgraf@suug.ch>
Thu, 31 Jan 2013 09:59:10 +0000 (10:59 +0100)
Signed-off-by: Malte Langermann <mlangermann@radiodata.biz>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
lib/addr.c

index 806664b0f3ae5e0a0c3754e89857ef4ac5516f23..9089be8933e3b316ab51f7bdc419317913ef70da 100644 (file)
@@ -525,8 +525,8 @@ int nl_addr_cmp_prefix(struct nl_addr *a, struct nl_addr *b)
                int bytes = len / 8;
 
                d = memcmp(a->a_addr, b->a_addr, bytes);
-               if (d == 0) {
-                       int mask = (1UL << (len % 8)) - 1UL;
+               if (d == 0 && (len % 8) != 0) {
+                       int mask = (0xFF00 >> (len % 8)) & 0xFF;
 
                        d = (a->a_addr[bytes] & mask) -
                            (b->a_addr[bytes] & mask);