2 * iostat 2003 Ronnie Sahlberg
4 * $Id: tap-iousers.c,v 1.12 2003/08/25 00:44:20 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-ipx.h"
43 #include "packet-tcp.h"
44 #include "packet-udp.h"
45 #include "packet-eth.h"
46 #include "packet-tr.h"
47 #include "packet-fc.h"
50 typedef struct _io_users_t {
53 struct _io_users_item_t *items;
56 typedef struct _io_users_item_t {
57 struct _io_users_item_t *next;
70 iousers_udpip_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vudph)
73 char name1[256],name2[256];
77 if(CMP_ADDRESS(&udph->ip_src, &udph->ip_dst)>0){
78 snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
79 snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
82 snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
83 snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
86 for(iui=iu->items;iui;iui=iui->next){
87 if((!strcmp(iui->name1, name1))
88 && (!strcmp(iui->name2, name2)) ){
94 iui=g_malloc(sizeof(io_users_item_t));
98 iui->name1=strdup(name1);
100 iui->name2=strdup(name2);
109 iui->bytes1+=pinfo->fd->pkt_len;
112 iui->bytes2+=pinfo->fd->pkt_len;
120 iousers_tcpip_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vtcph)
122 struct tcpheader *tcph=vtcph;
123 char name1[256],name2[256];
124 io_users_item_t *iui;
127 if(CMP_ADDRESS(&tcph->ip_src, &tcph->ip_dst)>0){
128 snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
129 snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
132 snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
133 snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
136 for(iui=iu->items;iui;iui=iui->next){
137 if((!strcmp(iui->name1, name1))
138 && (!strcmp(iui->name2, name2)) ){
144 iui=g_malloc(sizeof(io_users_item_t));
147 /* iui->addr1=NULL;*/
148 iui->name1=strdup(name1);
149 /* iui->addr2=NULL;*/
150 iui->name2=strdup(name2);
159 iui->bytes1+=pinfo->fd->pkt_len;
162 iui->bytes2+=pinfo->fd->pkt_len;
170 iousers_ip_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vip)
173 address *addr1, *addr2;
174 io_users_item_t *iui;
176 if(CMP_ADDRESS(&iph->ip_src, &iph->ip_dst)>0){
184 for(iui=iu->items;iui;iui=iui->next){
185 if((!CMP_ADDRESS(&iui->addr1, addr1))
186 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
192 iui=g_malloc(sizeof(io_users_item_t));
195 COPY_ADDRESS(&iui->addr1, addr1);
196 iui->name1=strdup(address_to_str(addr1));
197 COPY_ADDRESS(&iui->addr2, addr2);
198 iui->name2=strdup(address_to_str(addr2));
205 if(!CMP_ADDRESS(&iph->ip_dst, &iui->addr1)){
207 iui->bytes1+=pinfo->fd->pkt_len;
210 iui->bytes2+=pinfo->fd->pkt_len;
217 iousers_ipx_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vipx)
220 address *addr1, *addr2;
221 io_users_item_t *iui;
223 if(CMP_ADDRESS(&ipxh->ipx_src, &ipxh->ipx_dst)>0){
224 addr1=&ipxh->ipx_src;
225 addr2=&ipxh->ipx_dst;
227 addr2=&ipxh->ipx_src;
228 addr1=&ipxh->ipx_dst;
231 for(iui=iu->items;iui;iui=iui->next){
232 if((!CMP_ADDRESS(&iui->addr1, addr1))
233 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
239 iui=g_malloc(sizeof(io_users_item_t));
242 COPY_ADDRESS(&iui->addr1, addr1);
243 iui->name1=strdup(address_to_str(addr1));
244 COPY_ADDRESS(&iui->addr2, addr2);
245 iui->name2=strdup(address_to_str(addr2));
252 if(!CMP_ADDRESS(&ipxh->ipx_dst, &iui->addr1)){
254 iui->bytes1+=pinfo->fd->pkt_len;
257 iui->bytes2+=pinfo->fd->pkt_len;
264 iousers_fc_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vfc)
267 address *addr1, *addr2;
268 io_users_item_t *iui;
270 if(CMP_ADDRESS(&fchdr->s_id, &fchdr->d_id)<0){
278 for(iui=iu->items;iui;iui=iui->next){
279 if((!CMP_ADDRESS(&iui->addr1, addr1))
280 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
286 iui=g_malloc(sizeof(io_users_item_t));
289 COPY_ADDRESS(&iui->addr1, addr1);
290 iui->name1=strdup(address_to_str(addr1));
291 COPY_ADDRESS(&iui->addr2, addr2);
292 iui->name2=strdup(address_to_str(addr2));
299 if(!CMP_ADDRESS(&fchdr->d_id,&iui->addr1)){
301 iui->bytes1+=pinfo->fd->pkt_len;
304 iui->bytes2+=pinfo->fd->pkt_len;
311 iousers_eth_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *veth)
314 address *addr1, *addr2;
315 io_users_item_t *iui;
317 if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
325 for(iui=iu->items;iui;iui=iui->next){
326 if((!CMP_ADDRESS(&iui->addr1, addr1))
327 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
333 iui=g_malloc(sizeof(io_users_item_t));
336 COPY_ADDRESS(&iui->addr1, addr1);
337 iui->name1=strdup(address_to_str(addr1));
338 COPY_ADDRESS(&iui->addr2, addr2);
339 iui->name2=strdup(address_to_str(addr2));
346 if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
348 iui->bytes1+=pinfo->fd->pkt_len;
351 iui->bytes2+=pinfo->fd->pkt_len;
358 iousers_tr_packet(io_users_t *iu, packet_info *pinfo, epan_dissect_t *edt _U_, void *vtr)
361 address *addr1, *addr2;
362 io_users_item_t *iui;
364 if(CMP_ADDRESS(&trhdr->src, &trhdr->dst)<0){
372 for(iui=iu->items;iui;iui=iui->next){
373 if((!CMP_ADDRESS(&iui->addr1, addr1))
374 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
380 iui=g_malloc(sizeof(io_users_item_t));
383 COPY_ADDRESS(&iui->addr1, addr1);
384 iui->name1=strdup(address_to_str(addr1));
385 COPY_ADDRESS(&iui->addr2, addr2);
386 iui->name2=strdup(address_to_str(addr2));
393 if(!CMP_ADDRESS(&trhdr->dst,&iui->addr1)){
395 iui->bytes1+=pinfo->fd->pkt_len;
398 iui->bytes2+=pinfo->fd->pkt_len;
405 iousers_draw(io_users_t *iu)
407 io_users_item_t *iui;
408 guint32 last_frames, max_frames;
410 printf("================================================================================\n");
411 printf("%s Talkers\n",iu->type);
412 printf("Filter:%s\n",iu->filter?iu->filter:"<No Filter>");
413 printf(" | <- | | -> | | Total |\n");
414 printf(" | Frames Bytes | | Frames Bytes | | Frames Bytes |\n");
415 max_frames=0xffffffff;
418 for(iui=iu->items;iui;iui=iui->next){
420 tot_frames=iui->frames1+iui->frames2;
422 if((tot_frames>last_frames)
423 &&(tot_frames<max_frames)){
424 last_frames=tot_frames;
427 for(iui=iu->items;iui;iui=iui->next){
429 tot_frames=iui->frames1+iui->frames2;
431 if(tot_frames==last_frames){
432 printf("%-20s <-> %-20s %6d %9d %6d %9d %6d %9d\n",
433 iui->name1, iui->name2,
434 iui->frames1, iui->bytes1,
435 iui->frames2, iui->bytes2,
436 iui->frames1+iui->frames2,
437 iui->bytes1+iui->bytes2
441 max_frames=last_frames;
442 } while(last_frames);
443 printf("================================================================================\n");
447 iousers_init(char *optarg)
450 char *tap_type, *tap_type_name;
451 static int (*packet_func)(io_users_t *, packet_info *, epan_dissect_t *, void *);
453 GString *error_string;
455 if(!strncmp(optarg,"talkers,eth",11)){
462 tap_type_name="Ethernet";
463 packet_func=iousers_eth_packet;
464 } else if(!strncmp(optarg,"talkers,fc",10)){
471 tap_type_name="Fibre Channel";
472 packet_func=iousers_fc_packet;
473 } else if(!strncmp(optarg,"talkers,tcp",11)){
481 packet_func=iousers_tcpip_packet;
482 } else if(!strncmp(optarg,"talkers,udp",11)){
490 packet_func=iousers_udpip_packet;
491 } else if(!strncmp(optarg,"talkers,tr",10)){
498 tap_type_name="Token Ring";
499 packet_func=iousers_tr_packet;
500 } else if(!strncmp(optarg,"talkers,ipx",11)){
508 packet_func=iousers_ipx_packet;
509 } else if(!strncmp(optarg,"talkers,ip",10)){
516 tap_type_name="IPv4";
517 packet_func=iousers_ip_packet;
519 fprintf(stderr, "tethereal: invalid \"-z talkers,<type>[,<filter>]\" argument\n");
520 fprintf(stderr," <type> must be one of\n");
521 fprintf(stderr," \"eth\"\n");
522 fprintf(stderr," \"fc\"\n");
523 fprintf(stderr," \"ip\"\n");
524 fprintf(stderr," \"ipx\"\n");
525 fprintf(stderr," \"tcp\"\n");
526 fprintf(stderr," \"tr\"\n");
527 fprintf(stderr," \"udp\"\n");
532 iu=g_malloc(sizeof(io_users_t));
534 iu->type=tap_type_name;
536 iu->filter=strdup(filter);
541 error_string=register_tap_listener(tap_type, iu, filter, NULL, (void*)packet_func, (void*)iousers_draw);
547 fprintf(stderr, "tethereal: Couldn't register talkers tap: %s\n",
549 g_string_free(error_string, TRUE);
556 register_tap_listener_iousers(void)
558 register_ethereal_tap("talkers,", iousers_init);