[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wireshark-dev
Subject:    [Wireshark-dev] Add generated hf_register_info during proto_register_...
From:       Michael Lum <michael.lum () starsolutions ! com>
Date:       2021-09-28 0:32:06
Message-ID: 053D39D3D76C474EB2D2A284AA6BA31802C7637BBBE3 () COLOSSEXCH01 ! starsolutions ! com
[Download RAW message or body]

Hi, I've got a bunch of statically entered entries for the "normal" way of \
registering the field array:

I.e.

using static hf_register_info hf[] = {
...}

proto_register_field_array(proto_ublox, hf, array_length(hf));

Now I have chunk of code were I want to do this:

#define    NUM_PORT_VALS    (6)
#define    NUM_PROTO_VALS    (8)

static int hf_mon_msgpp_msg[NUM_PORT_VALS][NUM_PROTO_VALS];

...

    for (i = 0; i < NUM_PORT_VALS; i++)
    {
        subtree =
            proto_tree_add_subtree_format(tree, tvb, curr_offset, 16,
                ett_mon_msgpp_msg[i], NULL,
                "msg%u - Number of successfully parsed messages for each protocol on \
port%u",  i + 1, i);

        for (j = 0; j < NUM_PROTO_VALS; j++)
        {
            proto_tree_add_item(subtree, hf_mon_msgpp_msg[i][j], tvb, curr_offset, 2, \
ENC_LITTLE_ENDIAN);  curr_offset += 2;
        }
    }
Is there a way to append or the 48 (6 x 8) hf_register_info elements that I will \
generate at startup?

I would allocate something like this:

static hf_register_info hf2[NUM_PORT_VALS * NUM_PROTO_VALS];

And then programatically build the field name, description, etc.

for port < NUM_PORT_VALS ...
for proto < NUM_PROTO_VALS ...
        { &hf_mon_msgpp_msg[port][proto],
...
           "ublox.mon.msgpp.parsed.port%u.proto%u", port, proto)

Finally appending these field entries?

I looked through proto.h/proto.c but I couldn't find what I was looking for.

Thanks for any help

Cheers


Michael Lum (michael.lum@starsolutions.com<mailto:michael.lum@starsolutions.com>) | \
STAR SOLUTIONS<http://www.starsolutions.com/> | Principal Software Engineer 4600 \
Jacombs Road, Richmond BC, Canada V6V 3B1 | +1.604.303.2315


[Attachment #3 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 11.00.9600.19597"></HEAD>
<BODY>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>Hi, I've got a bunch 
of statically entered entries for the "normal" way of registering the field 
array:</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>I.e.</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>using static 
hf_register_info hf[] = {<BR>...}</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>proto_register_field_array(proto_ublox, hf, 
array_length(hf));</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>Now I have chunk of 
code were I want to do this:</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>#define&nbsp;&nbsp;&nbsp; 
NUM_PORT_VALS&nbsp;&nbsp;&nbsp; (6)</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>#define&nbsp;&nbsp;&nbsp; 
NUM_PROTO_VALS&nbsp;&nbsp;&nbsp; (8)</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>static int 
hf_mon_msgpp_msg[NUM_PORT_VALS][NUM_PROTO_VALS];</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>...</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>&nbsp;&nbsp;&nbsp; 
for (i = 0; i &lt; NUM_PORT_VALS; i++)<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; subtree 
=<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
proto_tree_add_subtree_format(tree, tvb, curr_offset, 
16,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 ett_mon_msgpp_msg[i], 
NULL,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 "msg%u - Number of successfully parsed messages for each protocol on 
port%u",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 i + 1, i);</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (j = 0; 
j &lt; NUM_PROTO_VALS; j++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
proto_tree_add_item(subtree, hf_mon_msgpp_msg[i][j], tvb, curr_offset, 2, 
ENC_LITTLE_ENDIAN);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
 curr_offset += 2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;&nbsp;&nbsp; }<BR></SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>Is there a way to 
append or the 48 (6 x 8) hf_register_info elements that I will generate at 
startup?</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>I would allocate 
something like this:</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>static 
hf_register_info hf2[NUM_PORT_VALS * NUM_PROTO_VALS];</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><SPAN class=568021000-28092021><FONT size=2 face=Arial>And then 
programatically build the field name, description, etc.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><SPAN class=568021000-28092021></SPAN><FONT size=2 face=Arial>f<SPAN 
class=568021000-28092021>or port&nbsp;&lt; NUM_PORT_VALS ...</SPAN></FONT></DIV>
<DIV><SPAN class=568021000-28092021></SPAN><SPAN 
class=568021000-28092021></SPAN><FONT size=2 face=Arial>f<SPAN 
class=568021000-28092021>or proto &lt; NUM_PROTO_VALS 
...</SPAN><BR></FONT></DIV></SPAN>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { 
&amp;hf_mon_msgpp_msg[port][proto],</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>...<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ublox.mon.msgpp.parsed.port%u.proto%u", \
 </SPAN></FONT><FONT size=2 face=Arial><SPAN class=568021000-28092021>port, 
proto)</DIV></SPAN></FONT>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>Finally appending 
these field entries?</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>I looked through 
proto.h/proto.c but I couldn't find what I was looking for.</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN class=568021000-28092021>Thanks for any 
help</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021>Cheers</SPAN></FONT></DIV>
<DIV><FONT size=2 face=Arial><SPAN 
class=568021000-28092021></SPAN></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV align=left><FONT size=2 face=Arial>
<DIV align=left><FONT color=#14477c size=1 face=Arial>Michael Lum (</FONT><A 
title=blocked::mailto:michael.lum@starsolutions.com 
href="mailto:michael.lum@starsolutions.com"><FONT 
title=blocked::mailto:michael.lum@starsolutions.com color=#14477c size=1 
face=Arial>michael.lum@starsolutions.com</FONT></A><FONT color=#14477c><FONT 
size=1 face=Arial>) | </FONT><A title=blocked::http://www.starsolutions.com/ 
href="http://www.starsolutions.com/"><FONT 
title=blocked::http://www.starsolutions.com/ size=1><FONT 
title=blocked::http://www.starsolutions.com/ face=Arial><STRONG 
title=blocked::http://www.starsolutions.com/><FONT 
title=blocked::http://www.starsolutions.com/ 
color=#870400>STAR</FONT></STRONG><FONT 
title=blocked::http://www.starsolutions.com/ color=#00457c> <STRONG 
title=blocked::http://www.starsolutions.com/>SOLUTIONS</STRONG></FONT></FONT></FONT></A><FONT \
 size=1 face=Arial> | Principal Software Engineer</FONT></FONT></DIV>
<DIV align=left><FONT color=#808080 size=1 face=Arial>4600 Jacombs Road, 
Richmond BC, Canada V6V 3B1 | +1.604.303.2315</FONT></DIV></FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV></BODY></HTML>


[Attachment #4 (unknown)]

___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@wireshark.org>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://www.wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@wireshark.org?subject=unsubscribe


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic