Have tap listeners specify whether the "packet" routine requires
[obnox/wireshark/wip.git] / plugins / stats_tree / pinfo_stats_tree.c
1 /* pinfo_stats_tree.c
2 * Stats tree for ethernet frames
3 *
4 *  (c) 2005, Luis E. G. Ontanon <luis@ontanon.org>
5 *
6 * $Id$
7 *
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
11 *
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.
16 *
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.
21 *
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.
25 */
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <epan/stats_tree.h>
32
33 #include "pinfo_stats_tree.h"
34
35 /* XXX: this belongs to to_str.c */
36 static const gchar* port_type_to_str (port_type type) {
37         switch (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]";
49         }
50 }
51
52 /* ip host stats_tree -- basic test */
53 static int st_node_ip = -1;
54 static const gchar* st_str_ip = "IP Addresses";
55
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);    
58 }
59
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);
64         
65         return 1;
66 }
67
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";
71
72 static void ptype_stats_tree_init(stats_tree* st) {
73         st_node_ptype = stats_tree_create_pivot(st, st_str_ptype, 0);
74 }
75
76 static int ptype_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
77         const gchar* ptype;
78         
79         ptype = port_type_to_str(pinfo->ptype);
80
81         stats_tree_tick_pivot(st,st_node_ptype,ptype);
82         
83         return 1;
84 }
85
86 /* packet length stats_tree -- test range node */ 
87 static int st_node_plen = -1;
88 static const gchar* st_str_plen = "Packet Lengths";
89
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);
92 }
93
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);
97         
98         return 1;
99 }
100
101 /* a tree example
102  - IP
103     - PROTO
104            - PORT
105
106 */
107 static int st_node_dsts = -1;
108 static const gchar* st_str_dsts = "IP Destinations";
109
110 static void dsts_stats_tree_init(stats_tree* st) {
111         st_node_dsts = stats_tree_create_node(st, st_str_dsts, 0, TRUE);        
112 }
113
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];
116         int ip_dst_node;
117         int proto_node;
118         
119         tick_stat_node(st, st_str_dsts, 0, FALSE);
120         
121         ip_dst_node = tick_stat_node(st, address_to_str(&pinfo->net_src), st_node_dsts, TRUE);
122         
123         proto_node = tick_stat_node(st,port_type_to_str(pinfo->ptype),ip_dst_node,TRUE);
124
125         g_snprintf(str, sizeof(str),"%u",pinfo->destport);
126         tick_stat_node(st,str,proto_node,TRUE);
127         
128         return 1;
129 }
130
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 );
137 }
138