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

I am upgrading the plugin for 2.2 from 1.6. I am having Trouble with the conversion of proto_tree_add_text to proto_tree_add_item for such cases. How do I write the hf variable for the following case :

proto_tree_add_text(command_tree, tvb,  7, 1, "Direct PA:\t\t%s", match_strval(getbits(tvb_get_guint8(tvb, 7), 1, 2), discrete_status_var));

From the example souce codes, It seems to me that it should be like this:

static int hf_cidsifecmd_direct_pa = -1;
{&hf_cidsifecmd_direct_pa, { "Direct PA:", "cidsifecmd_direct.pa", FT_UINT8, BASE_DEC, VALS (discrete_status_var), 0x0, NULL, HFILL}},
  proto_tree_add_item(command_tree, hf_direct_pa, tvb, offset, msg_length, ENC_BIG_ENDIAN);

is this correct way to do it? I cant understand how "match_strval()" is going to work on this. Thanks.

asked 01 Feb, 03:24

xaheen's gravatar image

xaheen
71141519
accept rate: 50%


Previous code was fetching 2 bits only, so use a bitmask in your hf_cidsifecmd_direct_pa declaration:

{&hf_cidsifecmd_direct_pa, { "Direct PA", "cidsifecmd_direct.pa", FT_UINT8, BASE_DEC, VALS (discrete_status_var), 0x60, NULL, HFILL}},
proto_tree_add_item(command_tree, hf_cidsifecmd_direct_pa, tvb, 7, 1, ENC_BIG_ENDIAN);

Or use proto_tree_add_bits_item like in your previous question:

{&hf_cidsifecmd_direct_pa, { "Direct PA", "cidsifecmd_direct.pa", FT_UINT8, BASE_DEC, VALS (discrete_status_var), 0x0, NULL, HFILL}},
proto_tree_add_bits_item(command_tree, hf_cidsifecmd_direct_pa, tvb, 7<<3+1, 2, ENC_BIG_ENDIAN);
permanent link

answered 01 Feb, 04:13

Pascal%20Quantin's gravatar image

Pascal Quantin
5.5k960
accept rate: 30%

Thanks a lot :)

(01 Feb, 04:30) xaheen

@Pascal Quantin in the previous code, (as I have understood seeing the real wireshark output)

match_strval(getbits(tvb_get_guint8(tvb, 7), 1, 2), discrete_status_var));

makes sure that the value taken from two bits are compared with the index of "discrete_status_var" to Output the desired value from "discrete_status_var".

How is that done in the new code? Thanks

(01 Feb, 05:08) xaheen
1

Have a look at proto_tree_add_item() and proto_tree_add_bit_item() source code (more specifically the proto_tree_add_uint() and fill_label_number() sub functions). fill_label_number() takes care of the value_string search.

(01 Feb, 05:23) Pascal Quantin

Thanks :) will do

(01 Feb, 05:35) xaheen
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
×16
×10
×7

question asked: 01 Feb, 03:24

question was seen: 566 times

last updated: 01 Feb, 05:35

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