summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Ovsienko <denis@ovsienko.info>2020-10-01 15:17:10 +0100
committerDenis Ovsienko <denis@ovsienko.info>2020-10-01 17:02:43 +0100
commit63610e417b2d1bd99cb41e0bb5e129015b0aeb4e (patch)
treebf78650819139e82680546438d28b5197e0ffaa8
parente1fd57e0849de3b53eba7b380ce978f87de88e9c (diff)
downloadtcpdump-63610e417b2d1bd99cb41e0bb5e129015b0aeb4e.tar.gz
Fix a few bitmap printing bugs.
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.
-rw-r--r--print-aoe.c16
-rw-r--r--print-udld.c14
-rw-r--r--tests/aoe-oobr-1.out2
-rw-r--r--tests/udld-inf-loop-1-v.out2
-rw-r--r--tests/udld-v.out56
-rw-r--r--util-print.c53
6 files changed, 70 insertions, 73 deletions
diff --git a/print-aoe.c b/print-aoe.c
index 41f54b99..c4f3758f 100644
--- a/print-aoe.c
+++ b/print-aoe.c
@@ -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 */
diff --git a/print-udld.c b/print-udld.c
index 52ed7eff..d17e660b 100644
--- a/print-udld.c
+++ b/print-udld.c
@@ -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);
diff --git a/tests/aoe-oobr-1.out b/tests/aoe-oobr-1.out
index ce7039fe..602fe01d 100644
--- a/tests/aoe-oobr-1.out
+++ b/tests/aoe-oobr-1.out
@@ -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]
diff --git a/tests/udld-inf-loop-1-v.out b/tests/udld-inf-loop-1-v.out
index 08003ef5..f8b59d37 100644
--- a/tests/udld-inf-loop-1-v.out
+++ b/tests/udld-inf-loop-1-v.out
@@ -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
diff --git a/tests/udld-v.out b/tests/udld-v.out
index 66585dab..f996fd36 100644
--- a/tests/udld-v.out
+++ b/tests/udld-v.out
@@ -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
@@ -106,7 +106,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
- 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
@@ -115,7 +115,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
- 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
@@ -124,7 +124,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
- 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
@@ -133,7 +133,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
- 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
@@ -142,7 +142,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
- 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
@@ -151,7 +151,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
- 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
@@ -160,7 +160,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
- 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
@@ -169,7 +169,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
- 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
@@ -178,7 +178,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
- 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
@@ -187,7 +187,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
- 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
@@ -196,7 +196,7 @@
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
@@ -205,7 +205,7 @@
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
@@ -214,7 +214,7 @@
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
@@ -223,7 +223,7 @@
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
@@ -232,7 +232,7 @@
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
@@ -241,7 +241,7 @@
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
@@ -250,7 +250,7 @@
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
diff --git a/util-print.c b/util-print.c
index 00160b43..2524991b 100644
--- a/util-print.c
+++ b/util-print.c
@@ -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 */