This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Duplicated code in dissectors

0

Hi. I have two custom dissectors that i have written. The two protocols i dissect have fields that are very similar to eachother. The headers are different and some other things, but 1 quite large part of the protocol is identical. In my code i have a quite big while-loop that extracts data and adds it to the proto tree, and this loop is identical in both dissectors.

Is there an easy way to avoid this duplicated code when writing dissectors?

/Kit

asked 04 Jul '13, 07:34

Kitg's gravatar image

Kitg
16336
accept rate: 0%


One Answer:

2

In one dissector extract the loop into its own function, parametrise accordingly, and declare the function in a header file for that dissector. In the other dissector, include the header file from the first one and call the function with the appropriate parameters.

answered 04 Jul '13, 08:00

grahamb's gravatar image

grahamb ♦
19.8k330206
accept rate: 22%

Thanks alot, will do that.

(04 Jul '13, 08:06) Kitg