This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Dynamically add subtrees

0

I'm coding a dissector and want to dynamically add subtrees depending on number of parameters detected in the packet. Is there a way to do that?

asked 04 Jul '13, 04:59

Andrey's gravatar image

Andrey
21447
accept rate: 50%

I'm not certain of your question, most dissectors do something like that anyway as they dissect the packet.

Can you explain with some more detail what you want to achieve?

(04 Jul '13, 05:22) grahamb ♦

Packet from the application can have variable length and can accommodate from 0 to 255 parameters. I want my dissector to make a subtree for each parameter having subitems which split parameters into searchable fields.

(04 Jul '13, 05:24) Andrey

This all seems very normal, just create subtrees as required and then populate them with data items.

Subtrees are for presentation layout in the packet details pane, the hf structures determine what is filterable.

(04 Jul '13, 06:25) grahamb ♦

As I understood I have to define new proto_itme for each subtree. I can't understand how to get a new one in a loop, since I have same variable.

(04 Jul '13, 06:36) Andrey

I just made an array of proto_item of size 255. Is it fine to do that?

(04 Jul '13, 06:59) Andrey

If it's on the stack, that'll be fine. If you allocate it some way then you'll have to make sure it's freed correctly.

(04 Jul '13, 07:02) grahamb ♦
showing 5 of 6 show 1 more comments

One Answer:

0

Found a better solution. Moved recurrent dissection routine to dedicated function providing it the same tree and calling it in a variable loop (which depends on number it dissects earlier). In this case I don't have to keep handles for items in array.

answered 09 Jul '13, 05:09

Andrey's gravatar image

Andrey
21447
accept rate: 50%