Change includes for getenv_utf8()
[obnox/wireshark/wip.git] / tap-iousers.c
1 /* tap-iousers.c
2  * iostat   2003 Ronnie Sahlberg
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #include <string.h>
36 #include <epan/packet_info.h>
37 #include <epan/packet.h>
38 #include <epan/addr_resolv.h>
39 #include <epan/tap.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>
53
54 typedef struct _io_users_t {
55         const char *type;
56         char *filter;
57         struct _io_users_item_t *items;
58 } io_users_t;
59
60 typedef struct _io_users_item_t {
61         struct _io_users_item_t *next;
62         char *name1;
63         char *name2;
64         address addr1;
65         address addr2;
66         guint32 frames1;
67         guint32 frames2;
68         guint64 bytes1;
69         guint64 bytes2;
70 } io_users_item_t;
71
72
73 static int
74 iousers_udpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vudph)
75 {
76         io_users_t *iu=arg;
77         const e_udphdr *udph=vudph;
78         char name1[256],name2[256];
79         io_users_item_t *iui;
80         int direction=0;
81
82         if(udph->uh_sport>udph->uh_dport){
83                 direction=0;
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){
87                 direction=1;
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){
91                 direction=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));
94         } else {
95                 direction=1;
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));
98         }
99
100         for(iui=iu->items;iui;iui=iui->next){
101                 if((!strcmp(iui->name1, name1))
102                 && (!strcmp(iui->name2, name2)) ){
103                         break;
104                 }
105         }
106
107         if(!iui){
108                 iui=g_malloc(sizeof(io_users_item_t));
109                 iui->next=iu->items;
110                 iu->items=iui;
111 /*              iui->addr1=NULL;*/
112                 iui->name1=g_strdup(name1);
113 /*              iui->addr2=NULL;*/
114                 iui->name2=g_strdup(name2);
115                 iui->frames1=0;
116                 iui->frames2=0;
117                 iui->bytes1=0;
118                 iui->bytes2=0;
119         }
120
121         if(direction){
122                 iui->frames1++;
123                 iui->bytes1+=pinfo->fd->pkt_len;
124         } else {
125                 iui->frames2++;
126                 iui->bytes2+=pinfo->fd->pkt_len;
127         }
128
129         return 1;
130 }
131
132
133 static int
134 iousers_sctp_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vsctp)
135 {
136         io_users_t *iu=arg;
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;
140         int direction=0;
141
142         g_snprintf(s_sport, sizeof s_sport, "%d",sctph->sport);
143         g_snprintf(s_dport, sizeof s_dport, "%d",sctph->dport);
144
145         if(sctph->sport > sctph->dport) {
146                 direction=0;
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) {
150                 direction=1;
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);
153         } else {
154                 direction=0;
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);
157         }
158
159         for(iui=iu->items;iui;iui=iui->next){
160                 if((!strcmp(iui->name1, name1))
161                  && (!strcmp(iui->name2, name2)) ){
162                         break;
163                 }
164         }
165
166         if(!iui){
167                 iui=g_malloc(sizeof(io_users_item_t));
168                 iui->next=iu->items;
169                 iu->items=iui;
170 /*              iui->addr1=NULL;*/
171                 iui->name1=g_strdup(name1);
172 /*              iui->addr2=NULL;*/
173                 iui->name2=g_strdup(name2);
174                 iui->frames1=0;
175                 iui->frames2=0;
176                 iui->bytes1=0;
177                 iui->bytes2=0;
178         }
179
180         if(direction){
181                 iui->frames1++;
182                 iui->bytes1+=pinfo->fd->pkt_len;
183         } else {
184                 iui->frames2++;
185                 iui->bytes2+=pinfo->fd->pkt_len;
186         }
187
188         return 1;
189 }
190
191
192 static int
193 iousers_tcpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtcph)
194 {
195         io_users_t *iu=arg;
196         const struct tcpheader *tcph=vtcph;
197         char name1[256],name2[256];
198         io_users_item_t *iui;
199         int direction=0;
200
201         if(tcph->th_sport>tcph->th_dport){
202                 direction=0;
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){
206                 direction=1;
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){
210                 direction=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));
213         } else {
214                 direction=1;
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));
217         }
218
219         for(iui=iu->items;iui;iui=iui->next){
220                 if((!strcmp(iui->name1, name1))
221                 && (!strcmp(iui->name2, name2)) ){
222                         break;
223                 }
224         }
225
226         if(!iui){
227                 iui=g_malloc(sizeof(io_users_item_t));
228                 iui->next=iu->items;
229                 iu->items=iui;
230 /*              iui->addr1=NULL;*/
231                 iui->name1=g_strdup(name1);
232 /*              iui->addr2=NULL;*/
233                 iui->name2=g_strdup(name2);
234                 iui->frames1=0;
235                 iui->frames2=0;
236                 iui->bytes1=0;
237                 iui->bytes2=0;
238         }
239
240         if(direction){
241                 iui->frames1++;
242                 iui->bytes1+=pinfo->fd->pkt_len;
243         } else {
244                 iui->frames2++;
245                 iui->bytes2+=pinfo->fd->pkt_len;
246         }
247
248         return 1;
249 }
250
251
252 static int
253 iousers_ip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
254 {
255         io_users_t *iu=arg;
256         const ws_ip *iph=vip;
257         const address *addr1, *addr2;
258         io_users_item_t *iui;
259
260         if(CMP_ADDRESS(&iph->ip_src, &iph->ip_dst)>0){
261                 addr1=&iph->ip_src;
262                 addr2=&iph->ip_dst;
263         } else {
264                 addr2=&iph->ip_src;
265                 addr1=&iph->ip_dst;
266         }
267
268         for(iui=iu->items;iui;iui=iui->next){
269                 if((!CMP_ADDRESS(&iui->addr1, addr1))
270                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
271                         break;
272                 }
273         }
274
275         if(!iui){
276                 iui=g_malloc(sizeof(io_users_item_t));
277                 iui->next=iu->items;
278                 iu->items=iui;
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));
283                 iui->frames1=0;
284                 iui->frames2=0;
285                 iui->bytes1=0;
286                 iui->bytes2=0;
287         }
288
289         if(!CMP_ADDRESS(&iph->ip_dst, &iui->addr1)){
290                 iui->frames1++;
291                 iui->bytes1+=pinfo->fd->pkt_len;
292         } else {
293                 iui->frames2++;
294                 iui->bytes2+=pinfo->fd->pkt_len;
295         }
296
297         return 1;
298 }
299
300 static int
301 iousers_ipv6_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
302 {
303         io_users_t *iu=arg;
304         const struct ip6_hdr *ip6h=vip;
305         address src, dst;
306         const address *addr1, *addr2;
307         io_users_item_t *iui;
308
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;
314
315         if(CMP_ADDRESS(&src, &dst)>0){
316                 addr1=&src;
317                 addr2=&dst;
318         } else {
319                 addr2=&src;
320                 addr1=&dst;
321         }
322
323         for(iui=iu->items;iui;iui=iui->next){
324                 if((!CMP_ADDRESS(&iui->addr1, addr1))
325                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
326                         break;
327                 }
328         }
329
330         if(!iui){
331                 iui=g_malloc(sizeof(io_users_item_t));
332                 iui->next=iu->items;
333                 iu->items=iui;
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));
338                 iui->frames1=0;
339                 iui->frames2=0;
340                 iui->bytes1=0;
341                 iui->bytes2=0;
342         }
343
344         if(!CMP_ADDRESS(&dst, &iui->addr1)){
345                 iui->frames1++;
346                 iui->bytes1+=pinfo->fd->pkt_len;
347         } else {
348                 iui->frames2++;
349                 iui->bytes2+=pinfo->fd->pkt_len;
350         }
351
352         return 1;
353 }
354
355 static int
356 iousers_ipx_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vipx)
357 {
358         io_users_t *iu=arg;
359         const ipxhdr_t *ipxh=vipx;
360         const address *addr1, *addr2;
361         io_users_item_t *iui;
362
363         if(CMP_ADDRESS(&ipxh->ipx_src, &ipxh->ipx_dst)>0){
364                 addr1=&ipxh->ipx_src;
365                 addr2=&ipxh->ipx_dst;
366         } else {
367                 addr2=&ipxh->ipx_src;
368                 addr1=&ipxh->ipx_dst;
369         }
370
371         for(iui=iu->items;iui;iui=iui->next){
372                 if((!CMP_ADDRESS(&iui->addr1, addr1))
373                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
374                         break;
375                 }
376         }
377
378         if(!iui){
379                 iui=g_malloc(sizeof(io_users_item_t));
380                 iui->next=iu->items;
381                 iu->items=iui;
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));
386                 iui->frames1=0;
387                 iui->frames2=0;
388                 iui->bytes1=0;
389                 iui->bytes2=0;
390         }
391
392         if(!CMP_ADDRESS(&ipxh->ipx_dst, &iui->addr1)){
393                 iui->frames1++;
394                 iui->bytes1+=pinfo->fd->pkt_len;
395         } else {
396                 iui->frames2++;
397                 iui->bytes2+=pinfo->fd->pkt_len;
398         }
399
400         return 1;
401 }
402
403 static int
404 iousers_fc_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vfc)
405 {
406         io_users_t *iu=arg;
407         const fc_hdr *fchdr=vfc;
408         const address *addr1, *addr2;
409         io_users_item_t *iui;
410
411         if(CMP_ADDRESS(&fchdr->s_id, &fchdr->d_id)<0){
412                 addr1=&fchdr->s_id;
413                 addr2=&fchdr->d_id;
414         } else {
415                 addr2=&fchdr->s_id;
416                 addr1=&fchdr->d_id;
417         }
418
419         for(iui=iu->items;iui;iui=iui->next){
420                 if((!CMP_ADDRESS(&iui->addr1, addr1))
421                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
422                         break;
423                 }
424         }
425
426         if(!iui){
427                 iui=g_malloc(sizeof(io_users_item_t));
428                 iui->next=iu->items;
429                 iu->items=iui;
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));
434                 iui->frames1=0;
435                 iui->frames2=0;
436                 iui->bytes1=0;
437                 iui->bytes2=0;
438         }
439
440         if(!CMP_ADDRESS(&fchdr->d_id,&iui->addr1)){
441                 iui->frames1++;
442                 iui->bytes1+=pinfo->fd->pkt_len;
443         } else {
444                 iui->frames2++;
445                 iui->bytes2+=pinfo->fd->pkt_len;
446         }
447
448         return 1;
449 }
450
451 static int
452 iousers_eth_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
453 {
454         io_users_t *iu=arg;
455         const eth_hdr *ehdr=veth;
456         const address *addr1, *addr2;
457         io_users_item_t *iui;
458
459         if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
460                 addr1=&ehdr->src;
461                 addr2=&ehdr->dst;
462         } else {
463                 addr2=&ehdr->src;
464                 addr1=&ehdr->dst;
465         }
466
467         for(iui=iu->items;iui;iui=iui->next){
468                 if((!CMP_ADDRESS(&iui->addr1, addr1))
469                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
470                         break;
471                 }
472         }
473
474         if(!iui){
475                 iui=g_malloc(sizeof(io_users_item_t));
476                 iui->next=iu->items;
477                 iu->items=iui;
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));
482                 iui->frames1=0;
483                 iui->frames2=0;
484                 iui->bytes1=0;
485                 iui->bytes2=0;
486         }
487
488         if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
489                 iui->frames1++;
490                 iui->bytes1+=pinfo->fd->pkt_len;
491         } else {
492                 iui->frames2++;
493                 iui->bytes2+=pinfo->fd->pkt_len;
494         }
495
496         return 1;
497 }
498
499 static int
500 iousers_fddi_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
501 {
502         io_users_t *iu=arg;
503         const fddi_hdr *ehdr=veth;
504         const address *addr1, *addr2;
505         io_users_item_t *iui;
506
507         if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
508                 addr1=&ehdr->src;
509                 addr2=&ehdr->dst;
510         } else {
511                 addr2=&ehdr->src;
512                 addr1=&ehdr->dst;
513         }
514
515         for(iui=iu->items;iui;iui=iui->next){
516                 if((!CMP_ADDRESS(&iui->addr1, addr1))
517                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
518                         break;
519                 }
520         }
521
522         if(!iui){
523                 iui=g_malloc(sizeof(io_users_item_t));
524                 iui->next=iu->items;
525                 iu->items=iui;
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));
530                 iui->frames1=0;
531                 iui->frames2=0;
532                 iui->bytes1=0;
533                 iui->bytes2=0;
534         }
535
536         if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
537                 iui->frames1++;
538                 iui->bytes1+=pinfo->fd->pkt_len;
539         } else {
540                 iui->frames2++;
541                 iui->bytes2+=pinfo->fd->pkt_len;
542         }
543
544         return 1;
545 }
546
547 static int
548 iousers_tr_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtr)
549 {
550         io_users_t *iu=arg;
551         const tr_hdr *trhdr=vtr;
552         const address *addr1, *addr2;
553         io_users_item_t *iui;
554
555         if(CMP_ADDRESS(&trhdr->src, &trhdr->dst)<0){
556                 addr1=&trhdr->src;
557                 addr2=&trhdr->dst;
558         } else {
559                 addr2=&trhdr->src;
560                 addr1=&trhdr->dst;
561         }
562
563         for(iui=iu->items;iui;iui=iui->next){
564                 if((!CMP_ADDRESS(&iui->addr1, addr1))
565                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
566                         break;
567                 }
568         }
569
570         if(!iui){
571                 iui=g_malloc(sizeof(io_users_item_t));
572                 iui->next=iu->items;
573                 iu->items=iui;
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));
578                 iui->frames1=0;
579                 iui->frames2=0;
580                 iui->bytes1=0;
581                 iui->bytes2=0;
582         }
583
584         if(!CMP_ADDRESS(&trhdr->dst,&iui->addr1)){
585                 iui->frames1++;
586                 iui->bytes1+=pinfo->fd->pkt_len;
587         } else {
588                 iui->frames2++;
589                 iui->bytes2+=pinfo->fd->pkt_len;
590         }
591
592         return 1;
593 }
594
595 static void
596 iousers_draw(void *arg)
597 {
598         io_users_t *iu = arg;
599         io_users_item_t *iui;
600         guint32 last_frames, max_frames;
601
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;
608         do {
609                 last_frames=0;
610                 for(iui=iu->items;iui;iui=iui->next){
611                         guint32 tot_frames;
612                         tot_frames=iui->frames1+iui->frames2;
613
614                         if((tot_frames>last_frames)
615                         &&(tot_frames<max_frames)){
616                                 last_frames=tot_frames;
617                         }
618                 }
619                 for(iui=iu->items;iui;iui=iui->next){
620                         guint32 tot_frames;
621                         tot_frames=iui->frames1+iui->frames2;
622
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
630                                 );
631                         }
632                 }
633                 max_frames=last_frames;
634         } while(last_frames);
635         printf("================================================================================\n");
636 }
637
638 static void
639 iousers_init(const char *optarg, void* userdata _U_)
640 {
641         const char *filter=NULL;
642         const char *tap_type, *tap_type_name;
643         tap_packet_cb packet_func;
644         io_users_t *iu=NULL;
645         GString *error_string;
646
647         if(!strncmp(optarg,"conv,eth",8)){
648                 if(optarg[8]==','){
649                         filter=optarg+9;
650                 } else {
651                         filter=NULL;
652                 }
653                 tap_type="eth";
654                 tap_type_name="Ethernet";
655                 packet_func=iousers_eth_packet;
656         } else if(!strncmp(optarg,"conv,fc",7)){
657                 if(optarg[7]==','){
658                         filter=optarg+8;
659                 } else {
660                         filter=NULL;
661                 }
662                 tap_type="fc";
663                 tap_type_name="Fibre Channel";
664                 packet_func=iousers_fc_packet;
665         } else if(!strncmp(optarg,"conv,fddi",9)){
666                 if(optarg[9]==','){
667                         filter=optarg+10;
668                 } else {
669                         filter=NULL;
670                 }
671                 tap_type="fddi";
672                 tap_type_name="FDDI";
673                 packet_func=iousers_fddi_packet;
674         } else if(!strncmp(optarg,"conv,tcp",8)){
675                 if(optarg[8]==','){
676                         filter=optarg+9;
677                 } else {
678                         filter=NULL;
679                 }
680                 tap_type="tcp";
681                 tap_type_name="TCP";
682                 packet_func=iousers_tcpip_packet;
683         } else if(!strncmp(optarg,"conv,udp",8)){
684                 if(optarg[8]==','){
685                         filter=optarg+9;
686                 } else {
687                         filter=NULL;
688                 }
689                 tap_type="udp";
690                 tap_type_name="UDP";
691                 packet_func=iousers_udpip_packet;
692         } else if(!strncmp(optarg,"conv,tr",7)){
693                 if(optarg[7]==','){
694                         filter=optarg+8;
695                 } else {
696                         filter=NULL;
697                 }
698                 tap_type="tr";
699                 tap_type_name="Token Ring";
700                 packet_func=iousers_tr_packet;
701         } else if(!strncmp(optarg,"conv,ipx",8)){
702                 if(optarg[8]==','){
703                         filter=optarg+9;
704                 } else {
705                         filter=NULL;
706                 }
707                 tap_type="ipx";
708                 tap_type_name="IPX";
709                 packet_func=iousers_ipx_packet;
710         } else if(!strncmp(optarg,"conv,ip",7)){
711                 if(optarg[7]==','){
712                         filter=optarg+8;
713                 } else {
714                         filter=NULL;
715                 }
716                 tap_type="ip";
717                 tap_type_name="IPv4";
718                 packet_func=iousers_ip_packet;
719         } else if(!strncmp(optarg,"conv,ipv6",7)){
720                 if(optarg[7]==','){
721                         filter=optarg+10;
722                 } else {
723                         filter=NULL;
724                 }
725                 tap_type="ipv6";
726                 tap_type_name="IPv6";
727                 packet_func=iousers_ipv6_packet;
728         } else if(!strncmp(optarg,"conv,sctp",9)) {
729                 if(optarg[9]==','){
730                                 filter=optarg+10;
731                 } else {
732                         filter=NULL;
733                 }
734                 tap_type="sctp";
735                 tap_type_name="SCTP";
736                 packet_func=iousers_sctp_packet;
737         } else {
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");
749                 exit(1);
750         }
751
752
753         iu=g_malloc(sizeof(io_users_t));
754         iu->items=NULL;
755         iu->type=tap_type_name;
756         if(filter){
757                 iu->filter=g_strdup(filter);
758         } else {
759                 iu->filter=NULL;
760         }
761
762         error_string=register_tap_listener(tap_type, iu, filter, 0, NULL, packet_func, iousers_draw);
763         if(error_string){
764                 if(iu->items){
765                         g_free(iu->items);
766                 }
767                 g_free(iu);
768                 fprintf(stderr, "tshark: Couldn't register conversations tap: %s\n",
769                     error_string->str);
770                 g_string_free(error_string, TRUE);
771                 exit(1);
772         }
773
774 }
775
776 void
777 register_tap_listener_iousers(void)
778 {
779         register_stat_cmd_arg("conv,", iousers_init, NULL);
780 }