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/addr_resolv.h>
40 #include <epan/conversation.h>
41 #include <epan/stat_cmd_args.h>
42 #include <epan/dissectors/packet-ip.h>
43 #include <epan/dissectors/packet-ipv6.h>
44 #include <epan/dissectors/packet-ipx.h>
45 #include <epan/dissectors/packet-tcp.h>
46 #include <epan/dissectors/packet-udp.h>
47 #include <epan/dissectors/packet-eth.h>
48 #include <epan/dissectors/packet-sctp.h>
49 #include <epan/dissectors/packet-tr.h>
50 #include <epan/dissectors/packet-scsi.h>
51 #include <epan/dissectors/packet-fc.h>
52 #include <epan/dissectors/packet-fddi.h>
54 typedef struct _io_users_t {
57 struct _io_users_item_t *items;
60 typedef struct _io_users_item_t {
61 struct _io_users_item_t *next;
74 iousers_udpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vudph)
77 const e_udphdr *udph=vudph;
78 char name1[256],name2[256];
82 if(udph->uh_sport>udph->uh_dport){
84 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
85 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
86 } else if(udph->uh_sport<udph->uh_dport){
88 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
89 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
90 } else if(CMP_ADDRESS(&udph->ip_src, &udph->ip_dst)>0){
92 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
93 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
96 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
97 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
100 for(iui=iu->items;iui;iui=iui->next){
101 if((!strcmp(iui->name1, name1))
102 && (!strcmp(iui->name2, name2)) ){
108 iui=g_malloc(sizeof(io_users_item_t));
111 /* iui->addr1=NULL;*/
112 iui->name1=g_strdup(name1);
113 /* iui->addr2=NULL;*/
114 iui->name2=g_strdup(name2);
123 iui->bytes1+=pinfo->fd->pkt_len;
126 iui->bytes2+=pinfo->fd->pkt_len;
134 iousers_sctp_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vsctp)
137 const struct _sctp_info* sctph = vsctp;
138 char name1[256],name2[256], s_sport[10], s_dport[10];
139 io_users_item_t *iui;
142 g_snprintf(s_sport, sizeof s_sport, "%d",sctph->sport);
143 g_snprintf(s_dport, sizeof s_dport, "%d",sctph->dport);
145 if(sctph->sport > sctph->dport) {
147 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&sctph->ip_src),s_sport);
148 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&sctph->ip_dst),s_dport);
149 } else if(sctph->sport < sctph->dport) {
151 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&sctph->ip_src),s_sport);
152 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&sctph->ip_dst),s_dport);
155 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&sctph->ip_src),s_sport);
156 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&sctph->ip_dst),s_dport);
159 for(iui=iu->items;iui;iui=iui->next){
160 if((!strcmp(iui->name1, name1))
161 && (!strcmp(iui->name2, name2)) ){
167 iui=g_malloc(sizeof(io_users_item_t));
170 /* iui->addr1=NULL;*/
171 iui->name1=g_strdup(name1);
172 /* iui->addr2=NULL;*/
173 iui->name2=g_strdup(name2);
182 iui->bytes1+=pinfo->fd->pkt_len;
185 iui->bytes2+=pinfo->fd->pkt_len;
193 iousers_tcpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtcph)
196 const struct tcpheader *tcph=vtcph;
197 char name1[256],name2[256];
198 io_users_item_t *iui;
201 if(tcph->th_sport>tcph->th_dport){
203 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
204 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
205 } else if(tcph->th_sport<tcph->th_dport){
207 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
208 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
209 } else if(CMP_ADDRESS(&tcph->ip_src, &tcph->ip_dst)>0){
211 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
212 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
215 g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
216 g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
219 for(iui=iu->items;iui;iui=iui->next){
220 if((!strcmp(iui->name1, name1))
221 && (!strcmp(iui->name2, name2)) ){
227 iui=g_malloc(sizeof(io_users_item_t));
230 /* iui->addr1=NULL;*/
231 iui->name1=g_strdup(name1);
232 /* iui->addr2=NULL;*/
233 iui->name2=g_strdup(name2);
242 iui->bytes1+=pinfo->fd->pkt_len;
245 iui->bytes2+=pinfo->fd->pkt_len;
253 iousers_ip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
256 const ws_ip *iph=vip;
257 const address *addr1, *addr2;
258 io_users_item_t *iui;
260 if(CMP_ADDRESS(&iph->ip_src, &iph->ip_dst)>0){
268 for(iui=iu->items;iui;iui=iui->next){
269 if((!CMP_ADDRESS(&iui->addr1, addr1))
270 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
276 iui=g_malloc(sizeof(io_users_item_t));
279 COPY_ADDRESS(&iui->addr1, addr1);
280 iui->name1=g_strdup(ep_address_to_str(addr1));
281 COPY_ADDRESS(&iui->addr2, addr2);
282 iui->name2=g_strdup(ep_address_to_str(addr2));
289 if(!CMP_ADDRESS(&iph->ip_dst, &iui->addr1)){
291 iui->bytes1+=pinfo->fd->pkt_len;
294 iui->bytes2+=pinfo->fd->pkt_len;
301 iousers_ipv6_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
304 const struct ip6_hdr *ip6h=vip;
306 const address *addr1, *addr2;
307 io_users_item_t *iui;
309 /* Addresses aren't implemented as 'address' type in struct ip6_hdr */
310 src.type = dst.type = AT_IPv6;
311 src.len = dst.len = sizeof(struct e_in6_addr);
312 src.data = &ip6h->ip6_src;
313 dst.data = &ip6h->ip6_dst;
315 if(CMP_ADDRESS(&src, &dst)>0){
323 for(iui=iu->items;iui;iui=iui->next){
324 if((!CMP_ADDRESS(&iui->addr1, addr1))
325 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
331 iui=g_malloc(sizeof(io_users_item_t));
334 COPY_ADDRESS(&iui->addr1, addr1);
335 iui->name1=g_strdup(ep_address_to_str(addr1));
336 COPY_ADDRESS(&iui->addr2, addr2);
337 iui->name2=g_strdup(ep_address_to_str(addr2));
344 if(!CMP_ADDRESS(&dst, &iui->addr1)){
346 iui->bytes1+=pinfo->fd->pkt_len;
349 iui->bytes2+=pinfo->fd->pkt_len;
356 iousers_ipx_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vipx)
359 const ipxhdr_t *ipxh=vipx;
360 const address *addr1, *addr2;
361 io_users_item_t *iui;
363 if(CMP_ADDRESS(&ipxh->ipx_src, &ipxh->ipx_dst)>0){
364 addr1=&ipxh->ipx_src;
365 addr2=&ipxh->ipx_dst;
367 addr2=&ipxh->ipx_src;
368 addr1=&ipxh->ipx_dst;
371 for(iui=iu->items;iui;iui=iui->next){
372 if((!CMP_ADDRESS(&iui->addr1, addr1))
373 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
379 iui=g_malloc(sizeof(io_users_item_t));
382 COPY_ADDRESS(&iui->addr1, addr1);
383 iui->name1=g_strdup(ep_address_to_str(addr1));
384 COPY_ADDRESS(&iui->addr2, addr2);
385 iui->name2=g_strdup(ep_address_to_str(addr2));
392 if(!CMP_ADDRESS(&ipxh->ipx_dst, &iui->addr1)){
394 iui->bytes1+=pinfo->fd->pkt_len;
397 iui->bytes2+=pinfo->fd->pkt_len;
404 iousers_fc_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vfc)
407 const fc_hdr *fchdr=vfc;
408 const address *addr1, *addr2;
409 io_users_item_t *iui;
411 if(CMP_ADDRESS(&fchdr->s_id, &fchdr->d_id)<0){
419 for(iui=iu->items;iui;iui=iui->next){
420 if((!CMP_ADDRESS(&iui->addr1, addr1))
421 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
427 iui=g_malloc(sizeof(io_users_item_t));
430 COPY_ADDRESS(&iui->addr1, addr1);
431 iui->name1=g_strdup(ep_address_to_str(addr1));
432 COPY_ADDRESS(&iui->addr2, addr2);
433 iui->name2=g_strdup(ep_address_to_str(addr2));
440 if(!CMP_ADDRESS(&fchdr->d_id,&iui->addr1)){
442 iui->bytes1+=pinfo->fd->pkt_len;
445 iui->bytes2+=pinfo->fd->pkt_len;
452 iousers_eth_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
455 const eth_hdr *ehdr=veth;
456 const address *addr1, *addr2;
457 io_users_item_t *iui;
459 if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
467 for(iui=iu->items;iui;iui=iui->next){
468 if((!CMP_ADDRESS(&iui->addr1, addr1))
469 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
475 iui=g_malloc(sizeof(io_users_item_t));
478 COPY_ADDRESS(&iui->addr1, addr1);
479 iui->name1=g_strdup(ep_address_to_str(addr1));
480 COPY_ADDRESS(&iui->addr2, addr2);
481 iui->name2=g_strdup(ep_address_to_str(addr2));
488 if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
490 iui->bytes1+=pinfo->fd->pkt_len;
493 iui->bytes2+=pinfo->fd->pkt_len;
500 iousers_fddi_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
503 const fddi_hdr *ehdr=veth;
504 const address *addr1, *addr2;
505 io_users_item_t *iui;
507 if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
515 for(iui=iu->items;iui;iui=iui->next){
516 if((!CMP_ADDRESS(&iui->addr1, addr1))
517 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
523 iui=g_malloc(sizeof(io_users_item_t));
526 COPY_ADDRESS(&iui->addr1, addr1);
527 iui->name1=g_strdup(ep_address_to_str(addr1));
528 COPY_ADDRESS(&iui->addr2, addr2);
529 iui->name2=g_strdup(ep_address_to_str(addr2));
536 if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
538 iui->bytes1+=pinfo->fd->pkt_len;
541 iui->bytes2+=pinfo->fd->pkt_len;
548 iousers_tr_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtr)
551 const tr_hdr *trhdr=vtr;
552 const address *addr1, *addr2;
553 io_users_item_t *iui;
555 if(CMP_ADDRESS(&trhdr->src, &trhdr->dst)<0){
563 for(iui=iu->items;iui;iui=iui->next){
564 if((!CMP_ADDRESS(&iui->addr1, addr1))
565 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
571 iui=g_malloc(sizeof(io_users_item_t));
574 COPY_ADDRESS(&iui->addr1, addr1);
575 iui->name1=g_strdup(ep_address_to_str(addr1));
576 COPY_ADDRESS(&iui->addr2, addr2);
577 iui->name2=g_strdup(ep_address_to_str(addr2));
584 if(!CMP_ADDRESS(&trhdr->dst,&iui->addr1)){
586 iui->bytes1+=pinfo->fd->pkt_len;
589 iui->bytes2+=pinfo->fd->pkt_len;
596 iousers_draw(void *arg)
598 io_users_t *iu = arg;
599 io_users_item_t *iui;
600 guint32 last_frames, max_frames;
602 printf("================================================================================\n");
603 printf("%s Conversations\n",iu->type);
604 printf("Filter:%s\n",iu->filter?iu->filter:"<No Filter>");
605 printf(" | <- | | -> | | Total |\n");
606 printf(" | Frames Bytes | | Frames Bytes | | Frames Bytes |\n");
607 max_frames=0xffffffff;
610 for(iui=iu->items;iui;iui=iui->next){
612 tot_frames=iui->frames1+iui->frames2;
614 if((tot_frames>last_frames)
615 &&(tot_frames<max_frames)){
616 last_frames=tot_frames;
619 for(iui=iu->items;iui;iui=iui->next){
621 tot_frames=iui->frames1+iui->frames2;
623 if(tot_frames==last_frames){
624 printf("%-20s <-> %-20s %6d %9" G_GINT64_MODIFIER "d %6d %9" G_GINT64_MODIFIER "d %6d %9" G_GINT64_MODIFIER "d\n",
625 iui->name1, iui->name2,
626 iui->frames1, iui->bytes1,
627 iui->frames2, iui->bytes2,
628 iui->frames1+iui->frames2,
629 iui->bytes1+iui->bytes2
633 max_frames=last_frames;
634 } while(last_frames);
635 printf("================================================================================\n");
639 iousers_init(const char *optarg, void* userdata _U_)
641 const char *filter=NULL;
642 const char *tap_type, *tap_type_name;
643 tap_packet_cb packet_func;
645 GString *error_string;
647 if(!strncmp(optarg,"conv,eth",8)){
654 tap_type_name="Ethernet";
655 packet_func=iousers_eth_packet;
656 } else if(!strncmp(optarg,"conv,fc",7)){
663 tap_type_name="Fibre Channel";
664 packet_func=iousers_fc_packet;
665 } else if(!strncmp(optarg,"conv,fddi",9)){
672 tap_type_name="FDDI";
673 packet_func=iousers_fddi_packet;
674 } else if(!strncmp(optarg,"conv,tcp",8)){
682 packet_func=iousers_tcpip_packet;
683 } else if(!strncmp(optarg,"conv,udp",8)){
691 packet_func=iousers_udpip_packet;
692 } else if(!strncmp(optarg,"conv,tr",7)){
699 tap_type_name="Token Ring";
700 packet_func=iousers_tr_packet;
701 } else if(!strncmp(optarg,"conv,ipx",8)){
709 packet_func=iousers_ipx_packet;
710 } else if(!strncmp(optarg,"conv,ipv6",9)){
717 tap_type_name="IPv6";
718 packet_func=iousers_ipv6_packet;
719 } else if(!strncmp(optarg,"conv,ip",7)){
726 tap_type_name="IPv4";
727 packet_func=iousers_ip_packet;
728 } else if(!strncmp(optarg,"conv,sctp",9)) {
735 tap_type_name="SCTP";
736 packet_func=iousers_sctp_packet;
738 fprintf(stderr, "tshark: invalid \"-z conv,<type>[,<filter>]\" argument\n");
739 fprintf(stderr," <type> must be one of\n");
740 fprintf(stderr," \"eth\"\n");
741 fprintf(stderr," \"fc\"\n");
742 fprintf(stderr," \"fddi\"\n");
743 fprintf(stderr," \"ip\"\n");
744 fprintf(stderr," \"ipx\"\n");
745 fprintf(stderr," \"sctp\"\n");
746 fprintf(stderr," \"tcp\"\n");
747 fprintf(stderr," \"tr\"\n");
748 fprintf(stderr," \"udp\"\n");
753 iu=g_malloc(sizeof(io_users_t));
755 iu->type=tap_type_name;
757 iu->filter=g_strdup(filter);
762 error_string=register_tap_listener(tap_type, iu, filter, 0, NULL, packet_func, iousers_draw);
768 fprintf(stderr, "tshark: Couldn't register conversations tap: %s\n",
770 g_string_free(error_string, TRUE);
777 register_tap_listener_iousers(void)
779 register_stat_cmd_arg("conv,", iousers_init, NULL);