2 * boop_stat 2003 Jean-Michel FAYARD
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include "epan/packet_info.h"
34 #include <epan/stat_cmd_args.h>
38 typedef const char* bootp_info_value_t;
40 /* used to keep track of the statictics for an entire program interface */
41 typedef struct _dhcp_stats_t {
44 guint index; /* Number of to display */
46 /* used to keep track of a single DHCP message type */
47 typedef struct _dhcp_message_type_t {
50 dhcpstat_t *sp; /* entire program interface */
51 } dhcp_message_type_t;
54 /* Not used anywhere at this moment */
57 dhcp_free_hash( gpointer key _U_ , gpointer value, gpointer user_data _U_ )
64 dhcp_reset_hash(gchar *key _U_ , dhcp_message_type_t *data, gpointer ptr _U_ )
69 /* Update the entry corresponding to the number of packets of a special DHCP Message Type
70 * or create it if it don't exist.
73 dhcp_draw_message_type(gchar *key _U_, dhcp_message_type_t *data, gchar * format )
75 if ((data==NULL) || (data->packets==0))
77 printf( format, data->name, data->packets);
80 dhcpstat_reset(void *psp)
83 g_hash_table_foreach( sp->hash, (GHFunc)dhcp_reset_hash, NULL);
86 dhcpstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
89 const bootp_info_value_t value=pri;
90 dhcp_message_type_t *sc;
94 sc = g_hash_table_lookup(
98 sc = g_malloc( sizeof(dhcp_message_type_t) );
107 /*g_warning("sc(%s)->packets++", sc->name);*/
115 dhcpstat_draw(void *psp)
120 printf("===================================================================\n");
122 if (sp->filter==NULL)
123 printf("BOOTP Statistics\n");
125 printf("BOOTP Statistics with filter %s\n", sp->filter);
126 printf("BOOTP Option 53: DHCP Messages Types:\n");
127 printf("DHCP Message Type Packets nb\n" );
128 g_hash_table_foreach( sp->hash, (GHFunc) dhcp_draw_message_type,
130 printf("===================================================================\n");
137 /* When called, this function will create a new instance of tap-boopstat.
140 dhcpstat_init(const char *optarg, void* userdata _U_)
143 const char *filter=NULL;
144 GString *error_string;
146 if (!strncmp (optarg, "bootp,stat,", 11)){
152 sp = g_malloc( sizeof(dhcpstat_t) );
153 sp->hash = g_hash_table_new( g_str_hash, g_str_equal);
155 sp->filter=g_strdup(filter);
159 sp->index = 0; /* Nothing to display yet */
161 error_string = register_tap_listener(
169 /* error, we failed to attach to the tap. clean up */
172 fprintf(stderr, "tshark: Couldn't register dhcp,stat tap: %s\n",
174 g_string_free(error_string, TRUE);
182 register_tap_listener_gtkdhcpstat(void)
184 register_stat_cmd_arg("bootp,stat,", dhcpstat_init,NULL);