ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] wireshark decode as..??

From: Bill Meier <wmeier@xxxxxxxxxxx>
Date: Mon, 22 Mar 2010 18:53:21 -0400
Brian Oleksa wrote:
Olivier

Yes...looks like I do. Any thoughts on how I can fix this..??

Thanks,
Brian

void proto_reg_handoff_helen(void) {
    static gboolean initialized = FALSE;

    int i;

    for (i = 0; i < 25; i++) {

        if (!initialized) {
            data_handle = find_dissector("data");
helen_handle = create_dissector_handle(dissect_helen, proto_helen);
            dissector_add("udp.port", ports[i], helen_handle);
        }
    }
    initialized = TRUE;
}


I haven't double-checked, but I exepect the answer is to just reuse the handle; ie: create the handle just once rather than creating a new handle for each port.

Also: you certainly don't need to find a data_handle multiple times !

So: just loop on the dissector_add.

------

Note:

Theres also a "range" mechanism/idiom which can be used (especially if you want to allow the range to be changed in a preference).

See packet-fix.c for an example.