Wireshark-dev: [Wireshark-dev] Plugin Dissector with multiple .c files
From: Jason Dick <jasonkdick@xxxxxxxxx>
Date: Thu, 24 Jul 2008 15:45:30 -0700 (PDT)
I have a plugin dissector I am working on that dissects a custom protocol with about a dozen main message types.  In order to manage it easier I have broken the code into multiple .c files.  I seems that when I do that though, the actual functions I call in the 2nd .c file have problems with the ett subtree array.

When compiled and run I see the following errors for all packets dissected in the 2nd .c file.

   Dissector bug, protocol BLAH:  proto.c:3640:  failed assertion "idx >=0 && idx < num_tree_types"

Here is the snippet of code:

dissect_keep_alive(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree, int message_length)
{
        proto_item *ti = NULL;
        proto_tree *keepalive_tree = NULL;

        if (tree) {
            ti = proto_tree_add_text(tree, tvb, offset, message_length, "KeepAlive");
            ti = proto_tree_add_text(tree, tvb, offset, message_length, "ett_keepalive %d",ett_keepalive);
            keepalive_tree = proto_item_add_subtree(ti, ett_keepalive);
            proto_tree_add_item(keepalive_tree, hf_keepalive_timeout, tvb, offset, 2, FALSE); offset += 2;
            proto_tree_add_item(keepalive_tree, hf_keepalive_spare, tvb, offset, 2, FALSE); offset += 2;
        }
}

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,
...
};


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?  Is there an example dissector that has the dissector spread across multiple .c files and single .h file?  

My C skills are a bit rusty so thank you for your patience.
Jason