User Guide
FALSE we'll ignore for now.
After this change, there should be a label in the detailed display for the protocol, and selecting this
will highlight the remaining contents of the packet.
Now let's go to the next step and add some protocol dissection. For this step we'll need to construct a
couple of tables that help with dissection. This needs some changes to proto_register_foo. First a
couple of statically declare arrays.
Example 9.5. Registering data structures.
static hf_register_info hf[] = {
{ &hf_foo_pdu_type,
{ "FOO PDU Type", "foo.type",
FT_UINT8, BASE_DEC,
NULL, 0x0,
NULL, HFILL }
}
};
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_foo
};
Then, after the registration code, we register these arrays.
Example 9.6. Registering data structures.
proto_register_field_array(proto_foo, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
The variables hf_foo_pdu_type and ett_foo also need to be declared somewhere near the top of the
file.
Example 9.7. Dissector data structure globals.
static int hf_foo_pdu_type = -1;
static gint ett_foo = -1;
Now we can enhance the protocol display with some detail.
Example 9.8. Dissector starting to dissect the packets.
if (tree) { /* we are being asked for details */
proto_item *ti = NULL;
proto_tree *foo_tree = NULL;
ti = proto_tree_add_item(tree, proto_foo, tvb, 0, -1, FALSE);
foo_tree = proto_item_add_subtree(ti, ett_foo);
proto_tree_add_item(foo_tree, hf_foo_pdu_type, tvb, 0, 1, FALSE);
Packet dissection
104