2 * Stats tree for ethernet frames
4 * (c) 2005, Luis E. G. Ontanon <luis@ontanon.org>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
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.
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.
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.
31 #include <epan/stats_tree.h>
33 #include "pinfo_stats_tree.h"
35 /* XXX: this belongs to to_str.c */
36 static const gchar* port_type_to_str (port_type type) {
38 case PT_NONE: return "NONE";
39 case PT_SCTP: return "SCTP";
40 case PT_TCP: return "TCP";
41 case PT_UDP: return "UDP";
42 case PT_IPX: return "IPX";
43 case PT_NCP: return "NCP";
44 case PT_EXCHG: return "FC EXCHG";
45 case PT_DDP: return "DDP";
46 case PT_SBCCS: return "FICON SBCCS";
47 case PT_IDP: return "IDP";
48 default: return "[Unknown]";
52 /* ip host stats_tree -- basic test */
53 static int st_node_ip = -1;
54 static const gchar* st_str_ip = "IP Addresses";
56 static void ip_hosts_stats_tree_init(stats_tree* st) {
57 st_node_ip = stats_tree_create_node(st, st_str_ip, 0, TRUE);
60 static int ip_hosts_stats_tree_packet(stats_tree *st , packet_info *pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
61 tick_stat_node(st, st_str_ip, 0, FALSE);
62 tick_stat_node(st, address_to_str(&pinfo->net_src), st_node_ip, FALSE);
63 tick_stat_node(st, address_to_str(&pinfo->net_dst), st_node_ip, FALSE);
68 /* packet type stats_tree -- test pivot node */
69 static int st_node_ptype = -1;
70 static const gchar* st_str_ptype = "IP Protocol Types";
72 static void ptype_stats_tree_init(stats_tree* st) {
73 st_node_ptype = stats_tree_create_pivot(st, st_str_ptype, 0);
76 static int ptype_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
79 ptype = port_type_to_str(pinfo->ptype);
81 stats_tree_tick_pivot(st,st_node_ptype,ptype);
86 /* packet length stats_tree -- test range node */
87 static int st_node_plen = -1;
88 static const gchar* st_str_plen = "Packet Lengths";
90 static void plen_stats_tree_init(stats_tree* st) {
91 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);
94 static int plen_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
95 tick_stat_node(st, st_str_plen, 0, FALSE);
96 stats_tree_tick_range(st, st_str_plen, 0, pinfo->fd->pkt_len);
107 static int st_node_dsts = -1;
108 static const gchar* st_str_dsts = "IP Destinations";
110 static void dsts_stats_tree_init(stats_tree* st) {
111 st_node_dsts = stats_tree_create_node(st, st_str_dsts, 0, TRUE);
114 static int dsts_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
115 static gchar str[128];
119 tick_stat_node(st, st_str_dsts, 0, FALSE);
121 ip_dst_node = tick_stat_node(st, address_to_str(&pinfo->net_src), st_node_dsts, TRUE);
123 proto_node = tick_stat_node(st,port_type_to_str(pinfo->ptype),ip_dst_node,TRUE);
125 g_snprintf(str, sizeof(str),"%u",pinfo->destport);
126 tick_stat_node(st,str,proto_node,TRUE);
131 /* register all pinfo trees */
132 void register_pinfo_stat_trees(void) {
133 stats_tree_register("ip","ip_hosts",st_str_ip, 0, ip_hosts_stats_tree_packet, ip_hosts_stats_tree_init, NULL );
134 stats_tree_register("ip","ptype",st_str_ptype, 0, ptype_stats_tree_packet, ptype_stats_tree_init, NULL );
135 stats_tree_register_with_group("frame","plen",st_str_plen, 0, plen_stats_tree_packet, plen_stats_tree_init, NULL, REGISTER_STAT_GROUP_GENERIC );
136 stats_tree_register("ip","dests",st_str_dsts, 0, dsts_stats_tree_packet, dsts_stats_tree_init, NULL );