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