Wireshark mailing list archives

myProtocol_handle = find_dissector("myprotocol"); is NULL


From: "Posey, Nolan John, Jr (Nolan)" <Nolan.Posey () lsi com>
Date: Thu, 10 Dec 2009 16:35:22 -0500

Hi all,

I have created two dissectors.
I would like one dissector to use the other one.
I am getting a NULL return value when I call find_dissector();

The lower level dissector is named mgw and the pertinent code sections are:
From file packet-mgw.c:
---8<---
       void proto_register_mgw();
       void proto_reg_handoff_mgw();
static void dissect_mgw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);

static int  proto_mgw = -1;
static dissector_handle_t mgw_handle;
void
proto_register_mgw(void)
{
 static hf_register_info hf[] = {

  /* MGW header */
  { &hf_mgw_hdr,
   { "Message Header",
     "mgw.hdr",
     FT_PROTOCOL,
     BASE_NONE,
     NULL,
     0x0,
     "",
     HFILL }},
...
 proto_mgw = proto_register_protocol ("LSI MGW Framework Transport Protocol", "LSI MGW", "mgw");
 proto_register_field_array(proto_mgw, hf, array_length(hf));
 proto_register_subtree_array(ett, array_length(ett));

}
void
proto_reg_handoff_mgw(void)
{
 static gboolean initialized = FALSE;
 guint32 i;

 if (!initialized) {
  mgw_handle = create_dissector_handle(dissect_mgw, proto_mgw);
  for (i=global_mgw_base_port;i<=(global_mgw_base_port+3);i++) {
   dissector_add("udp.port", i, mgw_handle);
  }
/*   dissector_add("lsiint_hc.dstch", 0x07f0, mgw_handle); */
/*   dissector_add("lsiint_hc.dstch", 0x07f1, mgw_handle); */
/*   dissector_add("lsiint_hc.dstch", 0x07f2, mgw_handle); */
/*   dissector_add("lsiint_hc.dstch", 0x07f3, mgw_handle); */
  initialized = TRUE;
 }
}
---8<---
Calling from UDP port above works fine.
However, when I try to call from my upper level dissector, it fails.
The commented out dissector_add functions cause wireshark to crash.
From file packet-lsiint.c:
---8<---
       void proto_reg_handoff_lsiint();
       void proto_register_lsiint_hc();
static dissector_handle_t lsiint_hc_handle;
void
proto_reg_handoff_lsiint(void)
{
  static gboolean initialized = FALSE;

  if (!initialized) {
    lsiint_hc_handle = create_dissector_handle(dissect_lsiint_hc, proto_lsiint_hc);
    register_dissector("lsiint_hc",  dissect_lsiint_hc,  proto_lsiint_hc);
    mgw_handle = find_dissector("mgw");
    if (mgw_handle == NULL) {
     fprintf(stderr, "MGW handle is NULL\n");
    }
    data_handle = find_dissector("data");
    initialized = TRUE;
  }
}
---8<---
If I make mgw_handle global in packet-mgw.c and an extern in packet-lsiint.c, then the protocol decodes happen as they 
should.

What am I doing wrong with the registration?

Many thanks in advance,

 -posey
___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe

Current thread: