2 * camel message counter for tshark
3 * Copyright 2006 Florent DROUIN
7 * This part of code is extracted from tap-h225counter.c from Lars Roland
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
39 #include "epan/packet.h"
40 #include "epan/packet_info.h"
42 #include "epan/value_string.h"
43 #include "epan/stat_cmd_args.h"
44 #include "epan/asn1.h"
45 #include "epan/camel-persistentdata.h"
47 void register_tap_listener_camelcounter(void);
49 /* used to keep track of the statistics for an entire program interface */
50 struct camelcounter_t {
52 guint32 camel_msg[camel_MAX_NUM_OPR_CODES];
56 static void camelcounter_reset(void *phs)
58 struct camelcounter_t * p_counter= ( struct camelcounter_t *) phs;
59 memset(p_counter,0,sizeof(struct camelcounter_t));
62 static int camelcounter_packet(void *phs,
63 packet_info *pinfo _U_,
64 epan_dissect_t *edt _U_,
67 struct camelcounter_t * p_counter =(struct camelcounter_t *)phs;
68 const struct camelsrt_info_t * pi=phi;
69 if (pi->opcode != 255)
70 p_counter->camel_msg[pi->opcode]++;
76 static void camelcounter_draw(void *phs)
78 struct camelcounter_t * p_counter= (struct camelcounter_t *)phs;
81 printf("CAMEL Message and Response Status Counter:\n");
82 printf("------------------------------------------\n");
84 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
86 if(p_counter->camel_msg[i]!=0) {
87 printf("%30s ", val_to_str(i,camel_opr_code_strings,"Unknown message "));
88 printf("%6d\n", p_counter->camel_msg[i]);
91 printf("------------------------------------------\n");
94 static void camelcounter_init(const char *optarg, void* userdata _U_)
96 struct camelcounter_t *p_camelcounter;
97 GString *error_string;
99 p_camelcounter = g_malloc(sizeof(struct camelcounter_t));
100 if(!strncmp(optarg,"camel,counter,",13)){
101 p_camelcounter->filter=g_strdup(optarg+13);
103 p_camelcounter->filter=NULL;
106 camelcounter_reset(p_camelcounter);
108 error_string=register_tap_listener("CAMEL",
110 p_camelcounter->filter,
117 /* error, we failed to attach to the tap. clean up */
118 g_free(p_camelcounter->filter);
119 g_free(p_camelcounter);
121 fprintf(stderr, "tshark: Couldn't register camel,counter tap: %s\n",
123 g_string_free(error_string, TRUE);
129 void /* Next line mandatory */
130 register_tap_listener_camelcounter(void)
132 register_stat_cmd_arg("camel,counter", camelcounter_init, NULL);