2003-09-02 22:47:59 +00:00
|
|
|
/* tap-bootpstat.c
|
|
|
|
* boop_stat 2003 Jean-Michel FAYARD
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2003-09-02 22:47:59 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2010-09-23 06:08:19 +00:00
|
|
|
*
|
2003-09-02 22:47:59 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-09-23 06:08:19 +00:00
|
|
|
*
|
2003-09-02 22:47:59 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2010-09-23 06:08:19 +00:00
|
|
|
*
|
2003-09-02 22:47:59 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-09-02 22:47:59 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 01:29:52 +00:00
|
|
|
#include "config.h"
|
2003-09-02 22:47:59 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2013-11-10 15:59:37 +00:00
|
|
|
#include <stdlib.h>
|
2005-08-19 09:29:41 +00:00
|
|
|
#include <string.h>
|
2003-09-02 22:47:59 +00:00
|
|
|
|
|
|
|
#include "epan/packet_info.h"
|
2004-09-29 00:06:36 +00:00
|
|
|
#include <epan/tap.h>
|
2005-08-20 20:06:05 +00:00
|
|
|
#include <epan/stat_cmd_args.h>
|
2003-09-02 22:47:59 +00:00
|
|
|
|
2013-11-14 06:21:02 +00:00
|
|
|
void register_tap_listener_gtkdhcpstat(void);
|
2003-09-02 22:47:59 +00:00
|
|
|
|
2014-10-13 19:04:21 +00:00
|
|
|
typedef const char *bootp_info_value_t;
|
2003-09-02 22:47:59 +00:00
|
|
|
|
|
|
|
/* used to keep track of the statictics for an entire program interface */
|
|
|
|
typedef struct _dhcp_stats_t {
|
|
|
|
char *filter;
|
|
|
|
GHashTable *hash;
|
|
|
|
guint index; /* Number of to display */
|
|
|
|
} dhcpstat_t;
|
|
|
|
/* used to keep track of a single DHCP message type */
|
|
|
|
typedef struct _dhcp_message_type_t {
|
|
|
|
const char *name;
|
|
|
|
guint32 packets;
|
|
|
|
dhcpstat_t *sp; /* entire program interface */
|
|
|
|
} dhcp_message_type_t;
|
|
|
|
|
|
|
|
|
|
|
|
/* Not used anywhere at this moment */
|
|
|
|
/*
|
|
|
|
static void
|
|
|
|
dhcp_free_hash( gpointer key _U_ , gpointer value, gpointer user_data _U_ )
|
|
|
|
{
|
|
|
|
g_free(value);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2010-09-23 06:08:19 +00:00
|
|
|
dhcp_reset_hash(gchar *key _U_ , dhcp_message_type_t *data, gpointer ptr _U_ )
|
|
|
|
{
|
2003-09-02 22:47:59 +00:00
|
|
|
data->packets = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the entry corresponding to the number of packets of a special DHCP Message Type
|
|
|
|
* or create it if it don't exist.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dhcp_draw_message_type(gchar *key _U_, dhcp_message_type_t *data, gchar * format )
|
|
|
|
{
|
2014-10-13 19:04:21 +00:00
|
|
|
if ((data == NULL) || (data->packets == 0))
|
2003-09-02 22:47:59 +00:00
|
|
|
return;
|
|
|
|
printf( format, data->name, data->packets);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
dhcpstat_reset(void *psp)
|
|
|
|
{
|
2014-10-13 19:04:21 +00:00
|
|
|
dhcpstat_t *sp = (dhcpstat_t *)psp;
|
2010-09-23 06:08:19 +00:00
|
|
|
g_hash_table_foreach( sp->hash, (GHFunc)dhcp_reset_hash, NULL);
|
2003-09-02 22:47:59 +00:00
|
|
|
}
|
|
|
|
static int
|
2005-01-01 02:57:02 +00:00
|
|
|
dhcpstat_packet(void *psp, packet_info *pinfo _U_, epan_dissect_t *edt _U_, const void *pri)
|
2003-09-02 22:47:59 +00:00
|
|
|
{
|
2014-10-13 19:04:21 +00:00
|
|
|
dhcpstat_t *sp = (dhcpstat_t *)psp;
|
|
|
|
const bootp_info_value_t value = (const bootp_info_value_t)pri;
|
2003-09-02 22:47:59 +00:00
|
|
|
dhcp_message_type_t *sc;
|
|
|
|
|
2014-10-13 19:04:21 +00:00
|
|
|
if (sp == NULL)
|
2003-09-02 22:47:59 +00:00
|
|
|
return 0;
|
2013-03-05 22:15:20 +00:00
|
|
|
sc = (dhcp_message_type_t *)g_hash_table_lookup(
|
2010-09-23 06:08:19 +00:00
|
|
|
sp->hash,
|
2003-09-02 22:47:59 +00:00
|
|
|
value);
|
|
|
|
if (!sc) {
|
2014-10-13 19:04:21 +00:00
|
|
|
sc = g_new(dhcp_message_type_t, 1);
|
2003-09-02 22:47:59 +00:00
|
|
|
sc -> packets = 1;
|
|
|
|
sc -> name = value;
|
|
|
|
sc -> sp = sp;
|
|
|
|
g_hash_table_insert(
|
|
|
|
sp->hash,
|
|
|
|
(gpointer) value,
|
|
|
|
sc);
|
|
|
|
} else {
|
|
|
|
/*g_warning("sc(%s)->packets++", sc->name);*/
|
|
|
|
sc->packets++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
dhcpstat_draw(void *psp)
|
|
|
|
{
|
2014-10-13 19:04:21 +00:00
|
|
|
dhcpstat_t *sp = (dhcpstat_t *)psp;
|
2003-09-02 22:47:59 +00:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
printf("===================================================================\n");
|
|
|
|
|
2014-10-13 19:04:21 +00:00
|
|
|
if (sp->filter == NULL)
|
2003-09-02 22:47:59 +00:00
|
|
|
printf("BOOTP Statistics\n");
|
|
|
|
else
|
|
|
|
printf("BOOTP Statistics with filter %s\n", sp->filter);
|
|
|
|
printf("BOOTP Option 53: DHCP Messages Types:\n");
|
|
|
|
printf("DHCP Message Type Packets nb\n" );
|
|
|
|
g_hash_table_foreach( sp->hash, (GHFunc) dhcp_draw_message_type,
|
2012-12-26 05:57:06 +00:00
|
|
|
(gpointer)"%23s %-9d\n" );
|
2003-09-02 22:47:59 +00:00
|
|
|
printf("===================================================================\n");
|
2010-09-23 06:08:19 +00:00
|
|
|
|
2003-09-02 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* When called, this function will create a new instance of tap-boopstat.
|
|
|
|
*/
|
|
|
|
static void
|
2014-10-13 19:04:21 +00:00
|
|
|
dhcpstat_init(const char *opt_arg, void *userdata _U_)
|
2003-09-02 22:47:59 +00:00
|
|
|
{
|
|
|
|
dhcpstat_t *sp;
|
2014-10-13 19:04:21 +00:00
|
|
|
const char *filter = NULL;
|
2003-09-02 22:47:59 +00:00
|
|
|
GString *error_string;
|
2010-09-23 06:08:19 +00:00
|
|
|
|
2014-10-13 19:04:21 +00:00
|
|
|
if (!strncmp (opt_arg, "bootp,stat,", 11)) {
|
|
|
|
filter = opt_arg+11;
|
2003-09-02 22:47:59 +00:00
|
|
|
} else {
|
2014-10-13 19:04:21 +00:00
|
|
|
filter = NULL;
|
2003-09-02 22:47:59 +00:00
|
|
|
}
|
2010-09-23 06:08:19 +00:00
|
|
|
|
2014-10-13 19:04:21 +00:00
|
|
|
sp = g_new(dhcpstat_t, 1);
|
2003-09-02 22:47:59 +00:00
|
|
|
sp->hash = g_hash_table_new( g_str_hash, g_str_equal);
|
2014-10-13 19:04:21 +00:00
|
|
|
if (filter) {
|
|
|
|
sp->filter = g_strdup(filter);
|
2003-09-02 22:47:59 +00:00
|
|
|
} else {
|
2014-10-13 19:04:21 +00:00
|
|
|
sp->filter = NULL;
|
2003-09-02 22:47:59 +00:00
|
|
|
}
|
|
|
|
sp->index = 0; /* Nothing to display yet */
|
|
|
|
|
2010-09-23 06:08:19 +00:00
|
|
|
error_string = register_tap_listener(
|
2003-09-02 22:47:59 +00:00
|
|
|
"bootp",
|
|
|
|
sp,
|
|
|
|
filter,
|
2009-06-05 22:42:47 +00:00
|
|
|
0,
|
2003-09-02 22:47:59 +00:00
|
|
|
dhcpstat_reset,
|
|
|
|
dhcpstat_packet,
|
|
|
|
dhcpstat_draw);
|
2014-10-13 19:04:21 +00:00
|
|
|
if (error_string) {
|
2003-09-02 22:47:59 +00:00
|
|
|
/* error, we failed to attach to the tap. clean up */
|
|
|
|
g_free(sp->filter);
|
|
|
|
g_free(sp);
|
2006-05-31 17:38:42 +00:00
|
|
|
fprintf(stderr, "tshark: Couldn't register dhcp,stat tap: %s\n",
|
2003-09-02 22:47:59 +00:00
|
|
|
error_string->str);
|
|
|
|
g_string_free(error_string, TRUE);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-14 18:42:26 +00:00
|
|
|
static stat_tap_ui dhcpstat_ui = {
|
2014-11-14 18:31:04 +00:00
|
|
|
REGISTER_STAT_GROUP_GENERIC,
|
|
|
|
NULL,
|
|
|
|
"bootp,stat,",
|
|
|
|
dhcpstat_init,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
NULL
|
|
|
|
};
|
2003-09-02 22:47:59 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
register_tap_listener_gtkdhcpstat(void)
|
|
|
|
{
|
2014-11-14 18:42:26 +00:00
|
|
|
register_stat_tap_ui(&dhcpstat_ui, NULL);
|
2003-09-02 22:47:59 +00:00
|
|
|
}
|
|
|
|
|
2014-10-13 19:04:21 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|