Wireshark-dev: Re: [Wireshark-dev] Registering header fields later/in other functions?
From: Andreas <[email protected]>
Date: Sun, 13 Feb 2011 09:36:20 +0100
Am 12.02.2011 22:32, schrieb Thomas Wiens:

I am developing a custom dissector in C.
For clearness I want to put parts of the dissector in different source

The problem I have, is that the header fields have to be registered
directly after the proto_register_protocol() call.
It would be nice if it would be possible to declare and register the
header fields only in the sourcefile where they are used.
Is there a way to do this?

Example (the main hf struct-array was registered before):
gint hf_pr = -1;
hf_register_info hf = { &hf_pr,
{ "index", "s7comm.szl_0131_2", FT_UINT16, BASE_HEX, NULL, 0x0, "SZL ID
0x0131 Index 2: index", HFILL }
// is it possible to register header field here?
proto_tree_add_uint(tree, hf_pr, tvb, offset, 2, tvb_get_ntohs(tvb,

I don't need to filter on these entries, but I want to use the nicer
display features I have with the header fields (e.g. comments in status
At this time I'm using the proto_tree_add_text() in my 'outsourced'
functions to display the dissected items.
I have dissectors classes that are spreaded over a lot of source files. 
When Wireshark calls the function plugin_register() of my dissector, all 
classes' Register() functions are called. So there is no problem with 
making a dissector modular.
Registering the header fields on demand, before calling the 
proto_tree_add_xxx might work, but you need to handle the state 
"registered". Therefore you should register it, when Wireshark calls you 
for it.