Wireshark-dev: Re: [Wireshark-dev] Plugin dissector registration order problem
From: "Sebastien Dubois" <sebastien.dubois@xxxxxxxxxxxx>
Date: Tue, 9 Oct 2007 15:28:29 -0400
Title: RE: Plugin dissector registration order problem

Hi,

  Thanks for the reply.  I was able to make my stuff work using heuristic dissectors,  but I'll try what you recommend as well.

Thx,
/Sebastien

_____________________________________________

Date: Tue, 9 Oct 2007 13:21:23 -0400
From: "Maynard, Chris" <Christopher.Maynard@xxxxxxxxx>
Subject: Re: [Wireshark-dev] Plugin dissector registration order
        problem
To: "Developer support list for Wireshark"
        <wireshark-dev@xxxxxxxxxxxxx>
Message-ID:
        <44D5BA69A4AF3A458C294028BAD9E5A580FE3D@xxxxxxxxxxxxxxxxxxxxxx>
Content-Type: text/plain; charset="utf-8"

I have 2 plugins with just such a situation as yours where one plugin passes off dissection to the other plugin.  I use find_dissector()/call_dissector().

 

So ... in your proto_reg_handoff_foo2_proto() function, replace the
dissector_add() call with "foo_handle = find_dissector("foo_proto")", then wherever in your foo2_proto dissector you decide that you need to pass off dissection to the foo_proto dissector, use "call_dissector(foo_handle, ...)".

 

I hope it helps,

Chris

_____________________________________________
From:   Sebastien Dubois 
Sent:   October 5, 2007 10:10 AM
To:     'wireshark-dev@xxxxxxxxxxxxx'
Subject:        RE: Plugin dissector registration order problem



Thanks for the quick answer,

  In this case, is there any example code available that exists implementing a sub-dissector like the one I'm trying to code below, so that I can look at it to see what I'm doing wrong?

Thx,
/Sebas


------------------------------------------------------------------------------------------------
Sebastien Dubois schrieb:

    Hi,

    I'm currently having problems trying to implement a new plugin as a sub-dissector to another plugin. The first plugin (let's call it foo_proto) registers itself and adds itself as a dissector that uses a given udp port as follows:

    -------------------------------------------------------
    *void** proto_register_foo_proto*(*void*)
    {
        module_t* foo_proto_module;
       * if* (proto_foo_proto == -1)
        {
    proto_foo_proto =* proto_register_protocol*("Foo Protocol ", "foo_proto", "foo_proto"); * register_dissector*("foo_proto", dissect_foo_proto, proto_foo_proto); * proto_register_field_array*(proto_foo_proto, hf, array_length(hf));

           * proto_register_subtree_array*(ett, array_length(ett));
        }
    foo_proto_module =* prefs_register_protocol*(proto_foo_proto, proto_reg_handoff_foo_proto);
    }

    *void** proto_reg_handoff_foo_proto*(*void*)
    {
       * static** int* Initialized = FALSE;
       * if* (!Initialized)
        {
    foo_proto_handle =* create_dissector_handle*(dissect_foo_proto, proto_foo_proto);
           * dissector_add*("udp.port", foo_proto_port, foo_proto_handle);
            Initialized = TRUE;
        }
    } -------------------------------------------------------

    The second plugin (let's call it foo2_proto) also registers itself and adds itself as a dissector that uses a registered field in the previous dissector foo_proto as follows:

    -------------------------------------------------------
    *void** proto_register_foo2_proto*(*void*)
    {
        module_t* foo2_proto_module;
       * if* (proto_foo2_proto == -1)
        {
    proto_foo2_proto =* proto_register_protocol*("Foo2 Protocol ", "foo2_proto", "foo2_proto"); * register_dissector*("foo2_proto", dissect_foo2_proto, proto_foo2_proto); * proto_register_field_array*(proto_foo2_proto, hf, array_length(hf));

           * proto_register_subtree_array*(ett, array_length(ett));
        }
    foo2_proto_module =* prefs_register_protocol*(proto_foo2_proto, proto_reg_handoff_foo2_proto);
    }

    *void** proto_reg_handoff_foo2_proto*(*void*)
    {
       * static** int* Initialized = FALSE;
       * if* (!Initialized)
        {
    foo2_proto_handle =* create_dissector_handle*(dissect_foo2_proto, proto_foo2_proto); * dissector_add*("foo_proto.hf_some_field", foo2_proto_port, foo2_proto_handle);

            Initialized = TRUE;
        }
    } -------------------------------------------------------

    This compiles fine, but I get the following assertion failure in function dissector_add(...) at startup:

    Err  file packet.c: line 671: assertion failed: (sub_dissectors)

    It seems that the first plugin (foo) is not registered when the second one (foo2) calls dissector_add on it.

    So, how does this work? How can you add a plugin dissector to another plugin dissector? Is it at all possible?

Wireshark will call all register functions (it knows of) before calling any of the handoff functions. So this sequence should not be your problem.

The line 671 of the assert might get a hint, but it's a bit worthless together with your code snippet ...

Regards, ULFL

-----------------------------------------------------------------------------------