First time here? Check out the FAQ!
THIS IS A TEST INSTANCE. Feel free to ask and answer questions, but take care to avoid triggering too many notifications.
0

how to define hf_register_info in dissector

  • retag add tags

I get data in tvbuff_t *tvb, its size is 10 to 50 bit depend on another parameter assume p.
Message structure is as below:

Struct AA  
{    
      Var a : x bit, [0<=range(x)<=32]   
      Var b : y bit, [0<=range(y)<=16]  
};

define static hf_register_info hf[] in dissector, and register it to proto as

proto_register_field_array(proto_xxx, hf, array_length(hf));

Should I define 32+16=48 hf_xxx with different bit_mask and byte_type and select different two hf_xxx for a and b according to p?
Is there any good method to solve this problem?

taotiemuren's avatar
3
taotiemuren
asked 2020-11-05 02:42:47 +0000
grahamb's avatar
23.8k
grahamb
updated 2020-11-05 09:07:01 +0000
edit flag offensive 0 remove flag close merge delete

Comments

So by x bit, [0<=range(x)<=32] do you mean that the first field in the structure is a variable number of bits, with different instances of the structure possibly having different numbers of bits in that field, with the field being somewhere between 0 bits (i.e., absent) and 32 bits?

Guy Harris's avatar Guy Harris (2020-11-05 03:26:21 +0000) edit

yes, and y is in the same situation.

taotiemuren's avatar taotiemuren (2020-11-05 04:49:56 +0000) edit
add a comment see more comments

1 Answer

0

Hi, If the var are used to store integers of various sizes add 2 hfs 16 and 32 bits then use proto_tree_add_bits_item() to read the variables from the tvb using the proper bit length.

Anders's avatar
5k
Anders
answered 2020-11-05 08:23:59 +0000
edit flag offensive 0 remove flag delete link

Comments

It seems to me the complication is that the starting offset for field b ranges from 0 to 32, so you would need a 48 bit integer hf for b, and set the offset and length accordingly in the call to proto_tree_add_bits_item().

grahamb's avatar grahamb (2020-11-05 09:13:42 +0000) edit

Thanks for your advice. I define two hf and adjust bit_mask in each message according to parameter p

taotiemuren's avatar taotiemuren (2020-11-17 07:03:06 +0000) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer