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>
43 #include <epan/dissectors/packet-ip.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",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
85 g_snprintf(name2,256,"%s:%s",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",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
89 g_snprintf(name1,256,"%s:%s",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",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
93 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
96 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
97 g_snprintf(name1,256,"%s:%s",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",address_to_str(&sctph->ip_src),s_sport);
148 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);
149 } else if(sctph->sport < sctph->dport) {
151 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);
152 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);
155 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);
156 g_snprintf(name2,256,"%s:%s",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",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
204 g_snprintf(name2,256,"%s:%s",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",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
208 g_snprintf(name1,256,"%s:%s",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",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
212 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
215 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
216 g_snprintf(name1,256,"%s:%s",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(address_to_str(addr1));
281 COPY_ADDRESS(&iui->addr2, addr2);
282 iui->name2=g_strdup(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_ipx_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vipx)
304 const ipxhdr_t *ipxh=vipx;
305 const address *addr1, *addr2;
306 io_users_item_t *iui;
308 if(CMP_ADDRESS(&ipxh->ipx_src, &ipxh->ipx_dst)>0){
309 addr1=&ipxh->ipx_src;
310 addr2=&ipxh->ipx_dst;
312 addr2=&ipxh->ipx_src;
313 addr1=&ipxh->ipx_dst;
316 for(iui=iu->items;iui;iui=iui->next){
317 if((!CMP_ADDRESS(&iui->addr1, addr1))
318 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
324 iui=g_malloc(sizeof(io_users_item_t));
327 COPY_ADDRESS(&iui->addr1, addr1);
328 iui->name1=g_strdup(address_to_str(addr1));
329 COPY_ADDRESS(&iui->addr2, addr2);
330 iui->name2=g_strdup(address_to_str(addr2));
337 if(!CMP_ADDRESS(&ipxh->ipx_dst, &iui->addr1)){
339 iui->bytes1+=pinfo->fd->pkt_len;
342 iui->bytes2+=pinfo->fd->pkt_len;
349 iousers_fc_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vfc)
352 const fc_hdr *fchdr=vfc;
353 const address *addr1, *addr2;
354 io_users_item_t *iui;
356 if(CMP_ADDRESS(&fchdr->s_id, &fchdr->d_id)<0){
364 for(iui=iu->items;iui;iui=iui->next){
365 if((!CMP_ADDRESS(&iui->addr1, addr1))
366 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
372 iui=g_malloc(sizeof(io_users_item_t));
375 COPY_ADDRESS(&iui->addr1, addr1);
376 iui->name1=g_strdup(address_to_str(addr1));
377 COPY_ADDRESS(&iui->addr2, addr2);
378 iui->name2=g_strdup(address_to_str(addr2));
385 if(!CMP_ADDRESS(&fchdr->d_id,&iui->addr1)){
387 iui->bytes1+=pinfo->fd->pkt_len;
390 iui->bytes2+=pinfo->fd->pkt_len;
397 iousers_eth_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
400 const eth_hdr *ehdr=veth;
401 const address *addr1, *addr2;
402 io_users_item_t *iui;
404 if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
412 for(iui=iu->items;iui;iui=iui->next){
413 if((!CMP_ADDRESS(&iui->addr1, addr1))
414 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
420 iui=g_malloc(sizeof(io_users_item_t));
423 COPY_ADDRESS(&iui->addr1, addr1);
424 iui->name1=g_strdup(address_to_str(addr1));
425 COPY_ADDRESS(&iui->addr2, addr2);
426 iui->name2=g_strdup(address_to_str(addr2));
433 if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
435 iui->bytes1+=pinfo->fd->pkt_len;
438 iui->bytes2+=pinfo->fd->pkt_len;
445 iousers_fddi_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
448 const fddi_hdr *ehdr=veth;
449 const address *addr1, *addr2;
450 io_users_item_t *iui;
452 if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
460 for(iui=iu->items;iui;iui=iui->next){
461 if((!CMP_ADDRESS(&iui->addr1, addr1))
462 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
468 iui=g_malloc(sizeof(io_users_item_t));
471 COPY_ADDRESS(&iui->addr1, addr1);
472 iui->name1=g_strdup(address_to_str(addr1));
473 COPY_ADDRESS(&iui->addr2, addr2);
474 iui->name2=g_strdup(address_to_str(addr2));
481 if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
483 iui->bytes1+=pinfo->fd->pkt_len;
486 iui->bytes2+=pinfo->fd->pkt_len;
493 iousers_tr_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtr)
496 const tr_hdr *trhdr=vtr;
497 const address *addr1, *addr2;
498 io_users_item_t *iui;
500 if(CMP_ADDRESS(&trhdr->src, &trhdr->dst)<0){
508 for(iui=iu->items;iui;iui=iui->next){
509 if((!CMP_ADDRESS(&iui->addr1, addr1))
510 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
516 iui=g_malloc(sizeof(io_users_item_t));
519 COPY_ADDRESS(&iui->addr1, addr1);
520 iui->name1=g_strdup(address_to_str(addr1));
521 COPY_ADDRESS(&iui->addr2, addr2);
522 iui->name2=g_strdup(address_to_str(addr2));
529 if(!CMP_ADDRESS(&trhdr->dst,&iui->addr1)){
531 iui->bytes1+=pinfo->fd->pkt_len;
534 iui->bytes2+=pinfo->fd->pkt_len;
541 iousers_draw(void *arg)
543 io_users_t *iu = arg;
544 io_users_item_t *iui;
545 guint32 last_frames, max_frames;
547 printf("================================================================================\n");
548 printf("%s Conversations\n",iu->type);
549 printf("Filter:%s\n",iu->filter?iu->filter:"<No Filter>");
550 printf(" | <- | | -> | | Total |\n");
551 printf(" | Frames Bytes | | Frames Bytes | | Frames Bytes |\n");
552 max_frames=0xffffffff;
555 for(iui=iu->items;iui;iui=iui->next){
557 tot_frames=iui->frames1+iui->frames2;
559 if((tot_frames>last_frames)
560 &&(tot_frames<max_frames)){
561 last_frames=tot_frames;
564 for(iui=iu->items;iui;iui=iui->next){
566 tot_frames=iui->frames1+iui->frames2;
568 if(tot_frames==last_frames){
569 printf("%-20s <-> %-20s %6d %9" G_GINT64_MODIFIER "d %6d %9" G_GINT64_MODIFIER "d %6d %9" G_GINT64_MODIFIER "d\n",
570 iui->name1, iui->name2,
571 iui->frames1, iui->bytes1,
572 iui->frames2, iui->bytes2,
573 iui->frames1+iui->frames2,
574 iui->bytes1+iui->bytes2
578 max_frames=last_frames;
579 } while(last_frames);
580 printf("================================================================================\n");
584 iousers_init(const char *optarg, void* userdata _U_)
586 const char *filter=NULL;
587 const char *tap_type, *tap_type_name;
588 tap_packet_cb packet_func;
590 GString *error_string;
592 if(!strncmp(optarg,"conv,eth",8)){
599 tap_type_name="Ethernet";
600 packet_func=iousers_eth_packet;
601 } else if(!strncmp(optarg,"conv,fc",7)){
608 tap_type_name="Fibre Channel";
609 packet_func=iousers_fc_packet;
610 } else if(!strncmp(optarg,"conv,fddi",9)){
617 tap_type_name="FDDI";
618 packet_func=iousers_fddi_packet;
619 } else if(!strncmp(optarg,"conv,tcp",8)){
627 packet_func=iousers_tcpip_packet;
628 } else if(!strncmp(optarg,"conv,udp",8)){
636 packet_func=iousers_udpip_packet;
637 } else if(!strncmp(optarg,"conv,tr",7)){
644 tap_type_name="Token Ring";
645 packet_func=iousers_tr_packet;
646 } else if(!strncmp(optarg,"conv,ipx",8)){
654 packet_func=iousers_ipx_packet;
655 } else if(!strncmp(optarg,"conv,ip",7)){
662 tap_type_name="IPv4";
663 packet_func=iousers_ip_packet;
664 } else if(!strncmp(optarg,"conv,sctp",9)) {
671 tap_type_name="SCTP";
672 packet_func=iousers_sctp_packet;
674 fprintf(stderr, "tshark: invalid \"-z conv,<type>[,<filter>]\" argument\n");
675 fprintf(stderr," <type> must be one of\n");
676 fprintf(stderr," \"eth\"\n");
677 fprintf(stderr," \"fc\"\n");
678 fprintf(stderr," \"fddi\"\n");
679 fprintf(stderr," \"ip\"\n");
680 fprintf(stderr," \"ipx\"\n");
681 fprintf(stderr," \"sctp\"\n");
682 fprintf(stderr," \"tcp\"\n");
683 fprintf(stderr," \"tr\"\n");
684 fprintf(stderr," \"udp\"\n");
689 iu=g_malloc(sizeof(io_users_t));
691 iu->type=tap_type_name;
693 iu->filter=g_strdup(filter);
698 error_string=register_tap_listener(tap_type, iu, filter, 0, NULL, packet_func, iousers_draw);
704 fprintf(stderr, "tshark: Couldn't register conversations tap: %s\n",
706 g_string_free(error_string, TRUE);
713 register_tap_listener_iousers(void)
715 register_stat_cmd_arg("conv,", iousers_init, NULL);