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>
37 typedef const char* bootp_info_value_t;
39 /* used to keep track of the statictics for an entire program interface */
40 typedef struct _dhcp_stats_t {
43 guint index; /* Number of to display */
45 /* used to keep track of a single DHCP message type */
46 typedef struct _dhcp_message_type_t {
49 dhcpstat_t *sp; /* entire program interface */
50 } dhcp_message_type_t;
53 /* Not used anywhere at this moment */
56 dhcp_free_hash( gpointer key _U_ , gpointer value, gpointer user_data _U_ )
63 dhcp_reset_hash(gchar *key _U_ , dhcp_message_type_t *data, gpointer ptr _U_ )
68 /* Update the entry corresponding to the number of packets of a special DHCP Message Type
69 * or create it if it don't exist.
72 dhcp_draw_message_type(gchar *key _U_, dhcp_message_type_t *data, gchar * format )
74 if ((data==NULL) || (data->packets==0))
76 printf( format, data->name, data->packets);
79 dhcpstat_reset(void *psp)
82 g_hash_table_foreach( sp->hash, (GHFunc)dhcp_reset_hash, NULL);
85 dhcpstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
88 const bootp_info_value_t value=pri;
89 dhcp_message_type_t *sc;
93 sc = g_hash_table_lookup(
97 sc = g_malloc( sizeof(dhcp_message_type_t) );
106 /*g_warning("sc(%s)->packets++", sc->name);*/
114 dhcpstat_draw(void *psp)
119 printf("===================================================================\n");
121 if (sp->filter==NULL)
122 printf("BOOTP Statistics\n");
124 printf("BOOTP Statistics with filter %s\n", sp->filter);
125 printf("BOOTP Option 53: DHCP Messages Types:\n");
126 printf("DHCP Message Type Packets nb\n" );
127 g_hash_table_foreach( sp->hash, (GHFunc) dhcp_draw_message_type,
129 printf("===================================================================\n");
136 /* When called, this function will create a new instance of tap-boopstat.
139 dhcpstat_init(const char *optarg, void* userdata _U_)
142 const char *filter=NULL;
143 GString *error_string;
145 if (!strncmp (optarg, "bootp,stat,", 11)){
151 sp = g_malloc( sizeof(dhcpstat_t) );
152 sp->hash = g_hash_table_new( g_str_hash, g_str_equal);
154 sp->filter=g_strdup(filter);
158 sp->index = 0; /* Nothing to display yet */
160 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);