diff options
Diffstat (limited to 'epan/tap.c')
-rw-r--r-- | epan/tap.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/epan/tap.c b/epan/tap.c index 4d89056b2b..ad3cb4af68 100644 --- a/epan/tap.c +++ b/epan/tap.c @@ -80,6 +80,25 @@ typedef struct _tap_listener_t { } tap_listener_t; static volatile tap_listener_t *tap_listener_queue=NULL; +/* structure to keep track of what tap listeners have registered + command-line arguments. + */ +typedef struct _tap_cmd_arg { + struct _tap_cmd_arg *next; + char *cmd; + void (*func)(char *arg); +} tap_cmd_arg; +static tap_cmd_arg *tap_cmd_arg_list=NULL; + +/* structure to keep track of what taps have been specified on the + command line. + */ +typedef struct { + tap_cmd_arg *tca; + char *arg; +} tap_requested; +static GSList *taps_requested = NULL; + /* ********************************************************************** * Init routine only called from epan at application startup * ********************************************************************** */ @@ -102,7 +121,72 @@ tap_init(void) return; } +/* ********************************************************************** + * Function called from tap to register the tap's command-line argument + * and initialization routine + * ********************************************************************** */ +void +register_tap_listener_cmd_arg(char *cmd, void (*func)(char *arg)) +{ + tap_cmd_arg *newtca; + + newtca=malloc(sizeof(tap_cmd_arg)); + newtca->next=tap_cmd_arg_list; + tap_cmd_arg_list=newtca; + newtca->cmd=cmd; + newtca->func=func; +} +/* ********************************************************************** + * Function called for a tap command-line argument + * ********************************************************************** */ +gboolean +process_tap_cmd_arg(char *optarg) +{ + tap_cmd_arg *tca; + tap_requested *tr; + + for(tca=tap_cmd_arg_list;tca;tca=tca->next){ + if(!strncmp(tca->cmd,optarg,strlen(tca->cmd))){ + tr=g_malloc(sizeof (tap_requested)); + tr->tca = tca; + tr->arg=g_strdup(optarg); + taps_requested=g_slist_append(taps_requested, tr); + return TRUE; + } + } + return FALSE; +} + +/* ********************************************************************** + * Function to list all possible tap command-line arguments + * ********************************************************************** */ +void +list_tap_cmd_args(void) +{ + tap_cmd_arg *tca; + + for(tca=tap_cmd_arg_list;tca;tca=tca->next){ + fprintf(stderr," %s\n",tca->cmd); + } +} + +/* ********************************************************************** + * Function to process taps requested with command-line arguments + * ********************************************************************** */ +void +start_requested_taps(void) +{ + tap_requested *tr; + + while(taps_requested){ + tr=taps_requested->data; + (*tr->tca->func)(tr->arg); + g_free(tr->arg); + g_free(tr); + taps_requested=g_slist_remove(taps_requested, tr); + } +} /* ********************************************************************** * Functions called from dissector when made tappable |