2 * iostat 2003 Ronnie Sahlberg
4 * $Id: tap-iousers.c,v 1.2 2003/01/22 07:28:29 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
36 #include <epan/packet_info.h>
37 #include <epan/packet.h>
38 #include <epan/resolv.h>
41 #include "packet-ip.h"
42 #include "packet-eth.h"
43 #include "packet-tr.h"
46 typedef struct _io_users_t {
49 struct _io_users_item_t *items;
52 typedef struct _io_users_item_t {
53 struct _io_users_item_t *next;
65 iousers_ip_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vip)
71 if(iph->ip_src>iph->ip_dst){
79 for(iui=iu->items;iui;iui=iui->next){
80 if((!memcmp(iui->addr1, &addr1, 4))
81 &&(!memcmp(iui->addr2, &addr2, 4)) ){
87 iui=g_malloc(sizeof(io_users_item_t));
90 iui->addr1=g_malloc(4);
91 memcpy(iui->addr1, &addr1, 4);
92 iui->name1=strdup(get_hostname(addr1));
93 iui->addr2=g_malloc(4);
94 memcpy(iui->addr2, &addr2, 4);
95 iui->name2=strdup(get_hostname(addr2));
102 if(!memcmp(&iph->ip_src,iui->addr1,4)){
104 iui->bytes1+=pinfo->fd->pkt_len;
107 iui->bytes2+=pinfo->fd->pkt_len;
114 iousers_eth_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *veth)
117 gchar *addr1, *addr2;
118 io_users_item_t *iui;
120 if(memcmp(ehdr->src, ehdr->dst, 6)<0){
128 for(iui=iu->items;iui;iui=iui->next){
129 if((!memcmp(iui->addr1, addr1, 6))
130 &&(!memcmp(iui->addr2, addr2, 6)) ){
136 iui=g_malloc(sizeof(io_users_item_t));
139 iui->addr1=g_malloc(6);
140 memcpy(iui->addr1, addr1, 6);
141 iui->name1=strdup(ether_to_str(addr1));
142 iui->addr2=g_malloc(6);
143 memcpy(iui->addr2, addr2, 6);
144 iui->name2=strdup(ether_to_str(addr2));
151 if(!memcmp(ehdr->dst,iui->addr1,6)){
153 iui->bytes1+=pinfo->fd->pkt_len;
156 iui->bytes2+=pinfo->fd->pkt_len;
164 iousers_tr_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vtr)
167 gchar *addr1, *addr2;
168 io_users_item_t *iui;
170 if(memcmp(trhdr->src, trhdr->dst, 6)<0){
178 for(iui=iu->items;iui;iui=iui->next){
179 if((!memcmp(iui->addr1, addr1, 6))
180 &&(!memcmp(iui->addr2, addr2, 6)) ){
186 iui=g_malloc(sizeof(io_users_item_t));
189 iui->addr1=g_malloc(6);
190 memcpy(iui->addr1, addr1, 6);
191 iui->name1=strdup(ether_to_str(addr1));
192 iui->addr2=g_malloc(6);
193 memcpy(iui->addr2, addr2, 6);
194 iui->name2=strdup(ether_to_str(addr2));
201 if(!memcmp(trhdr->dst,iui->addr1,6)){
203 iui->bytes1+=pinfo->fd->pkt_len;
206 iui->bytes2+=pinfo->fd->pkt_len;
213 iousers_draw(io_users_t *iu)
215 io_users_item_t *iui;
216 guint32 last_frames, max_frames;
218 printf("================================================================================\n");
219 printf("IO-USERS Statistics\n");
220 printf("Type:%s\n",iu->type);
221 printf("Filter:%s\n",iu->filter?iu->filter:"<No Filter>");
222 printf(" | <- | | -> | | Total |\n");
223 printf(" | Frames Bytes | | Frames Bytes | | Frames Bytes |\n");
224 max_frames=0xffffffff;
227 for(iui=iu->items;iui;iui=iui->next){
229 tot_frames=iui->frames1+iui->frames2;
231 if((tot_frames>last_frames)
232 &&(tot_frames<max_frames)){
233 last_frames=tot_frames;
236 for(iui=iu->items;iui;iui=iui->next){
238 tot_frames=iui->frames1+iui->frames2;
240 if(tot_frames==last_frames){
241 printf("%-20s <-> %-20s %6d %9d %6d %9d %6d %9d\n",
242 iui->name1, iui->name2,
243 iui->frames1, iui->bytes1,
244 iui->frames2, iui->bytes2,
245 iui->frames1+iui->frames2,
246 iui->bytes1+iui->bytes2
250 max_frames=last_frames;
251 } while(last_frames);
252 printf("================================================================================\n");
256 iousers_init(char *optarg)
260 static int (*packet_func)(io_users_t *, packet_info *, epan_dissect_t *, void *);
263 if(!strncmp(optarg,"io,users,eth",12)){
270 packet_func=iousers_eth_packet;
271 } else if(!strncmp(optarg,"io,users,tr",11)){
278 packet_func=iousers_tr_packet;
279 } else if(!strncmp(optarg,"io,users,ip",11)){
286 packet_func=iousers_ip_packet;
288 fprintf(stderr, "tethereal: invalid \"-z io,users,<type>[,<filter>]\" argument\n");
289 fprintf(stderr," <type> must be one of\n");
290 fprintf(stderr," \"eth\"\n");
291 fprintf(stderr," \"ip\"\n");
292 fprintf(stderr," \"tr\"\n");
297 iu=g_malloc(sizeof(io_users_t));
301 iu->filter=strdup(filter);
306 if(register_tap_listener(tap_type, iu, filter, NULL, (void*)packet_func, (void*)iousers_draw)){
311 fprintf(stderr,"tethereal: iousers_init() failed to attach tap\n");
318 register_tap_listener_iousers(void)
320 register_ethereal_tap("io,users,", iousers_init, NULL, NULL);