From fb9d01556dbc28a507778f66cbaca234a55e6305 Mon Sep 17 00:00:00 2001 From: David Perry Date: Tue, 19 Sep 2023 14:12:28 -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-p*` to `packet-v*`. 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, save the result in a static variable, and use that variable 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-usb-ccid.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'epan/dissectors/packet-usb-ccid.c') diff --git a/epan/dissectors/packet-usb-ccid.c b/epan/dissectors/packet-usb-ccid.c index fc2c4d93ee..40e13233f3 100644 --- a/epan/dissectors/packet-usb-ccid.c +++ b/epan/dissectors/packet-usb-ccid.c @@ -114,6 +114,8 @@ static int hf_ccid_bIFSC = -1; static int hf_ccid_bNadValue = -1; static dissector_handle_t usb_ccid_handle; +static dissector_handle_t usb_ccid_descr_handle; + static int * const bVoltageLevel_fields[] = { &hf_ccid_bVoltageSupport18, @@ -1018,6 +1020,7 @@ proto_register_ccid(void) prefs_register_obsolete_preference(pref_mod, "prtype"); usb_ccid_handle = register_dissector("usbccid", dissect_ccid, proto_ccid); + usb_ccid_descr_handle = register_dissector("usbccid.descriptor", dissect_usb_ccid_descriptor, proto_ccid); subdissector_table = register_decode_as_next_proto(proto_ccid, "usbccid.subdissector", "USB CCID payload", NULL); } @@ -1026,10 +1029,6 @@ proto_register_ccid(void) void proto_reg_handoff_ccid(void) { - dissector_handle_t usb_ccid_descr_handle; - - usb_ccid_descr_handle = create_dissector_handle( - dissect_usb_ccid_descriptor, proto_ccid); dissector_add_uint("usb.descriptor", IF_CLASS_SMART_CARD, usb_ccid_descr_handle); dissector_add_uint("usb.bulk", IF_CLASS_SMART_CARD, usb_ccid_handle); -- cgit v1.2.3