]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix a few bitmap printing bugs.
authorDenis Ovsienko <[email protected]>
Thu, 1 Oct 2020 14:17:10 +0000 (15:17 +0100)
committerDenis Ovsienko <[email protected]>
Thu, 1 Oct 2020 16:02:43 +0000 (17:02 +0100)
bittok2str_internal() used to match on a single walking 1, so a bitmap
token that had more than one bit set would never "match all" or "match
any". Replace the bit-walking loop with a single bitwise test, that's
faster and it provides "match all" for multiple-bit tokens if required.
Also a 0 token would always match a 0 value, which makes no sense in
bitmaps, so fix a 0 token to never match. Update the comment and fixup
some indentation.

This change had immediately chased a bug out of print-udld.c, where the
tokens were wrong in udld_flags_values[]. Fix that, list the MBZ bits and
rename the array for clarity. Update output for two tests.

In the course of this debugging it became clear that in print-aoe.c I got
both the tokens and the labels wrong in aoev1_aflag_str[]. Fix that,
rename the listed MBZ bits for brevity and rename the array for clarity.
Update output for one test.

print-aoe.c
print-udld.c
tests/aoe-oobr-1.out
tests/udld-inf-loop-1-v.out
tests/udld-v.out
util-print.c

index 41f54b99380936e768532f8ce7784ba2353012eb..c4f3758f3dcbdec84e0f684ff5a25674df7cc05d 100644 (file)
@@ -72,8 +72,8 @@ static const struct tok cmdcode_str[] = {
 static const struct tok aoev1_flag_str[] = {
        { AOEV1_FLAG_R, "Response" },
        { AOEV1_FLAG_E, "Error"    },
-       { 0x02,         "MBZ-0x02" },
-       { 0x01,         "MBZ-0x01" },
+       { 0x02,         "MBZ-1"    },
+       { 0x01,         "MBZ-0"    },
        { 0, NULL }
 };
 
@@ -92,13 +92,13 @@ static const struct tok aoev1_errcode_str[] = {
 #define AOEV1_AFLAG_A 0x02
 #define AOEV1_AFLAG_W 0x01
 
-static const struct tok aoev1_aflag_str[] = {
-       { 0x08,          "MBZ-0x08" },
+static const struct tok aoev1_aflag_bitmap_str[] = {
+       { 0x80,          "MBZ-7"    },
        { AOEV1_AFLAG_E, "Ext48"    },
-       { 0x06,          "MBZ-0x06" },
+       { 0x20,          "MBZ-5"    },
        { AOEV1_AFLAG_D, "Device"   },
-       { 0x04,          "MBZ-0x04" },
-       { 0x03,          "MBZ-0x03" },
+       { 0x08,          "MBZ-3"    },
+       { 0x04,          "MBZ-2"    },
        { AOEV1_AFLAG_A, "Async"    },
        { AOEV1_AFLAG_W, "Write"    },
        { 0, NULL }
@@ -148,7 +148,7 @@ aoev1_issue_print(netdissect_options *ndo,
                goto invalid;
        /* AFlags */
        ND_PRINT("\n\tAFlags: [%s]",
-                bittok2str(aoev1_aflag_str, "none", GET_U_1(cp)));
+                bittok2str(aoev1_aflag_bitmap_str, "none", GET_U_1(cp)));
        cp += 1;
        len -= 1;
        /* Err/Feature */
index 52ed7eff9f5d4117ec9a07bf98df7282d55d1c0d..d17e660b35889ea14baef7cbe3239d7e7f664e3a 100644 (file)
@@ -57,9 +57,15 @@ static const struct tok udld_code_values[] = {
     { 0, NULL}
 };
 
-static const struct tok udld_flags_values[] = {
-    { 0x00, "RT"},
-    { 0x01, "RSY"},
+static const struct tok udld_flags_bitmap_str[] = {
+    { 1U << 0, "RT"    },
+    { 1U << 1, "RSY"   },
+    { 1U << 2, "MBZ-2" },
+    { 1U << 3, "MBZ-3" },
+    { 1U << 4, "MBZ-4" },
+    { 1U << 5, "MBZ-5" },
+    { 1U << 6, "MBZ-6" },
+    { 1U << 7, "MBZ-7" },
     { 0, NULL}
 };
 
@@ -112,7 +118,7 @@ udld_print(netdissect_options *ndo, const u_char *pptr, u_int length)
            UDLD_EXTRACT_VERSION(GET_U_1(tptr)),
            tok2str(udld_code_values, "Reserved", code),
            code,
-           bittok2str(udld_flags_values, "none", GET_U_1((tptr + 1))),
+           bittok2str(udld_flags_bitmap_str, "none", GET_U_1((tptr + 1))),
            GET_U_1((tptr + 1)),
            length);
 
index ce7039fec43da2b01a10f6e8328977e6ce675870..602fe01d0fc550b6c6aca1213fed9845a98d58a5 100644 (file)
@@ -1,3 +1,3 @@
-    1  06:58:21.1048579 AoE length 18, Ver 1, Flags: [Response, MBZ-0x02, MBZ-0x01]
+    1  06:58:21.1048579 AoE length 18, Ver 1, Flags: [Response, MBZ-1, MBZ-0]
        Major: 0x40f6, Minor: 0x02, Command: Reserve/Release, Tag: 0x01010101
        RCmd: Set reserve list, NMacs: 1 [|aoe]
index 08003ef5a7bccc31826124dd37d5f1f6e5d3d99d..f8b59d37af4a9661a11b99879a2e8edddbdc0df9 100644 (file)
@@ -1,4 +1,4 @@
-    1  11:15:30.259144 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+    1  11:15:30.259144 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x3956 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
index 66585dab9234195b1b688c2936c5008ccafe610f..f996fd36e6739cc146341fd5fc41d28328ed3887 100644 (file)
@@ -7,7 +7,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 1
-    2  11:14:12.244346 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    2  11:14:12.244346 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805d (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
@@ -16,7 +16,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 1
-    3  11:14:12.244696 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    3  11:14:12.244696 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805e (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
@@ -25,7 +25,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 1
-    4  11:14:12.633254 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    4  11:14:12.633254 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805c (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
@@ -34,7 +34,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 2
-    5  11:14:13.250690 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    5  11:14:13.250690 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805d (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
@@ -43,7 +43,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 2
-    6  11:14:13.631606 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    6  11:14:13.631606 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805b (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
@@ -52,7 +52,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 3
-    7  11:14:14.249094 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    7  11:14:14.249094 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805c (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
@@ -61,7 +61,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 3
-    8  11:14:14.629963 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    8  11:14:14.629963 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805a (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
@@ -70,7 +70,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 4
-    9  11:14:15.247436 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+    9  11:14:15.247436 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805b (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
@@ -79,7 +79,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 4
-   10  11:14:15.628301 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+   10  11:14:15.628301 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x8059 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
@@ -88,7 +88,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 5
-   11  11:14:16.245782 UDLDv1, Code Echo message (2), Flags [RT] (0x00), length 80
+   11  11:14:16.245782 UDLDv1, Code Echo message (2), Flags [none] (0x00), length 80
        Checksum 0x805a (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
@@ -97,7 +97,7 @@
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 5
-   12  11:14:16.635051 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   12  11:14:16.635051 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x795c (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 1
-   13  11:14:17.244147 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   13  11:14:17.244147 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x795d (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 1
-   14  11:14:23.631900 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   14  11:14:23.631900 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x795b (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 2
-   15  11:14:24.249530 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   15  11:14:24.249530 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x795c (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 2
-   16  11:14:30.637186 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   16  11:14:30.637186 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x795a (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 3
-   17  11:14:31.246440 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   17  11:14:31.246440 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x795b (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 3
-   18  11:14:37.634025 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   18  11:14:37.634025 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7959 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 4
-   19  11:14:38.251795 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   19  11:14:38.251795 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x795a (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 4
-   20  11:14:44.639308 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   20  11:14:44.639308 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7958 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 5
-   21  11:14:45.248751 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   21  11:14:45.248751 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7959 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 5
-   22  11:14:59.639781 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   22  11:14:59.639781 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7957 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 6
-   23  11:15:00.249419 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   23  11:15:00.249419 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7958 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 6
-   24  11:15:14.640244 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   24  11:15:14.640244 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7956 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 7
-   25  11:15:15.814760 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   25  11:15:15.814760 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7957 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 7
-   26  11:15:29.640733 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   26  11:15:29.640733 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7955 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 8
-   27  11:15:30.259144 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   27  11:15:30.259144 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7956 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S1
        Sequence Number TLV (0x0007) TLV, length 8, 8
-   28  11:15:44.641210 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   28  11:15:44.641210 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7954 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1025X4W3
        Port-ID TLV (0x0002) TLV, length 9, Fa0/1
        Timeout Interval TLV (0x0005) TLV, length 5, 5s
        Device Name TLV (0x0006) TLV, length 6, S2
        Sequence Number TLV (0x0007) TLV, length 8, 9
-   29  11:15:45.259800 UDLDv1, Code Probe message (1), Flags [RT, RSY] (0x01), length 80
+   29  11:15:45.259800 UDLDv1, Code Probe message (1), Flags [RT] (0x01), length 80
        Checksum 0x7955 (unverified)
        Device-ID TLV (0x0001) TLV, length 15, FOC1031Z7JG
        Port-ID TLV (0x0002) TLV, length 9, Gi0/1
index 00160b432d06a0f2a7d78c9319f7cb91ef8373b6..2524991b5517e220c90798ebbd965d455792354b 100644 (file)
@@ -533,6 +533,9 @@ tok2str(const struct tok *lp, const char *fmt,
  * Convert a bit token value to a string; use "fmt" if not found.
  * this is useful for parsing bitfields, the output strings are separated
  * if the s field is positive.
+ *
+ * A token matches iff it has one or more bits set and every bit that is set
+ * in the token is set in v. Consequently, a 0 token never matches.
  */
 static char *
 bittok2str_internal(const struct tok *lp, const char *fmt,
@@ -541,41 +544,29 @@ bittok2str_internal(const struct tok *lp, const char *fmt,
         static char buf[1024+1]; /* our string buffer */
         char *bufp = buf;
         size_t space_left = sizeof(buf), string_size;
-        u_int rotbit; /* this is the bit we rotate through all bitpositions */
-        u_int tokval;
         const char * sepstr = "";
 
-       while (lp != NULL && lp->s != NULL) {
-            tokval=lp->v;   /* load our first value */
-            rotbit=1;
-            while (rotbit != 0) {
-                /*
-                 * lets AND the rotating bit with our token value
-                 * and see if we have got a match
-                 */
-               if (tokval == (v&rotbit)) {
-                    /* ok we have found something */
-                    if (space_left <= 1)
-                        return (buf); /* only enough room left for NUL, if that */
-                    string_size = strlcpy(bufp, sepstr, space_left);
-                    if (string_size >= space_left)
-                        return (buf);    /* we ran out of room */
-                    bufp += string_size;
-                    space_left -= string_size;
-                    if (space_left <= 1)
-                        return (buf); /* only enough room left for NUL, if that */
-                    string_size = strlcpy(bufp, lp->s, space_left);
-                    if (string_size >= space_left)
-                        return (buf);    /* we ran out of room */
-                    bufp += string_size;
-                    space_left -= string_size;
-                    sepstr = sep;
-                    break;
-                }
-                rotbit=rotbit<<1; /* no match - lets shift and try again */
+        while (lp != NULL && lp->s != NULL) {
+            if (lp->v && (v & lp->v) == lp->v) {
+                /* ok we have found something */
+                if (space_left <= 1)
+                    return (buf); /* only enough room left for NUL, if that */
+                string_size = strlcpy(bufp, sepstr, space_left);
+                if (string_size >= space_left)
+                    return (buf);    /* we ran out of room */
+                bufp += string_size;
+                space_left -= string_size;
+                if (space_left <= 1)
+                    return (buf); /* only enough room left for NUL, if that */
+                string_size = strlcpy(bufp, lp->s, space_left);
+                if (string_size >= space_left)
+                    return (buf);    /* we ran out of room */
+                bufp += string_size;
+                space_left -= string_size;
+                sepstr = sep;
             }
             lp++;
-       }
+        }
 
         if (bufp == buf)
             /* bummer - lets print the "unknown" message as advised in the fmt string if we got one */