Update Free Software Foundation address.
[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 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <stdio.h>
36
37 #include <string.h>
38 #include "epan/packet_info.h"
39 #include "epan/value_string.h"
40 #include <epan/tap.h>
41 #include <epan/stat_cmd_args.h>
42 #include <epan/dissectors/packet-bssap.h>
43 #include <epan/dissectors/packet-ansi_a.h>
44
45
46 typedef struct _ansi_a_stat_t {
47     int         bsmap_message_type[0xff];
48     int         dtap_message_type[0xff];
49 } ansi_a_stat_t;
50
51
52 static int
53 ansi_a_stat_packet(
54     void                        *tapdata,
55     packet_info                 *pinfo _U_,
56     epan_dissect_t              *edt _U_,
57     const void                  *data)
58 {
59     ansi_a_stat_t               *stat_p = tapdata;
60     const ansi_a_tap_rec_t      *tap_p = data;
61
62
63     switch (tap_p->pdu_type)
64     {
65     case BSSAP_PDU_TYPE_BSMAP:
66         stat_p->bsmap_message_type[tap_p->message_type]++;
67         break;
68
69     case BSSAP_PDU_TYPE_DTAP:
70         stat_p->dtap_message_type[tap_p->message_type]++;
71         break;
72
73     default:
74         /*
75          * unknown PDU type !!!
76          */
77         return(0);
78     }
79
80     return(1);
81 }
82
83
84 static void
85 ansi_a_stat_draw(
86     void                *tapdata)
87 {
88     ansi_a_stat_t       *stat_p = tapdata;
89     guint8              i;
90
91
92     printf("\n");
93     printf("=========== ANSI A-i/f Statistics ============================\n");
94     printf("BSMAP\n");
95     printf("Message (ID)Type                                        Number\n");
96
97     i = 0;
98     while (ansi_a_ios401_bsmap_strings[i].strptr)
99     {
100         if (stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value] > 0)
101         {
102             printf("0x%02x  %-50s%d\n",
103                 ansi_a_ios401_bsmap_strings[i].value,
104                 ansi_a_ios401_bsmap_strings[i].strptr,
105                 stat_p->bsmap_message_type[ansi_a_ios401_bsmap_strings[i].value]);
106         }
107
108         i++;
109     }
110
111     printf("\nDTAP\n");
112     printf("Message (ID)Type                                        Number\n");
113
114     i = 0;
115     while (ansi_a_ios401_dtap_strings[i].strptr)
116     {
117         if (stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value] > 0)
118         {
119             printf("0x%02x  %-50s%d\n",
120                 ansi_a_ios401_dtap_strings[i].value,
121                 ansi_a_ios401_dtap_strings[i].strptr,
122                 stat_p->dtap_message_type[ansi_a_ios401_dtap_strings[i].value]);
123         }
124
125         i++;
126     }
127
128     printf("==============================================================\n");
129 }
130
131
132 static void
133 ansi_a_stat_init(const char *optarg _U_, void* userdata _U_)
134 {
135     ansi_a_stat_t       *stat_p;
136     GString             *err_p;
137
138     stat_p = g_malloc(sizeof(ansi_a_stat_t));
139
140     memset(stat_p, 0, sizeof(ansi_a_stat_t));
141
142     err_p =
143         register_tap_listener("ansi_a", stat_p, NULL, 0,
144             NULL,
145             ansi_a_stat_packet,
146             ansi_a_stat_draw);
147
148     if (err_p != NULL)
149     {
150         g_free(stat_p);
151         g_string_free(err_p, TRUE);
152
153         exit(1);
154     }
155 }
156
157
158 void
159 register_tap_listener_ansi_astat(void)
160 {
161     register_stat_cmd_arg("ansi_a,", ansi_a_stat_init,NULL);
162 }