ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] Is there a good way of handling bitfields with different bit

From: Stephen Fisher <stephentfisher@xxxxxxxxx>
Date: Tue, 13 Nov 2007 16:47:21 -0700
On Mon, Nov 12, 2007 at 06:01:09PM -0000, Neil Piercy wrote:

> If the protocol has bitfields they can be defined in the hf structs,
> but what is the best way to cope if these fields can be at different
> bit offsets within the byte ? E.g. a 4 bit field which can occur as
> the lower 4 bits or the upper 4 bits of a byte.

You can pass a bitfield mask in hex in the hf_ field setup, for example:

      { &hf_vnc_button_8_pos,
        { "Mouse button #8 position", "vnc.button_8_pos",
          FT_UINT8, BASE_DEC, VALS(&button_mask_vs), 0x80,
          "Whether mouse button #8 is being pressed or not", HFILL }
      },

0x80 = 0000 0001, so it will match the rightmost bit only.  You can
match the rightmost 4 bits by using binary 0000 1111 = 0xF or the
leftmost 4 bits by using binary 1111 0000 = 0xF0.  Is this what you are
looking for?


Steve