From 5468611d57cb0302d4f0f359f79c0bedc66ee888 Mon Sep 17 00:00:00 2001 From: David Perry Date: Tue, 9 May 2023 15:19:23 -0400 Subject: Use `register_dissector()` for more protocols Changes several calls of `create_dissector_handle()` to instead call `register_dissector()` with a name for the dissector. This should handle all dissectors in `epan/` from `packet-a*` to `packet-d*`. This change allows affected dissectors to be findable by calls to `find_dissector()`. In turn, this opens up more command-line use for these protocols, including fuzzshark and rawshark, as well as lua use via `Dissector.get()`. Where needed, move the call from the protocol handoff function to the protocol register function, and use `find_dissector()` in the handoff function. There were some calls to `create_dissector_handle()` or `register_dissector()` which passed `-1` as the protocol argument. When I saw those I corrected them to pass the actual `proto_foo` identifier instead. Partially addresses #5612 --- epan/dissectors/packet-autosar-nm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'epan/dissectors/packet-autosar-nm.c') diff --git a/epan/dissectors/packet-autosar-nm.c b/epan/dissectors/packet-autosar-nm.c index 631b36086a..dc8dc9b4a8 100644 --- a/epan/dissectors/packet-autosar-nm.c +++ b/epan/dissectors/packet-autosar-nm.c @@ -727,6 +727,9 @@ void proto_register_autosar_nm(void) prefs_register_range_preference(autosar_nm_module, "ipdum.pdu.id", "AUTOSAR I-PduM PDU IDs", "I-PDU Multiplexer PDU IDs.", &g_autosar_nm_ipdum_pdus, 0xffffffff); + + nm_handle = register_dissector("autosar-nm", dissect_autosar_nm, proto_autosar_nm); + nm_handle_can = register_dissector("autosar-nm.can", dissect_autosar_nm_can, proto_autosar_nm); } void proto_reg_handoff_autosar_nm(void) @@ -734,10 +737,8 @@ void proto_reg_handoff_autosar_nm(void) static gboolean initialized = FALSE; if (!initialized) { - nm_handle = create_dissector_handle(dissect_autosar_nm, proto_autosar_nm); dissector_add_for_decode_as_with_preference("udp.port", nm_handle); - nm_handle_can = create_dissector_handle(dissect_autosar_nm_can, proto_autosar_nm); dissector_add_for_decode_as("can.subdissector", nm_handle_can); /* heuristics default on since they do nothing without IDs being configured */ -- cgit v1.2.3