Get rid of -Wshadow warning - I guess we're including something that
[metze/wireshark/wip.git] / ui / cli / 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  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 /*
28  * This TAP provides statistics for the ANSI A Interface:
29  */
30
31 #include "config.h"
32
33 #include <stdio.h>
34
35 #include <string.h>
36 #include "epan/packet_info.h"
37 #include "epan/value_string.h"
38 #include <epan/tap.h>
39 #include <epan/stat_cmd_args.h>
40 #include <epan/dissectors/packet-bssap.h>
41 #include <epan/dissectors/packet-ansi_a.h>
42
43
44 typedef struct _ansi_a_stat_t {
45     int         bsmap_message_type[0xff];
46     int         dtap_message_type[0xff];
47 } ansi_a_stat_t;
48
49
50 static int
51 ansi_a_stat_packet(
52     void                        *tapdata,
53     packet_info                 *pinfo _U_,
54     epan_dissect_t              *edt _U_,
55     const void                  *data)
56 {
57     ansi_a_stat_t               *stat_p = (ansi_a_stat_t *)tapdata;
58     const ansi_a_tap_rec_t      *tap_p = (const ansi_a_tap_rec_t *)data;
59
60
61     switch (tap_p->pdu_type)
62     {
63     case BSSAP_PDU_TYPE_BSMAP:
64         stat_p->bsmap_message_type[tap_p->message_type]++;
65         break;
66
67     case BSSAP_PDU_TYPE_DTAP:
68         stat_p->dtap_message_type[tap_p->message_type]++;
69         break;
70
71     default:
72         /*
73          * unknown PDU type !!!
74          */
75         return(0);
76     }
77
78     return(1);
79 }
80
81
82 static void
83 ansi_a_stat_draw(
84     void                *tapdata)
85 {
86     ansi_a_stat_t       *stat_p = (ansi_a_stat_t *)tapdata;
87     guint8              i;
88
89
90     printf("\n");
91     printf("=========== ANSI A-i/f Statistics ============================\n");
92     printf("BSMAP\n");
93     printf("Message (ID)Type                                        Number\n");
94
95     i = 0;
96     while (ansi_a_ios401_bsmap_strings[i].strptr)
97     {
98         if (stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value] > 0)
99         {
100             printf("0x%02x  %-50s%d\n",
101                 ansi_a_ios401_bsmap_strings[i].value,
102                 ansi_a_ios401_bsmap_strings[i].strptr,
103                 stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value]);
104         }
105
106         i++;
107     }
108
109     printf("\nDTAP\n");
110     printf("Message (ID)Type                                        Number\n");
111
112     i = 0;
113     while (ansi_a_ios401_dtap_strings[i].strptr)
114     {
115         if (stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value] > 0)
116         {
117             printf("0x%02x  %-50s%d\n",
118                 ansi_a_ios401_dtap_strings[i].value,
119                 ansi_a_ios401_dtap_strings[i].strptr,
120                 stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value]);
121         }
122
123         i++;
124     }
125
126     printf("==============================================================\n");
127 }
128
129
130 static void
131 ansi_a_stat_init(const char *opt_arg _U_, void* userdata _U_)
132 {
133     ansi_a_stat_t       *stat_p;
134     GString             *err_p;
135
136     stat_p = (ansi_a_stat_t *)g_malloc(sizeof(ansi_a_stat_t));
137
138     memset(stat_p, 0, sizeof(ansi_a_stat_t));
139
140     err_p =
141         register_tap_listener("ansi_a", stat_p, NULL, 0,
142             NULL,
143             ansi_a_stat_packet,
144             ansi_a_stat_draw);
145
146     if (err_p != NULL)
147     {
148         g_free(stat_p);
149         g_string_free(err_p, TRUE);
150
151         exit(1);
152     }
153 }
154
155
156 void
157 register_tap_listener_ansi_astat(void)
158 {
159     register_stat_cmd_arg("ansi_a,", ansi_a_stat_init,NULL);
160 }