2005-02-20 05:39:24 +00:00
|
|
|
/* pinfo_stats_tree.c
|
2005-02-16 14:26:27 +00:00
|
|
|
* Stats tree for ethernet frames
|
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* (c) 2005, Luis E. G. Ontanon <luis@ontanon.org>
|
2005-02-16 14:26:27 +00:00
|
|
|
*
|
2005-02-20 05:39:24 +00:00
|
|
|
* $Id$
|
2005-02-16 14:26:27 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-02-16 14:26:27 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <epan/stats_tree.h>
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
#include "pinfo_stats_tree.h"
|
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
/* XXX: this belongs to to_str.c */
|
2005-02-16 14:26:27 +00:00
|
|
|
static const gchar* port_type_to_str (port_type type) {
|
|
|
|
switch (type) {
|
2005-02-25 05:15:18 +00:00
|
|
|
case PT_NONE: return "NONE";
|
2005-02-16 14:26:27 +00:00
|
|
|
case PT_SCTP: return "SCTP";
|
|
|
|
case PT_TCP: return "TCP";
|
|
|
|
case PT_UDP: return "UDP";
|
|
|
|
case PT_IPX: return "IPX";
|
|
|
|
case PT_NCP: return "NCP";
|
2005-03-06 20:13:58 +00:00
|
|
|
case PT_EXCHG: return "FC EXCHG";
|
|
|
|
case PT_DDP: return "DDP";
|
|
|
|
case PT_SBCCS: return "FICON SBCCS";
|
2005-03-21 01:32:26 +00:00
|
|
|
case PT_IDP: return "IDP";
|
2005-06-10 18:30:33 +00:00
|
|
|
default: return "[Unknown]";
|
2005-02-16 14:26:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
/* ip host stats_tree -- basic test */
|
|
|
|
static int st_node_ip = -1;
|
2008-04-14 01:11:07 +00:00
|
|
|
static const gchar* st_str_ip = "IP Addresses";
|
2005-02-24 22:04:34 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void ip_hosts_stats_tree_init(stats_tree* st) {
|
2009-09-06 14:25:47 +00:00
|
|
|
st_node_ip = stats_tree_create_node(st, st_str_ip, 0, TRUE);
|
2005-02-16 14:26:27 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int ip_hosts_stats_tree_packet(stats_tree *st , packet_info *pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2007-03-28 21:55:11 +00:00
|
|
|
tick_stat_node(st, st_str_ip, 0, FALSE);
|
2009-09-06 14:25:47 +00:00
|
|
|
tick_stat_node(st, ep_address_to_str(&pinfo->net_src), st_node_ip, FALSE);
|
|
|
|
tick_stat_node(st, ep_address_to_str(&pinfo->net_dst), st_node_ip, FALSE);
|
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* packet type stats_tree -- test pivot node */
|
|
|
|
static int st_node_ptype = -1;
|
2008-04-14 01:11:07 +00:00
|
|
|
static const gchar* st_str_ptype = "IP Protocol Types";
|
2005-02-24 22:04:34 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void ptype_stats_tree_init(stats_tree* st) {
|
2005-03-21 01:32:26 +00:00
|
|
|
st_node_ptype = stats_tree_create_pivot(st, st_str_ptype, 0);
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int ptype_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2005-02-24 22:04:34 +00:00
|
|
|
const gchar* ptype;
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
ptype = port_type_to_str(pinfo->ptype);
|
|
|
|
|
2005-03-21 01:32:26 +00:00
|
|
|
stats_tree_tick_pivot(st,st_node_ptype,ptype);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
2009-09-06 14:25:47 +00:00
|
|
|
/* packet length stats_tree -- test range node */
|
2005-02-24 22:04:34 +00:00
|
|
|
static int st_node_plen = -1;
|
2008-04-14 01:11:07 +00:00
|
|
|
static const gchar* st_str_plen = "Packet Lengths";
|
2005-02-24 22:04:34 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void plen_stats_tree_init(stats_tree* st) {
|
2006-04-27 22:13:29 +00:00
|
|
|
st_node_plen = stats_tree_create_range_node(st, st_str_plen, 0, "0-19","20-39","40-79","80-159","160-319","320-639","640-1279","1280-2559","2560-5119","5120-",NULL);
|
2005-02-16 14:26:27 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int plen_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2007-03-28 21:55:11 +00:00
|
|
|
tick_stat_node(st, st_str_plen, 0, FALSE);
|
2005-03-21 01:32:26 +00:00
|
|
|
stats_tree_tick_range(st, st_str_plen, 0, pinfo->fd->pkt_len);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
2005-02-16 14:26:27 +00:00
|
|
|
|
2006-04-27 22:13:29 +00:00
|
|
|
/* a tree example
|
2005-02-25 05:15:18 +00:00
|
|
|
- IP
|
|
|
|
- PROTO
|
|
|
|
- PORT
|
|
|
|
|
|
|
|
*/
|
|
|
|
static int st_node_dsts = -1;
|
2008-04-14 01:11:07 +00:00
|
|
|
static const gchar* st_str_dsts = "IP Destinations";
|
2005-02-25 05:15:18 +00:00
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static void dsts_stats_tree_init(stats_tree* st) {
|
2009-09-06 14:25:47 +00:00
|
|
|
st_node_dsts = stats_tree_create_node(st, st_str_dsts, 0, TRUE);
|
2005-02-25 05:15:18 +00:00
|
|
|
}
|
|
|
|
|
2005-07-24 10:32:22 +00:00
|
|
|
static int dsts_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
|
2008-07-11 21:13:39 +00:00
|
|
|
static gchar str[128];
|
2005-02-25 05:15:18 +00:00
|
|
|
int ip_dst_node;
|
2010-01-28 23:53:27 +00:00
|
|
|
int protocol_node;
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2007-03-28 21:55:11 +00:00
|
|
|
tick_stat_node(st, st_str_dsts, 0, FALSE);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
|
|
|
ip_dst_node = tick_stat_node(st, ep_address_to_str(&pinfo->net_src), st_node_dsts, TRUE);
|
|
|
|
|
2010-01-28 23:53:27 +00:00
|
|
|
protocol_node = tick_stat_node(st,port_type_to_str(pinfo->ptype),ip_dst_node,TRUE);
|
2005-02-25 05:15:18 +00:00
|
|
|
|
2007-03-28 21:55:11 +00:00
|
|
|
g_snprintf(str, sizeof(str),"%u",pinfo->destport);
|
2010-01-28 23:53:27 +00:00
|
|
|
tick_stat_node(st,str,protocol_node,TRUE);
|
2009-09-06 14:25:47 +00:00
|
|
|
|
2005-02-25 05:15:18 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-02-24 22:04:34 +00:00
|
|
|
/* register all pinfo trees */
|
2005-07-24 21:23:10 +00:00
|
|
|
void register_pinfo_stat_trees(void) {
|
2009-06-05 22:42:47 +00:00
|
|
|
stats_tree_register("ip","ip_hosts",st_str_ip, 0, ip_hosts_stats_tree_packet, ip_hosts_stats_tree_init, NULL );
|
|
|
|
stats_tree_register("ip","ptype",st_str_ptype, 0, ptype_stats_tree_packet, ptype_stats_tree_init, NULL );
|
|
|
|
stats_tree_register_with_group("frame","plen",st_str_plen, 0, plen_stats_tree_packet, plen_stats_tree_init, NULL, REGISTER_STAT_GROUP_GENERIC );
|
|
|
|
stats_tree_register("ip","dests",st_str_dsts, 0, dsts_stats_tree_packet, dsts_stats_tree_init, NULL );
|
2005-02-24 22:04:34 +00:00
|
|
|
}
|
2009-09-06 14:25:47 +00:00
|
|
|
|