HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / ui / cli / tap-camelcounter.c
blobd1fd5dbf4424753572d0dd2088c987f55f0bc9b9
1 /* tap_camelcounter.c
2 * camel message counter for tshark
3 * Copyright 2006 Florent DROUIN
5 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "config.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
34 #include "epan/packet.h"
35 #include "epan/packet_info.h"
36 #include "epan/tap.h"
37 #include "epan/value_string.h"
38 #include "epan/stat_cmd_args.h"
39 #include "epan/asn1.h"
40 #include "epan/camel-persistentdata.h"
42 void register_tap_listener_camelcounter(void);
44 /* used to keep track of the statistics for an entire program interface */
45 struct camelcounter_t {
46 char *filter;
47 guint32 camel_msg[camel_MAX_NUM_OPR_CODES];
51 static void camelcounter_reset(void *phs)
53 struct camelcounter_t * p_counter= ( struct camelcounter_t *) phs;
54 memset(p_counter,0,sizeof(struct camelcounter_t));
57 static int camelcounter_packet(void *phs,
58 packet_info *pinfo _U_,
59 epan_dissect_t *edt _U_,
60 const void *phi)
62 struct camelcounter_t * p_counter =(struct camelcounter_t *)phs;
63 const struct camelsrt_info_t * pi=(const struct camelsrt_info_t *)phi;
64 if (pi->opcode != 255)
65 p_counter->camel_msg[pi->opcode]++;
67 return 1;
71 static void camelcounter_draw(void *phs)
73 struct camelcounter_t * p_counter= (struct camelcounter_t *)phs;
74 int i;
75 printf("\n");
76 printf("CAMEL Message and Response Status Counter:\n");
77 printf("------------------------------------------\n");
79 for(i=0;i<camel_MAX_NUM_OPR_CODES;i++) {
80 /* Message counter */
81 if(p_counter->camel_msg[i]!=0) {
82 printf("%30s ", val_to_str(i,camel_opr_code_strings,"Unknown message "));
83 printf("%6d\n", p_counter->camel_msg[i]);
85 } /* Message Type */
86 printf("------------------------------------------\n");
89 static void camelcounter_init(const char *opt_arg, void* userdata _U_)
91 struct camelcounter_t *p_camelcounter;
92 GString *error_string;
94 p_camelcounter = g_new(struct camelcounter_t,1);
95 if(!strncmp(opt_arg,"camel,counter,",13)){
96 p_camelcounter->filter=g_strdup(opt_arg+13);
97 } else {
98 p_camelcounter->filter=NULL;
101 camelcounter_reset(p_camelcounter);
103 error_string=register_tap_listener("CAMEL",
104 p_camelcounter,
105 p_camelcounter->filter,
107 NULL,
108 camelcounter_packet,
109 camelcounter_draw);
111 if(error_string){
112 /* error, we failed to attach to the tap. clean up */
113 g_free(p_camelcounter->filter);
114 g_free(p_camelcounter);
116 fprintf(stderr, "tshark: Couldn't register camel,counter tap: %s\n",
117 error_string->str);
118 g_string_free(error_string, TRUE);
119 exit(1);
124 void /* Next line mandatory */
125 register_tap_listener_camelcounter(void)
127 register_stat_cmd_arg("camel,counter", camelcounter_init, NULL);