2 * iostat 2003 Ronnie Sahlberg
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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/emem.h>
39 #include <epan/addr_resolv.h>
41 #include <epan/conversation.h>
42 #include <epan/stat_cmd_args.h>
44 #include <epan/dissectors/packet-ip.h>
45 #include <epan/dissectors/packet-ipx.h>
46 #include <epan/dissectors/packet-tcp.h>
47 #include <epan/dissectors/packet-udp.h>
48 #include <epan/dissectors/packet-eth.h>
49 #include <epan/dissectors/packet-sctp.h>
50 #include <epan/dissectors/packet-tr.h>
51 #include <epan/dissectors/packet-scsi.h>
52 #include <epan/dissectors/packet-fc.h>
53 #include <epan/dissectors/packet-fddi.h>
55 typedef struct _io_users_t {
58 struct _io_users_item_t *items;
61 typedef struct _io_users_item_t {
62 struct _io_users_item_t *next;
75 iousers_udpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vudph)
78 const e_udphdr *udph=vudph;
79 char name1[256],name2[256];
83 if(udph->uh_sport>udph->uh_dport){
85 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
86 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
87 } else if(udph->uh_sport<udph->uh_dport){
89 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
90 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
91 } else if(CMP_ADDRESS(&udph->ip_src, &udph->ip_dst)>0){
93 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
94 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
97 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
98 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
101 for(iui=iu->items;iui;iui=iui->next){
102 if((!strcmp(iui->name1, name1))
103 && (!strcmp(iui->name2, name2)) ){
109 iui=g_malloc(sizeof(io_users_item_t));
112 /* iui->addr1=NULL;*/
113 iui->name1=strdup(name1);
114 /* iui->addr2=NULL;*/
115 iui->name2=strdup(name2);
124 iui->bytes1+=pinfo->fd->pkt_len;
127 iui->bytes2+=pinfo->fd->pkt_len;
135 iousers_sctp_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vsctp)
138 const struct _sctp_info* sctph = vsctp;
139 char name1[256],name2[256], s_sport[10], s_dport[10];
140 io_users_item_t *iui;
143 g_snprintf(s_sport, sizeof s_sport, "%d",sctph->sport);
144 g_snprintf(s_dport, sizeof s_dport, "%d",sctph->dport);
146 if(sctph->sport > sctph->dport) {
148 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);
149 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);
150 } else if(sctph->sport < sctph->dport) {
152 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);
153 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);
156 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);
157 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);
160 for(iui=iu->items;iui;iui=iui->next){
161 if((!strcmp(iui->name1, name1))
162 && (!strcmp(iui->name2, name2)) ){
168 iui=g_malloc(sizeof(io_users_item_t));
171 /* iui->addr1=NULL;*/
172 iui->name1=strdup(name1);
173 /* iui->addr2=NULL;*/
174 iui->name2=strdup(name2);
183 iui->bytes1+=pinfo->fd->pkt_len;
186 iui->bytes2+=pinfo->fd->pkt_len;
194 iousers_tcpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtcph)
197 const struct tcpheader *tcph=vtcph;
198 char name1[256],name2[256];
199 io_users_item_t *iui;
202 if(tcph->th_sport>tcph->th_dport){
204 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
205 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
206 } else if(tcph->th_sport<tcph->th_dport){
208 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
209 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
210 } else if(CMP_ADDRESS(&tcph->ip_src, &tcph->ip_dst)>0){
212 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
213 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
216 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
217 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
220 for(iui=iu->items;iui;iui=iui->next){
221 if((!strcmp(iui->name1, name1))
222 && (!strcmp(iui->name2, name2)) ){
228 iui=g_malloc(sizeof(io_users_item_t));
231 /* iui->addr1=NULL;*/
232 iui->name1=strdup(name1);
233 /* iui->addr2=NULL;*/
234 iui->name2=strdup(name2);
243 iui->bytes1+=pinfo->fd->pkt_len;
246 iui->bytes2+=pinfo->fd->pkt_len;
254 iousers_ip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
258 const address *addr1, *addr2;
259 io_users_item_t *iui;
261 if(CMP_ADDRESS(&iph->ip_src, &iph->ip_dst)>0){
269 for(iui=iu->items;iui;iui=iui->next){
270 if((!CMP_ADDRESS(&iui->addr1, addr1))
271 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
277 iui=g_malloc(sizeof(io_users_item_t));
280 COPY_ADDRESS(&iui->addr1, addr1);
281 iui->name1=strdup(address_to_str(addr1));
282 COPY_ADDRESS(&iui->addr2, addr2);
283 iui->name2=strdup(address_to_str(addr2));
290 if(!CMP_ADDRESS(&iph->ip_dst, &iui->addr1)){
292 iui->bytes1+=pinfo->fd->pkt_len;
295 iui->bytes2+=pinfo->fd->pkt_len;
302 iousers_ipx_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vipx)
305 const ipxhdr_t *ipxh=vipx;
306 const address *addr1, *addr2;
307 io_users_item_t *iui;
309 if(CMP_ADDRESS(&ipxh->ipx_src, &ipxh->ipx_dst)>0){
310 addr1=&ipxh->ipx_src;
311 addr2=&ipxh->ipx_dst;
313 addr2=&ipxh->ipx_src;
314 addr1=&ipxh->ipx_dst;
317 for(iui=iu->items;iui;iui=iui->next){
318 if((!CMP_ADDRESS(&iui->addr1, addr1))
319 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
325 iui=g_malloc(sizeof(io_users_item_t));
328 COPY_ADDRESS(&iui->addr1, addr1);
329 iui->name1=strdup(address_to_str(addr1));
330 COPY_ADDRESS(&iui->addr2, addr2);
331 iui->name2=strdup(address_to_str(addr2));
338 if(!CMP_ADDRESS(&ipxh->ipx_dst, &iui->addr1)){
340 iui->bytes1+=pinfo->fd->pkt_len;
343 iui->bytes2+=pinfo->fd->pkt_len;
350 iousers_fc_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vfc)
353 const fc_hdr *fchdr=vfc;
354 const address *addr1, *addr2;
355 io_users_item_t *iui;
357 if(CMP_ADDRESS(&fchdr->s_id, &fchdr->d_id)<0){
365 for(iui=iu->items;iui;iui=iui->next){
366 if((!CMP_ADDRESS(&iui->addr1, addr1))
367 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
373 iui=g_malloc(sizeof(io_users_item_t));
376 COPY_ADDRESS(&iui->addr1, addr1);
377 iui->name1=strdup(address_to_str(addr1));
378 COPY_ADDRESS(&iui->addr2, addr2);
379 iui->name2=strdup(address_to_str(addr2));
386 if(!CMP_ADDRESS(&fchdr->d_id,&iui->addr1)){
388 iui->bytes1+=pinfo->fd->pkt_len;
391 iui->bytes2+=pinfo->fd->pkt_len;
398 iousers_eth_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
401 const eth_hdr *ehdr=veth;
402 const address *addr1, *addr2;
403 io_users_item_t *iui;
405 if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
413 for(iui=iu->items;iui;iui=iui->next){
414 if((!CMP_ADDRESS(&iui->addr1, addr1))
415 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
421 iui=g_malloc(sizeof(io_users_item_t));
424 COPY_ADDRESS(&iui->addr1, addr1);
425 iui->name1=strdup(address_to_str(addr1));
426 COPY_ADDRESS(&iui->addr2, addr2);
427 iui->name2=strdup(address_to_str(addr2));
434 if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
436 iui->bytes1+=pinfo->fd->pkt_len;
439 iui->bytes2+=pinfo->fd->pkt_len;
446 iousers_fddi_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
449 const fddi_hdr *ehdr=veth;
450 const address *addr1, *addr2;
451 io_users_item_t *iui;
453 if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
461 for(iui=iu->items;iui;iui=iui->next){
462 if((!CMP_ADDRESS(&iui->addr1, addr1))
463 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
469 iui=g_malloc(sizeof(io_users_item_t));
472 COPY_ADDRESS(&iui->addr1, addr1);
473 iui->name1=strdup(address_to_str(addr1));
474 COPY_ADDRESS(&iui->addr2, addr2);
475 iui->name2=strdup(address_to_str(addr2));
482 if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
484 iui->bytes1+=pinfo->fd->pkt_len;
487 iui->bytes2+=pinfo->fd->pkt_len;
494 iousers_tr_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtr)
497 const tr_hdr *trhdr=vtr;
498 const address *addr1, *addr2;
499 io_users_item_t *iui;
501 if(CMP_ADDRESS(&trhdr->src, &trhdr->dst)<0){
509 for(iui=iu->items;iui;iui=iui->next){
510 if((!CMP_ADDRESS(&iui->addr1, addr1))
511 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
517 iui=g_malloc(sizeof(io_users_item_t));
520 COPY_ADDRESS(&iui->addr1, addr1);
521 iui->name1=strdup(address_to_str(addr1));
522 COPY_ADDRESS(&iui->addr2, addr2);
523 iui->name2=strdup(address_to_str(addr2));
530 if(!CMP_ADDRESS(&trhdr->dst,&iui->addr1)){
532 iui->bytes1+=pinfo->fd->pkt_len;
535 iui->bytes2+=pinfo->fd->pkt_len;
542 iousers_draw(void *arg)
544 io_users_t *iu = arg;
545 io_users_item_t *iui;
546 guint32 last_frames, max_frames;
548 printf("================================================================================\n");
549 printf("%s Conversations\n",iu->type);
550 printf("Filter:%s\n",iu->filter?iu->filter:"<No Filter>");
551 printf(" | <- | | -> | | Total |\n");
552 printf(" | Frames Bytes | | Frames Bytes | | Frames Bytes |\n");
553 max_frames=0xffffffff;
556 for(iui=iu->items;iui;iui=iui->next){
558 tot_frames=iui->frames1+iui->frames2;
560 if((tot_frames>last_frames)
561 &&(tot_frames<max_frames)){
562 last_frames=tot_frames;
565 for(iui=iu->items;iui;iui=iui->next){
567 tot_frames=iui->frames1+iui->frames2;
569 if(tot_frames==last_frames){
570 printf("%-20s <-> %-20s %6d %9d %6d %9d %6d %9d\n",
571 iui->name1, iui->name2,
572 iui->frames1, iui->bytes1,
573 iui->frames2, iui->bytes2,
574 iui->frames1+iui->frames2,
575 iui->bytes1+iui->bytes2
579 max_frames=last_frames;
580 } while(last_frames);
581 printf("================================================================================\n");
585 iousers_init(const char *optarg, void* userdata _U_)
587 const char *filter=NULL;
588 const char *tap_type, *tap_type_name;
589 tap_packet_cb packet_func;
591 GString *error_string;
593 if(!strncmp(optarg,"conv,eth",8)){
600 tap_type_name="Ethernet";
601 packet_func=iousers_eth_packet;
602 } else if(!strncmp(optarg,"conv,fc",7)){
609 tap_type_name="Fibre Channel";
610 packet_func=iousers_fc_packet;
611 } else if(!strncmp(optarg,"conv,fddi",9)){
618 tap_type_name="FDDI";
619 packet_func=iousers_fddi_packet;
620 } else if(!strncmp(optarg,"conv,tcp",8)){
628 packet_func=iousers_tcpip_packet;
629 } else if(!strncmp(optarg,"conv,udp",8)){
637 packet_func=iousers_udpip_packet;
638 } else if(!strncmp(optarg,"conv,tr",7)){
645 tap_type_name="Token Ring";
646 packet_func=iousers_tr_packet;
647 } else if(!strncmp(optarg,"conv,ipx",8)){
655 packet_func=iousers_ipx_packet;
656 } else if(!strncmp(optarg,"conv,ip",7)){
663 tap_type_name="IPv4";
664 packet_func=iousers_ip_packet;
665 } else if(!strncmp(optarg,"conv,sctp",9)) {
672 tap_type_name="SCTP";
673 packet_func=iousers_sctp_packet;
675 fprintf(stderr, "tshark: invalid \"-z conv,<type>[,<filter>]\" argument\n");
676 fprintf(stderr," <type> must be one of\n");
677 fprintf(stderr," \"eth\"\n");
678 fprintf(stderr," \"fc\"\n");
679 fprintf(stderr," \"fddi\"\n");
680 fprintf(stderr," \"ip\"\n");
681 fprintf(stderr," \"ipx\"\n");
682 fprintf(stderr," \"sctp\"\n");
683 fprintf(stderr," \"tcp\"\n");
684 fprintf(stderr," \"tr\"\n");
685 fprintf(stderr," \"udp\"\n");
690 iu=g_malloc(sizeof(io_users_t));
692 iu->type=tap_type_name;
694 iu->filter=strdup(filter);
699 error_string=register_tap_listener(tap_type, iu, filter, NULL, packet_func, iousers_draw);
705 fprintf(stderr, "tshark: Couldn't register conversations tap: %s\n",
707 g_string_free(error_string, TRUE);
714 register_tap_listener_iousers(void)
716 register_stat_cmd_arg("conv,", iousers_init, NULL);