Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] Re : Tr : Dissector preferences reuse : solution

From: Jaap Keuter <jaap.keuter@xxxxxxxxx>
Date: Tue, 28 Apr 2009 19:23:27 +0200
Hi,

Maybe you want to look into the WS_VAR_IMPORT macro for that. But then again I'm no Windows developer.

Thanx,
Jaap


yvanmmailbox-web@xxxxxxxx wrote:
Hi,

I wish to answer myself because I found the solution. Thanks to Jeff for the idea of sharing only the variable in the preferences. I give here what I did, hoping it can be useful for somebody (maybe it can be put in a README or somewhere else). It was tested with MSVC++2008EE, with the two plugins like indicated in a previous mail in copy below. The aim was to share preferences defined in a plugin in order to be used by another plugin.

In the main plugin (called plugin1, the one that contains the preferences definition), the variable(s) that store the preference (range, UAT) must be declared directly in the C-code (i.e. packet-plugin1.c, header is not necessary) with the prefix __declspec(dllexport). For example, with a range of UDP ports:

__declspec(dllexport) range_t *bite_udp_range;

Then plugin1 can be compiled. The files packet-plugin1.obj and plugin1.lib must be copied into the directory of plugin2. In packet-plugin2.c, declare the same variable with the prefix __declspec(dllimport). Following the same example, we have:

__declspec(dllexport) range_t *bite_udp_range;

The last step is to modify the Makefile.nmake of plugin2 directory as follow (adding files of plugin1 in the 2nd line):


$(PLUGIN_NAME).dll $(PLUGIN_NAME).exp $(PLUGIN_NAME).lib : $(OBJECTS) $(LINK_PLUGIN_WITH) $(RESOURCE) link -dll /out:$(PLUGIN_NAME).dll $(LDFLAGS) $(OBJECTS) packet-plugin1.obj $(LINK_PLUGIN_WITH) plugin1.lib\
    $(GLIB_LIBS) $(RESOURCE)

Plugin2 can be compiled. I tried it only with a range_t but I'll try it in few weeks with an entire UAT table. This probably works only for Windows because "__declspec(dllexport)" is Windows-specific.

Thanks everyone for your help!

Yvan

------------------------------------------------------------------------
*De :* Jeff Morriss <jeff.morriss.ws@xxxxxxxxx>
*� :* Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx>
*Envoy� le :* Jeudi, 23 Avril 2009, 17h50mn 36s
*Objet :* Re: [Wireshark-dev] Tr : Dissector preferences reuse



yvanmmailbox-web@xxxxxxxx <mailto:yvanmmailbox-web@xxxxxxxx> wrote:

 > I 'm working on 2 plugin dissectors, and I wish to know if it's possible
 > (and if yes, how) to reuse preferences from one plugin to another. I
 > need to reuse only a part of the preferences (which is an UAT table, so
 > pretty long and boring to define) from plugin1 to plugin2, considering
 > that protocol2 is included in plugin1 like this:
 > plugin1
 >    IP struct
 >        UDP struct
 >            plugin2
 > Can the copy_prefs() function be useful? How must I define the
 > preferences in plugin1 to divide it in 2 parts? How to integrate a
 > separated part into preferences of plugin2?

Well, the plugins could simply share the variable that stores the
preference.  Basically: make the variable not 'static' (so it is visible
to other modules), put it in a header file (properly 'extern'd), and
have both plugins include the header file and use the variable.

For an example, see the mtp3_standard preference in packet-mtp3.{h,c}.

Note: I know this works for regular dissectors but I don't know if the
rules are different for plugins--especially on Windows.