I'm not sure what you aim to accomplish sharing something between a dissector and the epan
and ui/gtk
sections of Wireshark, but if I understand your question correctly, that is not your current problem.
The 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, packet-myproto.c
and packet-myproto.h
.
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:
epan/dissectors/myproto-helper.h
:
extern int my_global_variable;
epan/dissectors/packet-myproto.h
:
#include "myproto-helper.h"
epan/dissectors/packet-myproto.c
:
int my_global_variable;
path/to/your/gtk/stuff/my_gtk_stuff.c
*:
#include "../../../../epan/dissectors/myproto-helper.h
*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).
answered 13 Apr '12, 10:16
multipleinte...
1.3k●15●23●40
accept rate: 12%
Thanks for the reply. But I did as u said but still getting undefined reference to `variable_name' Also its a hash table so I cant add it as a preference. Does it have something related to the Makefile, I mean do I need to give some path so that it looks for it while linking.