1e7521f0d5c68e5c775cdb379d3cf2290c07ddc5
[obnox/wireshark/wip.git] / tap-iousers.c
1 /* tap-iousers.c
2  * iostat   2003 Ronnie Sahlberg
3  *
4  * $Id$
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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/emem.h>
39 #include <epan/addr_resolv.h>
40 #include <epan/tap.h>
41 #include <epan/stat_cmd_args.h>
42 #include "register.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-fc.h>
51 #include <epan/dissectors/packet-fddi.h>
52
53 typedef struct _io_users_t {
54         const char *type;
55         char *filter;
56         struct _io_users_item_t *items;
57 } io_users_t;
58
59 typedef struct _io_users_item_t {
60         struct _io_users_item_t *next;
61         char *name1;
62         char *name2;
63         address addr1;
64         address addr2; 
65         guint32 frames1;
66         guint32 frames2;
67         guint32 bytes1;
68         guint32 bytes2;
69 } io_users_item_t;
70
71
72 static int
73 iousers_udpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vudph)
74 {
75         io_users_t *iu=arg;
76         const e_udphdr *udph=vudph;
77         char name1[256],name2[256];
78         io_users_item_t *iui;
79         int direction=0;
80
81         if(udph->uh_sport>udph->uh_dport){
82                 direction=0;
83                 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
84                 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
85         } else if(udph->uh_sport<udph->uh_dport){
86                 direction=1;
87                 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
88                 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
89         } else if(CMP_ADDRESS(&udph->ip_src, &udph->ip_dst)>0){
90                 direction=0;
91                 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
92                 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
93         } else {
94                 direction=1;
95                 g_snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
96                 g_snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
97         }
98
99         for(iui=iu->items;iui;iui=iui->next){
100                 if((!strcmp(iui->name1, name1))
101                 && (!strcmp(iui->name2, name2)) ){
102                         break;
103                 }
104         }
105
106         if(!iui){
107                 iui=g_malloc(sizeof(io_users_item_t));
108                 iui->next=iu->items;
109                 iu->items=iui;
110 /*              iui->addr1=NULL;*/
111                 iui->name1=strdup(name1);
112 /*              iui->addr2=NULL;*/
113                 iui->name2=strdup(name2);
114                 iui->frames1=0;
115                 iui->frames2=0;
116                 iui->bytes1=0;
117                 iui->bytes2=0;
118         }
119
120         if(direction){
121                 iui->frames1++;
122                 iui->bytes1+=pinfo->fd->pkt_len;
123         } else {
124                 iui->frames2++;
125                 iui->bytes2+=pinfo->fd->pkt_len;
126         }
127
128         return 1;
129 }
130
131
132 static int
133 iousers_sctp_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vsctp)
134 {
135         io_users_t *iu=arg;
136         const struct _sctp_info* sctph = vsctp;
137         char name1[256],name2[256], s_sport[10], s_dport[10];
138         io_users_item_t *iui;
139         int direction=0;
140
141         g_snprintf(s_sport, sizeof s_sport, "%d",sctph->sport);
142         g_snprintf(s_dport, sizeof s_dport, "%d",sctph->dport);
143         
144         if(sctph->sport > sctph->dport) {
145                 direction=0;
146                 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);   
147                 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);   
148         } else if(sctph->sport < sctph->dport) {
149                 direction=1;
150                 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);   
151                 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);   
152         } else {
153                 direction=0;
154                 g_snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);   
155                 g_snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);   
156         }
157
158         for(iui=iu->items;iui;iui=iui->next){
159                 if((!strcmp(iui->name1, name1))
160                  && (!strcmp(iui->name2, name2)) ){
161                         break;
162                 }
163         }
164
165         if(!iui){
166                 iui=g_malloc(sizeof(io_users_item_t));
167                 iui->next=iu->items;
168                 iu->items=iui;
169 /*              iui->addr1=NULL;*/
170                 iui->name1=strdup(name1);
171 /*              iui->addr2=NULL;*/
172                 iui->name2=strdup(name2);
173                 iui->frames1=0;
174                 iui->frames2=0;
175                 iui->bytes1=0;
176                 iui->bytes2=0;
177         }
178
179         if(direction){
180                 iui->frames1++;
181                 iui->bytes1+=pinfo->fd->pkt_len;
182         } else {
183                 iui->frames2++;
184                 iui->bytes2+=pinfo->fd->pkt_len;
185         }
186
187         return 1;
188 }
189
190
191 static int
192 iousers_tcpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtcph)
193 {
194         io_users_t *iu=arg;
195         const struct tcpheader *tcph=vtcph;
196         char name1[256],name2[256];
197         io_users_item_t *iui;
198         int direction=0;
199
200         if(tcph->th_sport>tcph->th_dport){
201                 direction=0;
202                 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
203                 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
204         } else if(tcph->th_sport<tcph->th_dport){
205                 direction=1;
206                 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
207                 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
208         } else if(CMP_ADDRESS(&tcph->ip_src, &tcph->ip_dst)>0){
209                 direction=0;
210                 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
211                 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
212         } else {
213                 direction=1;
214                 g_snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
215                 g_snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
216         }
217
218         for(iui=iu->items;iui;iui=iui->next){
219                 if((!strcmp(iui->name1, name1))
220                 && (!strcmp(iui->name2, name2)) ){
221                         break;
222                 }
223         }
224
225         if(!iui){
226                 iui=g_malloc(sizeof(io_users_item_t));
227                 iui->next=iu->items;
228                 iu->items=iui;
229 /*              iui->addr1=NULL;*/
230                 iui->name1=strdup(name1);
231 /*              iui->addr2=NULL;*/
232                 iui->name2=strdup(name2);
233                 iui->frames1=0;
234                 iui->frames2=0;
235                 iui->bytes1=0;
236                 iui->bytes2=0;
237         }
238
239         if(direction){
240                 iui->frames1++;
241                 iui->bytes1+=pinfo->fd->pkt_len;
242         } else {
243                 iui->frames2++;
244                 iui->bytes2+=pinfo->fd->pkt_len;
245         }
246
247         return 1;
248 }
249
250
251 static int
252 iousers_ip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
253 {
254         io_users_t *iu=arg;
255         const e_ip *iph=vip;
256         const address *addr1, *addr2;
257         io_users_item_t *iui;
258
259         if(CMP_ADDRESS(&iph->ip_src, &iph->ip_dst)>0){
260                 addr1=&iph->ip_src;
261                 addr2=&iph->ip_dst;
262         } else {
263                 addr2=&iph->ip_src;
264                 addr1=&iph->ip_dst;
265         }
266
267         for(iui=iu->items;iui;iui=iui->next){
268                 if((!CMP_ADDRESS(&iui->addr1, addr1))
269                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
270                         break;
271                 }
272         }
273
274         if(!iui){
275                 iui=g_malloc(sizeof(io_users_item_t));
276                 iui->next=iu->items;
277                 iu->items=iui;
278                 COPY_ADDRESS(&iui->addr1, addr1);
279                 iui->name1=strdup(address_to_str(addr1));
280                 COPY_ADDRESS(&iui->addr2, addr2);
281                 iui->name2=strdup(address_to_str(addr2));
282                 iui->frames1=0;
283                 iui->frames2=0;
284                 iui->bytes1=0;
285                 iui->bytes2=0;
286         }
287
288         if(!CMP_ADDRESS(&iph->ip_dst, &iui->addr1)){
289                 iui->frames1++;
290                 iui->bytes1+=pinfo->fd->pkt_len;
291         } else {
292                 iui->frames2++;
293                 iui->bytes2+=pinfo->fd->pkt_len;
294         }
295
296         return 1;
297 }
298
299 static int
300 iousers_ipx_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vipx)
301 {
302         io_users_t *iu=arg;
303         const ipxhdr_t *ipxh=vipx;
304         const address *addr1, *addr2;
305         io_users_item_t *iui;
306
307         if(CMP_ADDRESS(&ipxh->ipx_src, &ipxh->ipx_dst)>0){
308                 addr1=&ipxh->ipx_src;
309                 addr2=&ipxh->ipx_dst;
310         } else {
311                 addr2=&ipxh->ipx_src;
312                 addr1=&ipxh->ipx_dst;
313         }
314
315         for(iui=iu->items;iui;iui=iui->next){
316                 if((!CMP_ADDRESS(&iui->addr1, addr1))
317                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
318                         break;
319                 }
320         }
321
322         if(!iui){
323                 iui=g_malloc(sizeof(io_users_item_t));
324                 iui->next=iu->items;
325                 iu->items=iui;
326                 COPY_ADDRESS(&iui->addr1, addr1);
327                 iui->name1=strdup(address_to_str(addr1));
328                 COPY_ADDRESS(&iui->addr2, addr2);
329                 iui->name2=strdup(address_to_str(addr2));
330                 iui->frames1=0;
331                 iui->frames2=0;
332                 iui->bytes1=0;
333                 iui->bytes2=0;
334         }
335
336         if(!CMP_ADDRESS(&ipxh->ipx_dst, &iui->addr1)){
337                 iui->frames1++;
338                 iui->bytes1+=pinfo->fd->pkt_len;
339         } else {
340                 iui->frames2++;
341                 iui->bytes2+=pinfo->fd->pkt_len;
342         }
343
344         return 1;
345 }
346
347 static int
348 iousers_fc_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vfc)
349 {
350         io_users_t *iu=arg;
351         const fc_hdr *fchdr=vfc;
352         const address *addr1, *addr2;
353         io_users_item_t *iui;
354
355         if(CMP_ADDRESS(&fchdr->s_id, &fchdr->d_id)<0){
356                 addr1=&fchdr->s_id;
357                 addr2=&fchdr->d_id;
358         } else {
359                 addr2=&fchdr->s_id;
360                 addr1=&fchdr->d_id;
361         }
362
363         for(iui=iu->items;iui;iui=iui->next){
364                 if((!CMP_ADDRESS(&iui->addr1, addr1))
365                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
366                         break;
367                 }
368         }
369
370         if(!iui){
371                 iui=g_malloc(sizeof(io_users_item_t));
372                 iui->next=iu->items;
373                 iu->items=iui;
374                 COPY_ADDRESS(&iui->addr1, addr1);
375                 iui->name1=strdup(address_to_str(addr1));
376                 COPY_ADDRESS(&iui->addr2, addr2);
377                 iui->name2=strdup(address_to_str(addr2));
378                 iui->frames1=0;
379                 iui->frames2=0;
380                 iui->bytes1=0;
381                 iui->bytes2=0;
382         }
383
384         if(!CMP_ADDRESS(&fchdr->d_id,&iui->addr1)){
385                 iui->frames1++;
386                 iui->bytes1+=pinfo->fd->pkt_len;
387         } else {
388                 iui->frames2++;
389                 iui->bytes2+=pinfo->fd->pkt_len;
390         }
391
392         return 1;
393 }
394
395 static int
396 iousers_eth_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
397 {
398         io_users_t *iu=arg;
399         const eth_hdr *ehdr=veth;
400         const address *addr1, *addr2;
401         io_users_item_t *iui;
402
403         if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
404                 addr1=&ehdr->src;
405                 addr2=&ehdr->dst;
406         } else {
407                 addr2=&ehdr->src;
408                 addr1=&ehdr->dst;
409         }
410
411         for(iui=iu->items;iui;iui=iui->next){
412                 if((!CMP_ADDRESS(&iui->addr1, addr1))
413                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
414                         break;
415                 }
416         }
417
418         if(!iui){
419                 iui=g_malloc(sizeof(io_users_item_t));
420                 iui->next=iu->items;
421                 iu->items=iui;
422                 COPY_ADDRESS(&iui->addr1, addr1);
423                 iui->name1=strdup(address_to_str(addr1));
424                 COPY_ADDRESS(&iui->addr2, addr2);
425                 iui->name2=strdup(address_to_str(addr2));
426                 iui->frames1=0;
427                 iui->frames2=0;
428                 iui->bytes1=0;
429                 iui->bytes2=0;
430         }
431
432         if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
433                 iui->frames1++;
434                 iui->bytes1+=pinfo->fd->pkt_len;
435         } else {
436                 iui->frames2++;
437                 iui->bytes2+=pinfo->fd->pkt_len;
438         }
439
440         return 1;
441 }
442
443 static int
444 iousers_fddi_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *veth)
445 {
446         io_users_t *iu=arg;
447         const fddi_hdr *ehdr=veth;
448         const address *addr1, *addr2;
449         io_users_item_t *iui;
450
451         if(CMP_ADDRESS(&ehdr->src, &ehdr->dst)<0){
452                 addr1=&ehdr->src;
453                 addr2=&ehdr->dst;
454         } else {
455                 addr2=&ehdr->src;
456                 addr1=&ehdr->dst;
457         }
458
459         for(iui=iu->items;iui;iui=iui->next){
460                 if((!CMP_ADDRESS(&iui->addr1, addr1))
461                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
462                         break;
463                 }
464         }
465
466         if(!iui){
467                 iui=g_malloc(sizeof(io_users_item_t));
468                 iui->next=iu->items;
469                 iu->items=iui;
470                 COPY_ADDRESS(&iui->addr1, addr1);
471                 iui->name1=strdup(address_to_str(addr1));
472                 COPY_ADDRESS(&iui->addr2, addr2);
473                 iui->name2=strdup(address_to_str(addr2));
474                 iui->frames1=0;
475                 iui->frames2=0;
476                 iui->bytes1=0;
477                 iui->bytes2=0;
478         }
479
480         if(!CMP_ADDRESS(&ehdr->dst,&iui->addr1)){
481                 iui->frames1++;
482                 iui->bytes1+=pinfo->fd->pkt_len;
483         } else {
484                 iui->frames2++;
485                 iui->bytes2+=pinfo->fd->pkt_len;
486         }
487
488         return 1;
489 }
490
491 static int
492 iousers_tr_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vtr)
493 {
494         io_users_t *iu=arg;
495         const tr_hdr *trhdr=vtr;
496         const address *addr1, *addr2;
497         io_users_item_t *iui;
498
499         if(CMP_ADDRESS(&trhdr->src, &trhdr->dst)<0){
500                 addr1=&trhdr->src;
501                 addr2=&trhdr->dst;
502         } else {
503                 addr2=&trhdr->src;
504                 addr1=&trhdr->dst;
505         }
506
507         for(iui=iu->items;iui;iui=iui->next){
508                 if((!CMP_ADDRESS(&iui->addr1, addr1))
509                 &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
510                         break;
511                 }
512         }
513
514         if(!iui){
515                 iui=g_malloc(sizeof(io_users_item_t));
516                 iui->next=iu->items;
517                 iu->items=iui;
518                 COPY_ADDRESS(&iui->addr1, addr1);
519                 iui->name1=strdup(address_to_str(addr1));
520                 COPY_ADDRESS(&iui->addr2, addr2);
521                 iui->name2=strdup(address_to_str(addr2));
522                 iui->frames1=0;
523                 iui->frames2=0;
524                 iui->bytes1=0;
525                 iui->bytes2=0;
526         }
527
528         if(!CMP_ADDRESS(&trhdr->dst,&iui->addr1)){
529                 iui->frames1++;
530                 iui->bytes1+=pinfo->fd->pkt_len;
531         } else {
532                 iui->frames2++;
533                 iui->bytes2+=pinfo->fd->pkt_len;
534         }
535
536         return 1;
537 }
538
539 static void
540 iousers_draw(void *arg)
541 {
542         io_users_t *iu = arg;
543         io_users_item_t *iui;
544         guint32 last_frames, max_frames;
545
546         printf("================================================================================\n");
547         printf("%s Conversations\n",iu->type);
548         printf("Filter:%s\n",iu->filter?iu->filter:"<No Filter>");
549         printf("                                               |       <-      | |       ->      | |     Total     |\n");
550         printf("                                               | Frames  Bytes | | Frames  Bytes | | Frames  Bytes |\n");
551         max_frames=0xffffffff;
552         do {
553                 last_frames=0;
554                 for(iui=iu->items;iui;iui=iui->next){
555                         guint32 tot_frames;
556                         tot_frames=iui->frames1+iui->frames2;
557
558                         if((tot_frames>last_frames)
559                         &&(tot_frames<max_frames)){
560                                 last_frames=tot_frames;
561                         }
562                 }
563                 for(iui=iu->items;iui;iui=iui->next){
564                         guint32 tot_frames;
565                         tot_frames=iui->frames1+iui->frames2;
566
567                         if(tot_frames==last_frames){
568                                 printf("%-20s <-> %-20s  %6d %9d  %6d %9d  %6d %9d\n",
569                                         iui->name1, iui->name2,
570                                         iui->frames1, iui->bytes1,
571                                         iui->frames2, iui->bytes2,
572                                         iui->frames1+iui->frames2,
573                                         iui->bytes1+iui->bytes2
574                                 );
575                         }
576                 }
577                 max_frames=last_frames;
578         } while(last_frames);
579         printf("================================================================================\n");
580 }
581
582 void
583 iousers_init(const char *optarg, void* userdata _U_)
584 {
585         const char *filter=NULL;
586         const char *tap_type, *tap_type_name;
587         tap_packet_cb packet_func;
588         io_users_t *iu=NULL;
589         GString *error_string;
590
591         if(!strncmp(optarg,"conv,eth",8)){
592                 if(optarg[8]==','){
593                         filter=optarg+9;
594                 } else {
595                         filter=NULL;
596                 }
597                 tap_type="eth";
598                 tap_type_name="Ethernet";
599                 packet_func=iousers_eth_packet;
600         } else if(!strncmp(optarg,"conv,fc",7)){
601                 if(optarg[7]==','){
602                         filter=optarg+8;
603                 } else {
604                         filter=NULL;
605                 }
606                 tap_type="fc";
607                 tap_type_name="Fibre Channel";
608                 packet_func=iousers_fc_packet;
609         } else if(!strncmp(optarg,"conv,fddi",9)){
610                 if(optarg[9]==','){
611                         filter=optarg+10;
612                 } else {
613                         filter=NULL;
614                 }
615                 tap_type="fddi";
616                 tap_type_name="FDDI";
617                 packet_func=iousers_fddi_packet;
618         } else if(!strncmp(optarg,"conv,tcp",8)){
619                 if(optarg[8]==','){
620                         filter=optarg+9;
621                 } else {
622                         filter=NULL;
623                 }
624                 tap_type="tcp";
625                 tap_type_name="TCP";
626                 packet_func=iousers_tcpip_packet;
627         } else if(!strncmp(optarg,"conv,udp",8)){
628                 if(optarg[8]==','){
629                         filter=optarg+9;
630                 } else {
631                         filter=NULL;
632                 }
633                 tap_type="udp";
634                 tap_type_name="UDP";
635                 packet_func=iousers_udpip_packet;
636         } else if(!strncmp(optarg,"conv,tr",7)){
637                 if(optarg[7]==','){
638                         filter=optarg+8;
639                 } else {
640                         filter=NULL;
641                 }
642                 tap_type="tr";
643                 tap_type_name="Token Ring";
644                 packet_func=iousers_tr_packet;
645         } else if(!strncmp(optarg,"conv,ipx",8)){
646                 if(optarg[8]==','){
647                         filter=optarg+9;
648                 } else {
649                         filter=NULL;
650                 }
651                 tap_type="ipx";
652                 tap_type_name="IPX";
653                 packet_func=iousers_ipx_packet;
654         } else if(!strncmp(optarg,"conv,ip",7)){
655                 if(optarg[7]==','){
656                         filter=optarg+8;
657                 } else {
658                         filter=NULL;
659                 }
660                 tap_type="ip";
661                 tap_type_name="IPv4";
662                 packet_func=iousers_ip_packet;
663         } else if(!strncmp(optarg,"conv,sctp",9)) {
664                 if(optarg[9]==','){
665                                 filter=optarg+10;
666                 } else {
667                         filter=NULL;
668                 }
669                 tap_type="sctp";
670                 tap_type_name="SCTP";
671                 packet_func=iousers_sctp_packet;
672         } else {
673                 fprintf(stderr, "tethereal: invalid \"-z conv,<type>[,<filter>]\" argument\n");
674                 fprintf(stderr,"   <type> must be one of\n");
675                 fprintf(stderr,"      \"eth\"\n");
676                 fprintf(stderr,"      \"fc\"\n");
677                 fprintf(stderr,"      \"fddi\"\n");
678                 fprintf(stderr,"      \"ip\"\n");
679                 fprintf(stderr,"      \"ipx\"\n");
680                 fprintf(stderr,"      \"sctp\"\n");
681                 fprintf(stderr,"      \"tcp\"\n");
682                 fprintf(stderr,"      \"tr\"\n");
683                 fprintf(stderr,"      \"udp\"\n");
684                 exit(1);
685         }
686
687
688         iu=g_malloc(sizeof(io_users_t));
689         iu->items=NULL;
690         iu->type=tap_type_name;
691         if(filter){
692                 iu->filter=strdup(filter);
693         } else {
694                 iu->filter=NULL;
695         }
696
697         error_string=register_tap_listener(tap_type, iu, filter, NULL, packet_func, iousers_draw);
698         if(error_string){
699                 if(iu->items){
700                         g_free(iu->items);
701                 }
702                 g_free(iu);
703                 fprintf(stderr, "tethereal: Couldn't register conversations tap: %s\n",
704                     error_string->str);
705                 g_string_free(error_string, TRUE);
706                 exit(1);
707         }
708
709 }
710
711 void
712 register_tap_listener_iousers(void)
713 {
714         register_stat_cmd_arg("conv,", iousers_init, NULL);
715 }