I'm not sure what you aim to accomplish sharing something between a dissector and the
ui/gtk sections of Wireshark, but if I understand your question correctly, that is not your current problem.
extern convention is only really one part of the puzzle you are looking at. At a basic level, the variable needs to both have shared visibility and a single storage area. Before going forward, note that this method will only work if your dissector is built in (which I think it is, since you say it's in
epan/dissectors somewhere). Your dissector probably comes in two parts,
To declare the single storage area, you do as you probably already have by declaring
int my_global_variable; somewhere in
packet-myproto.c. Then, you need to make it accessible to other parts of the application (the shared visibility I mentioned above), and there are two options for doing this:
First, you could simply declare
extern int my_global_variable; inside
packet-myproto.h, and then
#include "packet-myproto.h" in whatever file you need access to the variable, but this poses the issue of also including everything else included by your dissector (almost all of which is probably not needed by your gtk code).
A likely cleaner way of doing this would be to make another file (
myproto-globalvariable.h or something) in the same directory with your dissector, then
#include that file in
packet-myproto.h and in the file for your gtk code. Then, inside the new file simply
extern int my_globabl_variable; and you are ready to go. This provides you with the benefit of shared visibility without polluting your global namespace with dissection-related items where they are unneeded.
In brief, place the following in each of these files:
extern int my_global_variable;
*It could also be a
.h file or what-have-you. Also remember to fix the include path (I'm almost certain
../../../../ is not correct for your case).
13 Apr '12, 10:16