Wireshark-dev: [Wireshark-dev] "Correct" way to register protocols?

From: "J.C. Wren" <jcwren@xxxxxxxxxx>
Date: Mon, 2 Nov 2009 14:23:34 -0500
I have a dissector I wrote about two years ago that compiled and ran
under Wireshark 0.99.8-SVN-23896.  I'm now adding some updates and
trying to get it running under 1.3.2

I've attached the way I was doing it before.  At the time,
new_register_dissector() wasn't working, so I used the method below.

I've looked through all the initializers in the plugins directory, and
every one of them does it somewhat differently.  Using what I have
below compiles, but segfaults.  Unfortunately, I can't turn on JIT
debugging, because MSVC2008EE doesn't have it.  I've got a request in
to the IT department for MSVC2008, but I'm expecting the heat death of
the universe before I see them deliver anything.

Would someone mind cluing (apparently that's spelled right, even
though 'clueing' looks more right) me in as to the best-practices way
of initializing and registering a protocol?  Any maybe the "why" as to
why any given method is better than another?

Thanks,
--jc

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

void proto_register_r3 (void)
{
  if (proto_r3 == -1)
  {
    proto_r3 = proto_register_protocol ("R3", "R3", "r3");
    /*new_*/register_dissector ("r3", dissect_r3, proto_r3);
    proto_register_field_array (proto_r3, hf, array_length (hf));
    proto_register_subtree_array (ett, array_length (ett));
  }
}

void proto_reg_handoff_r3 (void)
{
  static gint initialized = FALSE;

  if (!initialized)
  {
    dissector_handle_t r3_handle = find_dissector ("r3");
    /* dissector_handle_t r3_handle = new_create_dissector_handle
(dissect_r3, proto_r3); */
    dissector_add ("tcp.port", 2571, r3_handle);
    dissector_add ("tcp.port", 8023, r3_handle);
    initialized = TRUE;
  }
}