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] Plugin Dissector with multiple .c files

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Thu, 24 Jul 2008 19:35:53 -0700

On Jul 24, 2008, at 3:45 PM, Jason Dick wrote:

It appears that ett_keepalive is -1 when I run wireshark. I have defined the ett_keepalive and the ett subtree in the .h file.

static gint ett_keepalive = -1;
static gint *ett[] = {
...
   &ett_keepalive,
...
};

The only things that should be defined in header files are macros and data types (and inline functions if the compiler supports them; not all compilers used to compile Wireshark do, so we don't use them). Defining static variables in a header file is almost always a bad idea, because each source file that includes the header file gets its own private copy of those static variables; if one of those variables gets changed, the other ones don't get changed to match.

It all works when I have just one source file but when I moved these functions to the 2nd file, I started having this problem. Do I need to define these in the proto_register function and explicitly pass the ett subtree array?

If ett_keepalive is used in more than one .c file, then:

you need to define ett_keepalive in the same source file that has the proto_register function, and do *NOT* define it as static;

you should define the ett[] array in the proto_register function, and call proto_register_subtree_array() in that function;

	you need to *declare* ett_keepalive in the .h file:

		extern gint ett_keepalive;

If you do that, there will be only *one* ett_keepalive variable, and it will be initialized by proto_register_subtree_array().