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

replacement of proto_tree_add_text()

0

is there any function other than proto_tree_add_item() in the new API, which could easily be implemented as a replacement of proto_tree_add_text()? especially for printf style implementation of proto_tree_add_text() for example :

proto_tree_add_text(command_tree, tvb, 14, 1, "Roof Shed:\t\t%s", try_val_to_str(getbits(tvb_get_guint8(tvb, 14), 5, 2), discrete_status_var));

asked 14 Dec '16, 03:46

xaheen's gravatar image

xaheen
71141519
accept rate: 50%

edited 14 Dec '16, 05:20

grahamb's gravatar image

grahamb ♦
19.8k330206


One Answer:

1

What's wrong with proto_tree_add_bits_item(command_tree, hf_roof_shed, tvb, 14<<3+5, 2, ENC_BIG_ENDIAN);

{ &hf_roof_shed, { "Roof Shed", "x.roof_shed", FT_UINT8, BASE_DEC, VALS(discrete_status_var), 0x0, NULL, HFILL }},

answered 14 Dec '16, 04:35

Anders's gravatar image

Anders ♦
4.6k952
accept rate: 17%

Thanks. I will try it. But it seems almost similar to proto_tree_add_item.

(14 Dec '16, 04:49) xaheen

@anders Could you please explain the reason for writing "14<<3+5, 2"? Thanks

(01 Feb '17, 02:09) xaheen
1

proto_tree_add_bits_item takas an offset and length in bits and not bytes.

So 14<<3+5 = 14*8+5 = 117 bits since the beginning of the tvb. 2 is the number of bits to be read from the offset.

(01 Feb '17, 04:09) Pascal Quantin
1

And that was a shot in the dark at what I assumed the previous code tried to do :-)

(01 Feb '17, 07:16) Anders ♦