TEMPLATE.TXT

(3 KB) Pobierz
/* 
 * This is essentially a template handler. Follow it, and things will be
 * just fine...
 *
 * This program will be compiled (and loaded at runtime) as a dynamic
 * object. Essentially, the handlers directory will be searched for all
 * .so files, and they will each be loaded. Once dlopen()'d, dlsym() will
 * be called to get the following:
 *
 *  init()    - Initialization for this handler. Must return a
 *              (struct handler_registration *) to register for certain ports.
 *              Note that you must register each protocol separately. So, for
 *              DNS, you must register 53 UDP and 53 TCP as separate ports,
 *              you can't simply do TCP|UDP and 53.
 *  cinit()   - Initialization for an individual "connection".
 *              Gets two trans_structs and a void **. The first (parent) is
 *              always NULL, unless this is a specialty handler.
 *              that must be allocated (or returned as NULL). It can be used
 *              for any data relevant to a specific connection. That data will
 *              be given to the handler() function.
 *              Init returns a (struct handler_registration *) which determines
 *              which packets will be delivered to this handler.
 *  handler() - Takes 2 trans_structs, a data, datalen, private_data, direction,
 *              and time. The private_data was allocated by init(), and is
 *              connection specific! Return 1 if the title of this connection
 *              or the actual transaction info has changed.
 *  destroy() - A connection has terminated (or the program is exiting),
 *              free private_data, and do any reporting necessary. It is
 *              assumed to be free()d when the function returns
 *
 * NOTE:
 *  This stuff needs to be as fast as possible, as it will be called with
 * every packet relevant to the connection.
 *
 * NOTE2:
 *   UDP "connections" do *NOT* call the destroy() function ever. Any memory
 * allocated in init will be lost. Since UDP really aren't connections, it's 
 * impossible to tell when a "connection" is really done. Therefore, if you
 * need to maintain state information for UDP, you must do it all in locally
 * managed memory (don't rely on private_data to help you).
 */

#include <stdio.h>
#include <sys/types.h>
#ifdef WIN
# include <time.h>
# include <winsock.h>
# include "win.h"
#else
# include <sys/time.h>
#endif

#include "transapi.h"


static struct alarm_hit_list *Local_Hitlist=NULL;
static struct friendly_functions *Friends;

/* This default handler gets everything--netbios, ip, etc. */
struct handler_registration *
init(struct friendly_functions *friends)
{
  static struct handler_registration hr;
  struct handler_port_list *hpl; /* Must be malloc()d. It's free()d by parent*/

  Friends = friends;

  hr.name      = "Default Handler"; /* Name */
  hr.inclusive = 0;                 /* Don't call if handled elsewhere */
  hr.ports     = NULL;              /* Give me everything */
  hr.alarms_avail = NULL;           /* I don't have alarms */
  hr.alarm_hitlist = &Local_Hitlist; /* Initialize my hitlist to 0 */
  return(&hr);
}

void
cinit(struct trans_struct *parent, struct trans_struct *trans, 
      void **private_data)
{

}

int
handler(struct trans_struct *parent, struct trans_struct *trans, 
                char *data, int datalen,
		void *private_data, int direction, struct timeval *ptime)
{
/*	printf("Got a packet of len %d, dir=%d\n", datalen, direction);*/
	return(0);
}

void
destroy(struct trans_struct *parent, struct trans_struct *trans, 
        void *private_data)
{

}
Zgłoś jeśli naruszono regulamin