aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/stats_tree/pinfo_stats_tree.c
blob: 34d6194d00cd772e0e312a981d54aa7fbd606ba9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* pinfo_stats_tree.c
* Stats tree for ethernet frames
*
*  (c) 2005, Luis E. G. Ontanon <luis.ontanon@gmail.com>
*
* $Id$
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* 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>

#include "pinfo_stats_tree.h"

/* XXX: this belongs to to_str.c */
static const gchar* port_type_to_str (port_type type) {
	switch (type) {
		case PT_NONE:   return "NONE";
		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";
		case PT_EXCHG:	return "FC EXCHG";
		case PT_DDP:	return "DDP";
		case PT_SBCCS:	return "FICON SBCCS";
		case PT_IDP:	return "IDP";
        default:        return "[Unknown]";
	}
}

/* ip host stats_tree -- basic test */
static int st_node_ip = -1;
static gchar* st_str_ip = "IP address";

static void ip_hosts_stats_tree_init(stats_tree* st) {
	st_node_ip = stats_tree_create_node(st, st_str_ip, 0, TRUE);	
}

static int ip_hosts_stats_tree_packet(stats_tree *st  , packet_info *pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
	static guint8 str[128];
	
	tick_stat_node(st, st_str_ip, 0, FALSE);
	
	g_snprintf(str, sizeof(str),"%s",address_to_str(&pinfo->net_src));
	tick_stat_node(st, str, st_node_ip, FALSE);

	g_snprintf(str, sizeof(str),"%s",address_to_str(&pinfo->net_dst));
	tick_stat_node(st, str, st_node_ip, FALSE);
	
	return 1;
}

/* packet type stats_tree -- test pivot node */
static int st_node_ptype = -1;
static gchar* st_str_ptype = "Port Type";

static void ptype_stats_tree_init(stats_tree* st) {
	st_node_ptype = stats_tree_create_pivot(st, st_str_ptype, 0);
}

static int ptype_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
	const gchar* ptype;
	
	ptype = port_type_to_str(pinfo->ptype);

	stats_tree_tick_pivot(st,st_node_ptype,ptype);
	
	return 1;
}

/* packet length stats_tree -- test range node */ 
static int st_node_plen = -1;
static gchar* st_str_plen = "Packet Length";

static void plen_stats_tree_init(stats_tree* st) {
	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-",NULL);
}

static int plen_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
	tick_stat_node(st, st_str_plen, 0, FALSE);
	stats_tree_tick_range(st, st_str_plen, 0, pinfo->fd->pkt_len);
	
	return 1;
}

/* a tree exapmple
 - IP
    - PROTO
	   - PORT

*/
static int st_node_dsts = -1;
static gchar* st_str_dsts = "Destinations";

static void dsts_stats_tree_init(stats_tree* st) {
	st_node_dsts = stats_tree_create_node(st, st_str_dsts, 0, TRUE);	
}

static int dsts_stats_tree_packet(stats_tree* st, packet_info* pinfo, epan_dissect_t *edt _U_, const void *p _U_) {
	static guint8 str[128];
	int ip_dst_node;
	int proto_node;
	
	tick_stat_node(st, st_str_dsts, 0, FALSE);
	
	g_snprintf(str, sizeof(str),"%s",address_to_str(&pinfo->net_src));
	ip_dst_node = tick_stat_node(st, str, st_node_dsts, TRUE);
	
	proto_node = tick_stat_node(st,port_type_to_str(pinfo->ptype),ip_dst_node,TRUE);

	g_snprintf(str, sizeof(str),"%u",pinfo->destport);
	tick_stat_node(st,str,proto_node,TRUE);
	
	return 1;
}

/* register all pinfo trees */
void register_pinfo_stat_trees(void) {
	stats_tree_register("ip","ip_hosts",st_str_ip, ip_hosts_stats_tree_packet, ip_hosts_stats_tree_init, NULL );
	stats_tree_register("ip","ptype",st_str_ptype, ptype_stats_tree_packet, ptype_stats_tree_init, NULL );
	stats_tree_register("frame","plen",st_str_plen, plen_stats_tree_packet, plen_stats_tree_init, NULL );
	stats_tree_register("ip","dests",st_str_dsts, dsts_stats_tree_packet, dsts_stats_tree_init, NULL );
}