Type for Dissecting n-bit Quantities
EDIT: Is it possible to just parse a large portion of a header to fit into a standard size, and then just mask from there? For example, for a 40 bit header, I could break that into two 'segments', one of 32 bit size, one of 8 bit size. If I then use a pointer to the same reference point, can I then use different masks to parse out different pieces of that 32 bit size to recover the original field?
To be more concrete, let me walk through an example of what I mean.
Assume I have a 40 bit header, foo, with the following fields:
bit<2> version
bit<1> bypass
bit<1> command_flag
.... (skipping until the end of 32 bits for concision)
bit<8> sequuence_number
Assume that the fields have been defined in similar order in the dissector:
static int hf_foo_version = -1;
static int hf_foo_bypass = -1;
static int hf_foo_cmd_flag = -1;
...
static int foo_sequence_number = -1;
Can I do something like the following?
/*inside the proto_register_foo function*/
static hf_register_info hf[] = {
{ &hf_foo_version,
{ "Version", "foo.version",
FT_UINT32, BASE_DEC,
NULL, 0x03,
NULL, HFILL }
}
};
static hf_register_info hf[] = {
{ &hf_foo_version,
{ "Bypass", "foo.bypass",
FT_UINT32, BASE_DEC,
NULL, 0x07,
NULL, HFILL }
}
};
and so on, to parse each field out of the 32 bit selection, offset from the same pointer?
Original question below for more background - if you can answer the rephrasing of the question in this edit, though, then I can potentially remove the original question and use this rephrasing.
================================================================================
Hello. I am in the middle of writing dissector for a custom protocol encapsulating ethernet/ipv4. The protocol has two headers. The first header is 5 bytes in length while the second header is 1 byte in length. However, those bytes are not evenly divided.
For example, let's call the first header Foo, to be consistent with the Developer's Guide. Foo has many fields of varying sizes - 1,2,6,8, and 10 bit fields.
From reading README.developer, I can guess that for the 1 bit fields I can use things like gboolean for 1 bit and guint8 for 8 bit fields. I've been given a template that uses an FT_ prefix instead of the g prefix - for example, it uses FT_Boolean and FT_UINT8 instead for the previous types.
I am trying to follow the example given in section 9.2 of the Wireshark Developer's Guide - specifically, I'm currently looking at the section containing the following code for dissecting specific fields:
static hf_register_info hf[] = {
{ &hf_foo_pdu_type,
{ "FOO PDU Type", "foo.type",
FT_UINT8, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
}
};
One example field in my custom protocol is a 2-bit sequence flag field. In my code, this looks like:
/* defined earlier in the actual file, included here for reference */
static const value_string foo_sequence_flags[] = {
{... /*omitted for concision as at this point, I cannot handle segmented data*/},
{3, "Unsegmented data" },
{0, NULL }
};
/* also defined earlier, included for reference.*/
static int hf_foo_seq_flags = -1
/*inside the proto_register_foo function*/
static hf_register_info hf[] = {
{ &hf_foo_seq_flags,
{ "Sequence Flags", "foo.seq_flags",
<unknown type here>, BASE_DEC,
VALS(foo_sequence_flags), 0b11 ...
(I'm not a developer so take with a grain of NaCl)
1.
packet-ieee80211.c
has 2 and 4 bit fields inproto_register_ieee80211()
that are put inFT_UINT8
.2. See
README.dissector
forFT_
definitions.3.
HFILL
is mentioned inREADME.dissector
:And defined in
epan/proto.h
:3b. Header fields defined in
epan/proto.h
: