Wireshark-dev: [Wireshark-dev] Beginners help. How to add additional subtrees ?

From: "Jan Kokott" <Blind007@xxxxxx>
Date: Fri, 19 Jan 2007 11:12:49 +0100
Hi,

My 802.15.4 plugin starts working, but as a newbie to C it�s still quite difficult to deal with the idea of pointer. :(
For starting the plugin I just reused the rudp plugin, so at the moment I implemented the Frame Control field and Addressing field of Zigbee under UDP at an virtual udp port.

I wanted to add 2 sub_tree and a single item to my dissector, but it doesn�t add the second subtree (adressing field).
the first one is displayed correctly and the "Sequence Number Field" added after the first sub_tree also works.

/*I defined all the fields with*/
static int hf_zigbee_frame = -1; ...and so on.

/*Then added all three fields*/
static gint ett_zigbee = -1;

static gint ett_zigbee_frame = -1;
static gint ett_zigbee_adr = -1;

tvbuff_t * next_tvb = NULL;
proto_tree *zigbee_tree = NULL, *frame_tree, *adr_tree;
proto_item *ti = NULL;

/*Tree*/
ti = proto_tree_add_item(tree, proto_zigbee, tvb, 0, hlen, FALSE);
zigbee_tree = proto_item_add_subtree(ti, ett_zigbee);

/*1.sub_tree*/
ti = proto_tree_add_item(zigbee_tree, hf_zigbee_frame, tvb, 0, 2, FALSE);
frame_tree = proto_item_add_subtree(ti, ett_zigbee_frame);
/*(filled with for ())*/

/*Then added the single field without any subtree*/
proto_tree_add_item(zigbee_tree, hf_zigbee_seq, tvb, 2, 1, FALSE);

/*And then just added the next subtree*/
ti = proto_tree_add_item(zigbee_tree, hf_zigbee_adr, tvb, 3, hlen, FALSE);
adr_tree = proto_item_add_subtree(ti, ett_zigbee_adr);
/*(again another for() to fill in the fields)*/


*/Defined all the field info in proto_register_zigbee(void)*/

/*Added the field array*/
static gint *ett[] = {
		&ett_zigbee,
		&ett_zigbee_frame,
		&ett_zigbee_adr,};

/*And registered them */
proto_register_field_array(proto_zigbee, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));

That isn�t the full code but should be the interesting part for the subtree.
Why does the first sub_tree work and the second is just displayed as a single Item with 20 bytes length ?

I think my problem is with the registration of the second sub_tree or with the pointer on ti or the tree.

Regards
Jan