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

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.8k330205


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 }},
permanent link

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, 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, 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, 07:16) Anders ♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×637
×173
×158
×10

question asked: 14 Dec '16, 03:46

question was seen: 981 times

last updated: 01 Feb, 07:16

p​o​w​e​r​e​d by O​S​Q​A