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.h"
37 #include "epan/packet_info.h"
39 #include "epan/value_string.h"
41 #include "epan/stat_cmd_args.h"
42 #include "epan/asn1.h"
43 #include "epan/camel-persistentdata.h"
45 void register_tap_listener_camelcounter(void);
47 /* used to keep track of the statistics for an entire program interface */
48 struct camelcounter_t {
50 guint32 camel_msg[camel_MAX_NUM_OPR_CODES];
54 static void camelcounter_reset(void *phs)
56 struct camelcounter_t * p_counter= ( struct camelcounter_t *) phs;
57 memset(p_counter,0,sizeof(struct camelcounter_t));
60 static int camelcounter_packet(void *phs,
61 packet_info *pinfo _U_,
62 epan_dissect_t *edt _U_,
65 struct camelcounter_t * p_counter =(struct camelcounter_t *)phs;
66 const struct camelsrt_info_t * pi=phi;
67 if (pi->opcode != 255)
68 p_counter->camel_msg[pi->opcode]++;
74 static void camelcounter_draw(void *phs)
76 struct camelcounter_t * p_counter= (struct camelcounter_t *)phs;
79 printf("CAMEL Message and Response Status Counter:\n");
80 printf("------------------------------------------\n");
82 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
84 if(p_counter->camel_msg[i]!=0) {
85 printf("%30s ", val_to_str(i,camel_opr_code_strings,"Unknown message "));
86 printf("%6d\n", p_counter->camel_msg[i]);
89 printf("------------------------------------------\n");
92 static void camelcounter_init(const char *optarg, void* userdata _U_)
94 struct camelcounter_t *p_camelcounter;
95 const char *filter=NULL;
96 const char *emptyfilter="";
97 GString *error_string;
99 if(!strncmp(optarg,"camel,counter,",13)){
105 p_camelcounter = g_malloc(sizeof(struct camelcounter_t));
107 p_camelcounter->filter=g_malloc(strlen(filter)+1);
108 strcpy(p_camelcounter->filter,filter);
110 p_camelcounter->filter=NULL;
113 camelcounter_reset(p_camelcounter);
116 error_string=register_tap_listener("CAMEL",
123 error_string=register_tap_listener("CAMEL",
132 /* error, we failed to attach to the tap. clean up */
133 g_free(p_camelcounter->filter);
134 g_free(p_camelcounter);
136 fprintf(stderr, "tshark: Couldn't register camel,counter tap: %s\n",
138 g_string_free(error_string, TRUE);
144 void /* Next line mandatory */
145 register_tap_listener_camelcounter(void)
147 register_stat_cmd_arg("camel,counter", camelcounter_init, NULL);