Wireshark-dev: Re: [Wireshark-dev] C equivalent of LUA proto.init
From: Pascal Quantin <[email protected]>
Date: Fri, 26 Aug 2016 18:26:38 +0200
Hi Paul,

2016-08-26 18:01 GMT+02:00 Paul Offord <[email protected]>:

Hi All,


I’m slowly porting the TRANSUM post-dissector from LUA to C.  My LUA dissector has a transum.init() function that is called each time a new trace file is opened.  Is there an equivalent mechanism in the C dissector functions.

Have a look at this function allowing you  to register a callback:
 * Allow protocols to register "init" routines, which are called before
 * we make a pass through a capture file and dissect all its packets
 * (e.g., when we read in a new capture file, or run a "filter packets"
 * or "colorize packets" pass over the current capture file or when the
 * preferences are changed).
WS_DLL_PUBLIC void register_init_routine(void (*func)(void)); 

If you need to cleanup memory (for example) when closing a file, you can register another callback with:
 * Allows protocols to register "cleanup" routines which are called
 * after closing a capture file (or when preferences are changed, in
 * that case these routines are called before the init routines are
 * executed). It can be used to release resources that are allocated in
 * register_init_routine.
WS_DLL_PUBLIC void register_cleanup_routine(void (*func)(void));