mate runtime did not get initialized when configured after loading a capture file
[obnox/wireshark/wip.git] / tap-ansi_astat.c
1 /* tap-ansi_astat.c
2  *
3  * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
4  * In association with Telos Technology Inc.
5  *
6  * $Id$
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 /*
28  * This TAP provides statistics for the ANSI A Interface:
29  */
30
31 /* With MSVC and a libethereal.dll this file needs to import some variables 
32    in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */   
33 #define _NEED_VAR_IMPORT_
34
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <stdio.h>
40
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
43 #endif
44
45 #include <string.h>
46 #include "epan/packet_info.h"
47 #include "epan/value_string.h"
48 #include <epan/tap.h>
49 #include <epan/dissectors/packet-bssap.h>
50 #include <epan/dissectors/packet-ansi_a.h>
51 #include "register.h"
52
53
54 typedef struct _ansi_a_stat_t {
55     int         bsmap_message_type[0xff];
56     int         dtap_message_type[0xff];
57 } ansi_a_stat_t;
58
59
60 static int
61 ansi_a_stat_packet(
62     void                        *tapdata,
63     packet_info                 *pinfo _U_,
64     epan_dissect_t              *edt _U_,
65     const void                  *data)
66 {
67     ansi_a_stat_t               *stat_p = tapdata;
68     const ansi_a_tap_rec_t      *tap_p = data;
69
70
71     switch (tap_p->pdu_type)
72     {
73     case BSSAP_PDU_TYPE_BSMAP:
74         stat_p->bsmap_message_type[tap_p->message_type]++;
75         break;
76
77     case BSSAP_PDU_TYPE_DTAP:
78         stat_p->dtap_message_type[tap_p->message_type]++;
79         break;
80
81     default:
82         /*
83          * unknown PDU type !!!
84          */
85         return(0);
86     }
87
88     return(1);
89 }
90
91
92 static void
93 ansi_a_stat_draw(
94     void                *tapdata)
95 {
96     ansi_a_stat_t       *stat_p = tapdata;
97     guint8              i;
98
99
100     printf("\n");
101     printf("=========== ANSI A-i/f Statistics ============================\n");
102     printf("BSMAP\n");
103     printf("Message (ID)Type                                        Number\n");
104
105     i = 0;
106     while (ansi_a_ios401_bsmap_strings[i].strptr)
107     {
108         if (stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value] > 0)
109         {
110             printf("0x%02x  %-50s%d\n",
111                 ansi_a_ios401_bsmap_strings[i].value,
112                 ansi_a_ios401_bsmap_strings[i].strptr,
113                 stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value]);
114         }
115
116         i++;
117     }
118
119     printf("\nDTAP\n");
120     printf("Message (ID)Type                                        Number\n");
121
122     i = 0;
123     while (ansi_a_ios401_dtap_strings[i].strptr)
124     {
125         if (stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value] > 0)
126         {
127             printf("0x%02x  %-50s%d\n",
128                 ansi_a_ios401_dtap_strings[i].value,
129                 ansi_a_ios401_dtap_strings[i].strptr,
130                 stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value]);
131         }
132
133         i++;
134     }
135
136     printf("==============================================================\n");
137 }
138
139
140 static void
141 ansi_a_stat_init(char *optarg)
142 {
143     ansi_a_stat_t       *stat_p;
144     GString             *err_p;
145
146
147     optarg = optarg;
148
149     stat_p = g_malloc(sizeof(ansi_a_stat_t));
150
151     memset(stat_p, 0, sizeof(ansi_a_stat_t));
152
153     err_p =
154         register_tap_listener("ansi_a", stat_p, NULL,
155             NULL,
156             ansi_a_stat_packet,
157             ansi_a_stat_draw);
158
159     if (err_p != NULL)
160     {
161         g_free(stat_p);
162         g_string_free(err_p, TRUE);
163
164         exit(1);
165     }
166 }
167
168
169 void
170 register_tap_listener_ansi_astat(void)
171 {
172     register_ethereal_tap("ansi_a,", ansi_a_stat_init);
173 }