From: Denis Ovsienko Date: Tue, 2 Feb 2021 00:25:25 +0000 (+0000) Subject: ZMTP: Replace custom code with bittok2str(). X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/9e651c514c58898c781639ec56f9ee4fa6a66b23 ZMTP: Replace custom code with bittok2str(). --- diff --git a/CHANGES b/CHANGES index 19fd8f01..4ca901d2 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ Monthday, Month DD, YYYY by gharris and denis OSPF: Update to match the Router Properties registry. MPLS: Rename the "exp" field to "tc". VQP: Do not print unknown error codes twice. + ZMTP: Replace custom code with bittok2str(). Source code: Use %zu when printing a sizeof to squelch compiler warnings (FIXME: somebody please wrap the line below just before the release) diff --git a/print-zeromq.c b/print-zeromq.c index c7020468..cdeecff8 100644 --- a/print-zeromq.c +++ b/print-zeromq.c @@ -26,6 +26,7 @@ */ /* \summary: ZeroMQ Message Transport Protocol (ZMTP) printer */ +/* specification: https://rfc.zeromq.org/spec/13/ */ #ifdef HAVE_CONFIG_H #include @@ -42,6 +43,18 @@ */ #define VBYTES 128 +static const struct tok flags_bm[] = { + { 0x01, "MORE" }, + { 0x02, "R1" }, + { 0x04, "R2" }, + { 0x08, "R3" }, + { 0x10, "R4" }, + { 0x20, "R5" }, + { 0x40, "R6" }, + { 0x80, "R7" }, + { 0, NULL } +}; + /* * Below is an excerpt from the "13/ZMTP" specification: * @@ -104,16 +117,7 @@ zmtp1_print_frame(netdissect_options *ndo, const u_char *cp, const u_char *ep) if (ndo->ndo_vflag) { uint64_t body_len_printed = ND_MIN(body_len_captured, body_len_declared); - ND_PRINT(" (%s|%s|%s|%s|%s|%s|%s|%s)", - flags & 0x80 ? "MBZ" : "-", - flags & 0x40 ? "MBZ" : "-", - flags & 0x20 ? "MBZ" : "-", - flags & 0x10 ? "MBZ" : "-", - flags & 0x08 ? "MBZ" : "-", - flags & 0x04 ? "MBZ" : "-", - flags & 0x02 ? "MBZ" : "-", - flags & 0x01 ? "MORE" : "-"); - + ND_PRINT(" (%s)", bittok2str(flags_bm, "none", flags)); if (ndo->ndo_vflag == 1) body_len_printed = ND_MIN(VBYTES + 1, body_len_printed); if (body_len_printed > 1) { diff --git a/tests/epgm_zmtp1v.out b/tests/epgm_zmtp1v.out index b9237d22..54f8d1af 100644 --- a/tests/epgm_zmtp1v.out +++ b/tests/epgm_zmtp1v.out @@ -11,7 +11,7 @@ 6 17:10:27.456516 IP (tos 0xb8, ttl 16, id 0, offset 0, flags [DF], proto UDP (17), length 1480) 10.0.0.45.40251 > 239.255.0.16.5563: 39236 > 5563: PGM, length 1428 0x47e3fdad9a9c ODATA trail 0 seq 282 [1452] frame offset 0x0000 - frame flags+body (8-bit) length 116, flags 0x00 (-|-|-|-|-|-|-|-), first 115 byte(s) of body: + frame flags+body (8-bit) length 116, flags 0x00 (none), first 115 byte(s) of body: 0x0000: 5468 6973 2069 7320 6120 7368 6f72 7420 This.is.a.short. 0x0010: 4153 4349 4920 6d65 7373 6167 6520 666f ASCII.message.fo 0x0020: 6c6c 6f77 6564 2062 7920 6120 7368 6f72 llowed.by.a.shor @@ -20,9 +20,9 @@ 0x0050: 206d 6573 7361 6765 2061 6e64 2061 2073 .message.and.a.s 0x0060: 686f 7274 2041 5343 4949 206d 6573 7361 hort.ASCII.messa 0x0070: 6765 2e ge. - frame flags+body (8-bit) length 17, flags 0x00 (-|-|-|-|-|-|-|-), first 16 byte(s) of body: + frame flags+body (8-bit) length 17, flags 0x00 (none), first 16 byte(s) of body: 0x0000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................ - frame flags+body (64-bit) length 2790 (1282 captured), flags 0x00 (-|-|-|-|-|-|-|-), first 128 byte(s) of body: + frame flags+body (64-bit) length 2790 (1282 captured), flags 0x00 (none), first 128 byte(s) of body: 0x0000: 5468 6520 7175 6963 6b20 6272 6f77 6e20 The.quick.brown. 0x0010: 666f 7820 6a75 6d70 7320 6f76 6572 2074 fox.jumps.over.t 0x0020: 6865 206c 617a 7920 646f 672e 2054 6865 he.lazy.dog..The @@ -53,7 +53,7 @@ 0x0030: 6272 6f77 6e20 666f 7820 6a75 6d70 7320 brown.fox.jumps. 0x0040: 6f76 6572 2074 6865 206c 617a 7920 646f over.the.lazy.do 0x0050: 672e g. - frame flags+body (8-bit) length 36, flags 0x00 (-|-|-|-|-|-|-|-), first 35 byte(s) of body: + frame flags+body (8-bit) length 36, flags 0x00 (none), first 35 byte(s) of body: 0x0000: 5468 6973 2069 7320 7468 6520 7472 6169 This.is.the.trai 0x0010: 6c69 6e67 2041 5343 4949 206d 6573 7361 ling.ASCII.messa 0x0020: 6765 2e ge. diff --git a/tests/pgm_zmtp1v.out b/tests/pgm_zmtp1v.out index e5d6a712..ed14deb4 100644 --- a/tests/pgm_zmtp1v.out +++ b/tests/pgm_zmtp1v.out @@ -7,7 +7,7 @@ 4 16:21:12.548313 IP (tos 0xb8, ttl 16, id 0, offset 0, flags [DF], proto PGM (113), length 1480) 10.0.0.45 > 239.255.0.16: 10.0.0.45.13320 > 239.255.0.16.5563: PGM, length 1436 0x3329041eba74 ODATA trail 21618 seq 54951 [1460] frame offset 0x0000 - frame flags+body (8-bit) length 116, flags 0x00 (-|-|-|-|-|-|-|-), first 115 byte(s) of body: + frame flags+body (8-bit) length 116, flags 0x00 (none), first 115 byte(s) of body: 0x0000: 5468 6973 2069 7320 6120 7368 6f72 7420 This.is.a.short. 0x0010: 4153 4349 4920 6d65 7373 6167 6520 666f ASCII.message.fo 0x0020: 6c6c 6f77 6564 2062 7920 6120 7368 6f72 llowed.by.a.shor @@ -16,9 +16,9 @@ 0x0050: 206d 6573 7361 6765 2061 6e64 2061 2073 .message.and.a.s 0x0060: 686f 7274 2041 5343 4949 206d 6573 7361 hort.ASCII.messa 0x0070: 6765 2e ge. - frame flags+body (8-bit) length 17, flags 0x00 (-|-|-|-|-|-|-|-), first 16 byte(s) of body: + frame flags+body (8-bit) length 17, flags 0x00 (none), first 16 byte(s) of body: 0x0000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................ - frame flags+body (64-bit) length 2790 (1290 captured), flags 0x00 (-|-|-|-|-|-|-|-), first 128 byte(s) of body: + frame flags+body (64-bit) length 2790 (1290 captured), flags 0x00 (none), first 128 byte(s) of body: 0x0000: 5468 6520 7175 6963 6b20 6272 6f77 6e20 The.quick.brown. 0x0010: 666f 7820 6a75 6d70 7320 6f76 6572 2074 fox.jumps.over.t 0x0020: 6865 206c 617a 7920 646f 672e 2054 6865 he.lazy.dog..The @@ -48,7 +48,7 @@ 0x0020: 6272 6f77 6e20 666f 7820 6a75 6d70 7320 brown.fox.jumps. 0x0030: 6f76 6572 2074 6865 206c 617a 7920 646f over.the.lazy.do 0x0040: 672e g. - frame flags+body (8-bit) length 36, flags 0x00 (-|-|-|-|-|-|-|-), first 35 byte(s) of body: + frame flags+body (8-bit) length 36, flags 0x00 (none), first 35 byte(s) of body: 0x0000: 5468 6973 2069 7320 7468 6520 7472 6169 This.is.the.trai 0x0010: 6c69 6e67 2041 5343 4949 206d 6573 7361 ling.ASCII.messa 0x0020: 6765 2e ge. diff --git a/tests/zmtp1.out b/tests/zmtp1.out index 763dd50e..25ebca82 100644 --- a/tests/zmtp1.out +++ b/tests/zmtp1.out @@ -6,18 +6,18 @@ 127.0.0.1.55358 > 127.0.0.1.33000: Flags [.], cksum 0xfe28 (incorrect -> 0x19da), ack 1, win 257, options [nop,nop,TS val 245537399 ecr 245537399], length 0 4 12:04:12.420115 IP (tos 0x0, ttl 64, id 17995, offset 0, flags [DF], proto TCP (6), length 54) 127.0.0.1.55358 > 127.0.0.1.33000: Flags [P.], cksum 0xfe2a (incorrect -> 0x18d0), seq 1:3, ack 1, win 257, options [nop,nop,TS val 245537399 ecr 245537399], length 2: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x00 (-|-|-|-|-|-|-|-) + frame flags+body (8-bit) length 1, flags 0x00 (none) 5 12:04:12.420121 IP (tos 0x0, ttl 64, id 51304, offset 0, flags [DF], proto TCP (6), length 52) 127.0.0.1.33000 > 127.0.0.1.55358: Flags [.], cksum 0xfe28 (incorrect -> 0x19d9), ack 3, win 256, options [nop,nop,TS val 245537399 ecr 245537399], length 0 6 12:04:12.420129 IP (tos 0x0, ttl 64, id 51305, offset 0, flags [DF], proto TCP (6), length 54) 127.0.0.1.33000 > 127.0.0.1.55358: Flags [P.], cksum 0xfe2a (incorrect -> 0x18cf), seq 1:3, ack 3, win 256, options [nop,nop,TS val 245537399 ecr 245537399], length 2: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x00 (-|-|-|-|-|-|-|-) + frame flags+body (8-bit) length 1, flags 0x00 (none) 7 12:04:12.420138 IP (tos 0x0, ttl 64, id 17996, offset 0, flags [DF], proto TCP (6), length 52) 127.0.0.1.55358 > 127.0.0.1.33000: Flags [.], cksum 0xfe28 (incorrect -> 0x19d6), ack 3, win 257, options [nop,nop,TS val 245537399 ecr 245537399], length 0 8 12:04:12.420189 IP (tos 0x0, ttl 64, id 17997, offset 0, flags [DF], proto TCP (6), length 148) 127.0.0.1.55358 > 127.0.0.1.33000: Flags [P.], cksum 0xfe88 (incorrect -> 0x11da), seq 3:99, ack 3, win 257, options [nop,nop,TS val 245537399 ecr 245537399], length 96: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x01 (-|-|-|-|-|-|-|MORE) - frame flags+body (8-bit) length 93, flags 0x00 (-|-|-|-|-|-|-|-), first 92 byte(s) of body: + frame flags+body (8-bit) length 1, flags 0x01 (MORE) + frame flags+body (8-bit) length 93, flags 0x00 (none), first 92 byte(s) of body: 0x0000: 5468 6973 2069 7320 6120 7368 6f72 7420 This.is.a.short. 0x0010: 4153 4349 4920 6d65 7373 6167 6520 666f ASCII.message.fo 0x0020: 6c6c 6f77 6564 2062 7920 6120 7368 6f72 llowed.by.a.shor @@ -26,25 +26,25 @@ 0x0050: 4349 4920 6d65 7373 6167 652e CII.message. 9 12:04:12.420352 IP (tos 0x0, ttl 64, id 51306, offset 0, flags [DF], proto TCP (6), length 84) 127.0.0.1.33000 > 127.0.0.1.55358: Flags [P.], cksum 0xfe48 (incorrect -> 0xc80f), seq 3:35, ack 99, win 256, options [nop,nop,TS val 245537399 ecr 245537399], length 32: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x01 (-|-|-|-|-|-|-|MORE) - frame flags+body (8-bit) length 29, flags 0x00 (-|-|-|-|-|-|-|-), first 28 byte(s) of body: + frame flags+body (8-bit) length 1, flags 0x01 (MORE) + frame flags+body (8-bit) length 29, flags 0x00 (none), first 28 byte(s) of body: 0x0000: 5468 6973 2069 7320 6120 7368 6f72 7420 This.is.a.short. 0x0010: 4153 4349 4920 7265 706c 792e ASCII.reply. 10 12:04:12.420442 IP (tos 0x0, ttl 64, id 17998, offset 0, flags [DF], proto TCP (6), length 72) 127.0.0.1.55358 > 127.0.0.1.33000: Flags [P.], cksum 0xfe3c (incorrect -> 0xcef8), seq 99:119, ack 35, win 257, options [nop,nop,TS val 245537399 ecr 245537399], length 20: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x01 (-|-|-|-|-|-|-|MORE) - frame flags+body (8-bit) length 17, flags 0x00 (-|-|-|-|-|-|-|-), first 16 byte(s) of body: + frame flags+body (8-bit) length 1, flags 0x01 (MORE) + frame flags+body (8-bit) length 17, flags 0x00 (none), first 16 byte(s) of body: 0x0000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................ 11 12:04:12.420526 IP (tos 0x0, ttl 64, id 51307, offset 0, flags [DF], proto TCP (6), length 84) 127.0.0.1.33000 > 127.0.0.1.55358: Flags [P.], cksum 0xfe48 (incorrect -> 0xc7da), seq 35:67, ack 119, win 256, options [nop,nop,TS val 245537400 ecr 245537399], length 32: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x01 (-|-|-|-|-|-|-|MORE) - frame flags+body (8-bit) length 29, flags 0x00 (-|-|-|-|-|-|-|-), first 28 byte(s) of body: + frame flags+body (8-bit) length 1, flags 0x01 (MORE) + frame flags+body (8-bit) length 29, flags 0x00 (none), first 28 byte(s) of body: 0x0000: 5468 6973 2069 7320 6120 7368 6f72 7420 This.is.a.short. 0x0010: 4153 4349 4920 7265 706c 792e ASCII.reply. 12 12:04:12.420620 IP (tos 0x0, ttl 64, id 17999, offset 0, flags [DF], proto TCP (6), length 603) 127.0.0.1.55358 > 127.0.0.1.33000: Flags [P.], cksum 0x0050 (incorrect -> 0xafc1), seq 119:670, ack 67, win 257, options [nop,nop,TS val 245537400 ecr 245537400], length 551: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x01 (-|-|-|-|-|-|-|MORE) - frame flags+body (64-bit) length 540, flags 0x00 (-|-|-|-|-|-|-|-), first 128 byte(s) of body: + frame flags+body (8-bit) length 1, flags 0x01 (MORE) + frame flags+body (64-bit) length 540, flags 0x00 (none), first 128 byte(s) of body: 0x0000: 5468 6520 7175 6963 6b20 6272 6f77 6e20 The.quick.brown. 0x0010: 666f 7820 6a75 6d70 7320 6f76 6572 2074 fox.jumps.over.t 0x0020: 6865 206c 617a 7920 646f 672e 2054 6865 he.lazy.dog..The @@ -55,8 +55,8 @@ 0x0070: 6d70 7320 6f76 6572 2074 6865 206c 617a mps.over.the.laz 13 12:04:12.420759 IP (tos 0x0, ttl 64, id 51308, offset 0, flags [DF], proto TCP (6), length 84) 127.0.0.1.33000 > 127.0.0.1.55358: Flags [P.], cksum 0xfe48 (incorrect -> 0xc592), seq 67:99, ack 670, win 256, options [nop,nop,TS val 245537400 ecr 245537400], length 32: ZMTP/1.0 - frame flags+body (8-bit) length 1, flags 0x01 (-|-|-|-|-|-|-|MORE) - frame flags+body (8-bit) length 29, flags 0x00 (-|-|-|-|-|-|-|-), first 28 byte(s) of body: + frame flags+body (8-bit) length 1, flags 0x01 (MORE) + frame flags+body (8-bit) length 29, flags 0x00 (none), first 28 byte(s) of body: 0x0000: 5468 6973 2069 7320 6120 7368 6f72 7420 This.is.a.short. 0x0010: 4153 4349 4920 7265 706c 792e ASCII.reply. 14 12:04:12.420972 IP (tos 0x0, ttl 64, id 18000, offset 0, flags [DF], proto TCP (6), length 52)