Writing Modules

This section describes how to write your own plug-in modules for tcptrace . The structure definition of a module (found in modules.h) is shown below.

struct module {
    Bool	module_inuse;
    char	*module_name;
    char	*module_descr;

    int (*module_init) (int argc, char *argv[]);

    void (*module_read) (
	struct ip *pip,		/* the packet */
	tcp_pair *ptp,		/* info I have about this connection */
	void *plast,		/* pointer to last byte */
	void *pmodstruct);	/* module-specific structure */

    void (*module_done) (void);

    void (*module_usage)(void);

    void (*module_newfile)(
	char *filename,		/* the name of the current file */
	u_long filesize,	/* number of bytes in file (might be compressed) */
	Bool fcompressed);	/* is the file compressed? */

    void *(*module_newconn)(
	tcp_pair *ptp);		/* info I have about this connection */

    void (*module_udp_read) (
	struct ip *pip,		/* the packet */
	udp_pair *pup,		/* info I have about this connection */
	void *plast,		/* pointer to last byte */
	void *pmodstruct);	/* module-specific structure */

    void *(*module_udp_newconn)(
	udp_pair *ptp);		/* info I have about this connection */

    void (*module_nontcpudp_read) (
	struct ip *pip,		/* the packet */
	void *plast);		/* pointer to last byte */

    void (*module_deleteconn) (
	 tcp_pair *ptp,		/* info I have about this connection */
	 void *pmodstruct);	/* module-specific structure */
};

As shown above, each module definition consists of fields that store a basic description of the module followed by a list of function pointers that need to be filled with functions specific to the module. The module_inuse variable is used by tcptrace to see if the module has been selected and is active. The module_name, and module_descr fields store the name and a short description of the module and are useful for debugging purposes. The list of function pointers that follow need to be set to appropriate module specific functions.

The function pointers and their assignments for the Real-Time module (from the modules.h file) are shown below. These functions are defined in the mod_realtime.c file.

    {TRUE,		         /* make FALSE if you don't want to call it at all */
     "realtime",                 /* name of the module */
     "example real-time package",/* description of the module */
     realtime_init,		 /* routine to call to init the module */
     realtime_read,		 /* routine to pass each TCP segment */
     realtime_done,		 /* routine to call at program end */
     realtime_usage,		 /* routine to call to print module usage */
     NULL,			 /* routine to call on each new file */
     realtime_newconn,		 /* routine to call on each new connection */
     realtime_udp_read,          /* routine to pass each UDP segment */
     NULL,              	 /* routine to call on each new UDP conn */
     realtime_nontcpudp_read, 	 /* routine to pass each non-tcp and non-udp 
				    packets*/
     realtime_deleteconn}


Super-User 2003-08-29