2 * camel message counter for tshark
3 * Copyright 2006 Florent DROUIN
4 * This part of code is extracted from tap-h225counter.c from Lars Roland
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
36 #include "epan/packet_info.h"
38 #include "epan/value_string.h"
40 #include "epan/stat_cmd_args.h"
41 #include "epan/camel-persistentdata.h"
43 void register_tap_listener_camelcounter(void);
45 /* used to keep track of the statistics for an entire program interface */
46 struct camelcounter_t {
48 guint32 camel_msg[camel_MAX_NUM_OPR_CODES];
52 static void camelcounter_reset(void *phs)
54 struct camelcounter_t * p_counter= ( struct camelcounter_t *) phs;
55 memset(p_counter,0,sizeof(struct camelcounter_t));
58 static int camelcounter_packet(void *phs,
59 packet_info *pinfo _U_,
60 epan_dissect_t *edt _U_,
63 struct camelcounter_t * p_counter =(struct camelcounter_t *)phs;
64 const struct camelsrt_info_t * pi=phi;
65 if (pi->opcode != 255)
66 p_counter->camel_msg[pi->opcode]++;
72 static void camelcounter_draw(void *phs)
74 struct camelcounter_t * p_counter= (struct camelcounter_t *)phs;
77 printf("CAMEL Message and Response Status Counter:\n");
78 printf("------------------------------------------\n");
80 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
82 if(p_counter->camel_msg[i]!=0) {
83 printf("%30s ", val_to_str(i,camel_opr_code_strings,"Unknown message "));
84 printf("%6d\n", p_counter->camel_msg[i]);
87 printf("------------------------------------------\n");
90 static void camelcounter_init(const char *optarg, void* userdata _U_)
92 struct camelcounter_t *p_camelcounter;
93 const char *filter=NULL;
94 const char *emptyfilter="";
95 GString *error_string;
97 if(!strncmp(optarg,"camel,counter,",13)){
103 p_camelcounter = g_malloc(sizeof(struct camelcounter_t));
105 p_camelcounter->filter=g_malloc(strlen(filter)+1);
106 strcpy(p_camelcounter->filter,filter);
108 p_camelcounter->filter=NULL;
111 camelcounter_reset(p_camelcounter);
114 error_string=register_tap_listener("CAMEL",
121 error_string=register_tap_listener("CAMEL",
130 /* error, we failed to attach to the tap. clean up */
131 g_free(p_camelcounter->filter);
132 g_free(p_camelcounter);
134 fprintf(stderr, "tshark: Couldn't register camel,counter tap: %s\n",
136 g_string_free(error_string, TRUE);
142 void /* Next line mandatory */
143 register_tap_listener_camelcounter(void)
145 register_stat_cmd_arg("camel,counter", camelcounter_init, NULL);