Update some links.
[obnox/wireshark/wip.git] / tap-iousers.c
index 693dbe36f7f7bd8012613f1b2b0cf21316962152..1cfe1c1385961b3e48162d47958d8ed96c5869cd 100644 (file)
@@ -3,20 +3,20 @@
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <epan/packet.h>
 #include <epan/addr_resolv.h>
 #include <epan/tap.h>
+#include <epan/conversation.h>
+#include <epan/stat_cmd_args.h>
 #include "register.h"
 #include <epan/dissectors/packet-ip.h>
+#include <epan/dissectors/packet-ipv6.h>
 #include <epan/dissectors/packet-ipx.h>
 #include <epan/dissectors/packet-tcp.h>
 #include <epan/dissectors/packet-udp.h>
 #include <epan/dissectors/packet-eth.h>
 #include <epan/dissectors/packet-sctp.h>
 #include <epan/dissectors/packet-tr.h>
+#include <epan/dissectors/packet-scsi.h>
 #include <epan/dissectors/packet-fc.h>
 #include <epan/dissectors/packet-fddi.h>
-#include <string.h>
 
 typedef struct _io_users_t {
        const char *type;
@@ -60,11 +63,11 @@ typedef struct _io_users_item_t {
        char *name1;
        char *name2;
        address addr1;
-       address addr2; 
+       address addr2;
        guint32 frames1;
        guint32 frames2;
-       guint32 bytes1;
-       guint32 bytes2;
+       guint64 bytes1;
+       guint64 bytes2;
 } io_users_item_t;
 
 
@@ -79,20 +82,20 @@ iousers_udpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, con
 
        if(udph->uh_sport>udph->uh_dport){
                direction=0;
-               snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
-               snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
        } else if(udph->uh_sport<udph->uh_dport){
                direction=1;
-               snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
-               snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
        } else if(CMP_ADDRESS(&udph->ip_src, &udph->ip_dst)>0){
                direction=0;
-               snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
-               snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
        } else {
                direction=1;
-               snprintf(name2,256,"%s:%s",address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
-               snprintf(name1,256,"%s:%s",address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&udph->ip_src),get_udp_port(udph->uh_sport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&udph->ip_dst),get_udp_port(udph->uh_dport));
        }
 
        for(iui=iu->items;iui;iui=iui->next){
@@ -107,9 +110,9 @@ iousers_udpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, con
                iui->next=iu->items;
                iu->items=iui;
 /*             iui->addr1=NULL;*/
-               iui->name1=strdup(name1);
+               iui->name1=g_strdup(name1);
 /*             iui->addr2=NULL;*/
-               iui->name2=strdup(name2);
+               iui->name2=g_strdup(name2);
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -137,21 +140,21 @@ iousers_sctp_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, cons
        io_users_item_t *iui;
        int direction=0;
 
-       sprintf(s_sport,"%d",sctph->sport);
-       sprintf(s_dport,"%d",sctph->dport);
-       
+       g_snprintf(s_sport, sizeof s_sport, "%d",sctph->sport);
+       g_snprintf(s_dport, sizeof s_dport, "%d",sctph->dport);
+
        if(sctph->sport > sctph->dport) {
                direction=0;
-               snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);     
-               snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);     
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&sctph->ip_src),s_sport);
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&sctph->ip_dst),s_dport);
        } else if(sctph->sport < sctph->dport) {
                direction=1;
-               snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);     
-               snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);     
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&sctph->ip_src),s_sport);
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&sctph->ip_dst),s_dport);
        } else {
                direction=0;
-               snprintf(name1,256,"%s:%s",address_to_str(&sctph->ip_src),s_sport);     
-               snprintf(name2,256,"%s:%s",address_to_str(&sctph->ip_dst),s_dport);     
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&sctph->ip_src),s_sport);
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&sctph->ip_dst),s_dport);
        }
 
        for(iui=iu->items;iui;iui=iui->next){
@@ -166,9 +169,9 @@ iousers_sctp_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, cons
                 iui->next=iu->items;
                 iu->items=iui;
 /*              iui->addr1=NULL;*/
-                iui->name1=strdup(name1);
+                iui->name1=g_strdup(name1);
 /*              iui->addr2=NULL;*/
-                iui->name2=strdup(name2);
+                iui->name2=g_strdup(name2);
                 iui->frames1=0;
                 iui->frames2=0;
                 iui->bytes1=0;
@@ -198,20 +201,20 @@ iousers_tcpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, con
 
        if(tcph->th_sport>tcph->th_dport){
                direction=0;
-               snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
-               snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
        } else if(tcph->th_sport<tcph->th_dport){
                direction=1;
-               snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
-               snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
        } else if(CMP_ADDRESS(&tcph->ip_src, &tcph->ip_dst)>0){
                direction=0;
-               snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
-               snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
        } else {
                direction=1;
-               snprintf(name2,256,"%s:%s",address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
-               snprintf(name1,256,"%s:%s",address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
+               g_snprintf(name2,256,"%s:%s",ep_address_to_str(&tcph->ip_src),get_tcp_port(tcph->th_sport));
+               g_snprintf(name1,256,"%s:%s",ep_address_to_str(&tcph->ip_dst),get_tcp_port(tcph->th_dport));
        }
 
        for(iui=iu->items;iui;iui=iui->next){
@@ -226,9 +229,9 @@ iousers_tcpip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, con
                iui->next=iu->items;
                iu->items=iui;
 /*             iui->addr1=NULL;*/
-               iui->name1=strdup(name1);
+               iui->name1=g_strdup(name1);
 /*             iui->addr2=NULL;*/
-               iui->name2=strdup(name2);
+               iui->name2=g_strdup(name2);
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -251,7 +254,7 @@ static int
 iousers_ip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
 {
        io_users_t *iu=arg;
-       const e_ip *iph=vip;
+       const ws_ip *iph=vip;
        const address *addr1, *addr2;
        io_users_item_t *iui;
 
@@ -275,9 +278,9 @@ iousers_ip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
                iui->next=iu->items;
                iu->items=iui;
                COPY_ADDRESS(&iui->addr1, addr1);
-               iui->name1=strdup(address_to_str(addr1));
+               iui->name1=g_strdup(ep_address_to_str(addr1));
                COPY_ADDRESS(&iui->addr2, addr2);
-               iui->name2=strdup(address_to_str(addr2));
+               iui->name2=g_strdup(ep_address_to_str(addr2));
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -295,6 +298,61 @@ iousers_ip_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
        return 1;
 }
 
+static int
+iousers_ipv6_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip)
+{
+       io_users_t *iu=arg;
+       const struct ip6_hdr *ip6h=vip;
+       address src, dst;
+       const address *addr1, *addr2;
+       io_users_item_t *iui;
+
+       /* Addresses aren't implemented as 'address' type in struct ip6_hdr */
+       src.type = dst.type = AT_IPv6;
+       src.len  = dst.len = sizeof(struct e_in6_addr);
+       src.data = &ip6h->ip6_src;
+       dst.data = &ip6h->ip6_dst;
+
+       if(CMP_ADDRESS(&src, &dst)>0){
+               addr1=&src;
+               addr2=&dst;
+       } else {
+               addr2=&src;
+               addr1=&dst;
+       }
+
+       for(iui=iu->items;iui;iui=iui->next){
+               if((!CMP_ADDRESS(&iui->addr1, addr1))
+               &&(!CMP_ADDRESS(&iui->addr2, addr2)) ){
+                       break;
+               }
+       }
+
+       if(!iui){
+               iui=g_malloc(sizeof(io_users_item_t));
+               iui->next=iu->items;
+               iu->items=iui;
+               COPY_ADDRESS(&iui->addr1, addr1);
+               iui->name1=g_strdup(ep_address_to_str(addr1));
+               COPY_ADDRESS(&iui->addr2, addr2);
+               iui->name2=g_strdup(ep_address_to_str(addr2));
+               iui->frames1=0;
+               iui->frames2=0;
+               iui->bytes1=0;
+               iui->bytes2=0;
+       }
+
+       if(!CMP_ADDRESS(&dst, &iui->addr1)){
+               iui->frames1++;
+               iui->bytes1+=pinfo->fd->pkt_len;
+       } else {
+               iui->frames2++;
+               iui->bytes2+=pinfo->fd->pkt_len;
+       }
+
+       return 1;
+}
+
 static int
 iousers_ipx_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vipx)
 {
@@ -323,9 +381,9 @@ iousers_ipx_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
                iui->next=iu->items;
                iu->items=iui;
                COPY_ADDRESS(&iui->addr1, addr1);
-               iui->name1=strdup(address_to_str(addr1));
+               iui->name1=g_strdup(ep_address_to_str(addr1));
                COPY_ADDRESS(&iui->addr2, addr2);
-               iui->name2=strdup(address_to_str(addr2));
+               iui->name2=g_strdup(ep_address_to_str(addr2));
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -371,9 +429,9 @@ iousers_fc_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
                iui->next=iu->items;
                iu->items=iui;
                COPY_ADDRESS(&iui->addr1, addr1);
-               iui->name1=strdup(address_to_str(addr1));
+               iui->name1=g_strdup(ep_address_to_str(addr1));
                COPY_ADDRESS(&iui->addr2, addr2);
-               iui->name2=strdup(address_to_str(addr2));
+               iui->name2=g_strdup(ep_address_to_str(addr2));
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -419,9 +477,9 @@ iousers_eth_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
                iui->next=iu->items;
                iu->items=iui;
                COPY_ADDRESS(&iui->addr1, addr1);
-               iui->name1=strdup(address_to_str(addr1));
+               iui->name1=g_strdup(ep_address_to_str(addr1));
                COPY_ADDRESS(&iui->addr2, addr2);
-               iui->name2=strdup(address_to_str(addr2));
+               iui->name2=g_strdup(ep_address_to_str(addr2));
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -467,9 +525,9 @@ iousers_fddi_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, cons
                iui->next=iu->items;
                iu->items=iui;
                COPY_ADDRESS(&iui->addr1, addr1);
-               iui->name1=strdup(address_to_str(addr1));
+               iui->name1=g_strdup(ep_address_to_str(addr1));
                COPY_ADDRESS(&iui->addr2, addr2);
-               iui->name2=strdup(address_to_str(addr2));
+               iui->name2=g_strdup(ep_address_to_str(addr2));
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -515,9 +573,9 @@ iousers_tr_packet(void *arg, packet_info *pinfo, epan_dissect_t *edt _U_, const
                iui->next=iu->items;
                iu->items=iui;
                COPY_ADDRESS(&iui->addr1, addr1);
-               iui->name1=strdup(address_to_str(addr1));
+               iui->name1=g_strdup(ep_address_to_str(addr1));
                COPY_ADDRESS(&iui->addr2, addr2);
-               iui->name2=strdup(address_to_str(addr2));
+               iui->name2=g_strdup(ep_address_to_str(addr2));
                iui->frames1=0;
                iui->frames2=0;
                iui->bytes1=0;
@@ -564,7 +622,7 @@ iousers_draw(void *arg)
                        tot_frames=iui->frames1+iui->frames2;
 
                        if(tot_frames==last_frames){
-                               printf("%-20s <-> %-20s  %6d %9d  %6d %9d  %6d %9d\n",
+                               printf("%-20s <-> %-20s  %6d %9" G_GINT64_MODIFIER "d  %6d %9" G_GINT64_MODIFIER "d  %6d %9" G_GINT64_MODIFIER "d\n",
                                        iui->name1, iui->name2,
                                        iui->frames1, iui->bytes1,
                                        iui->frames2, iui->bytes2,
@@ -578,8 +636,8 @@ iousers_draw(void *arg)
        printf("================================================================================\n");
 }
 
-void
-iousers_init(const char *optarg)
+static void
+iousers_init(const char *optarg, void* userdata _U_)
 {
        const char *filter=NULL;
        const char *tap_type, *tap_type_name;
@@ -659,6 +717,15 @@ iousers_init(const char *optarg)
                tap_type="ip";
                tap_type_name="IPv4";
                packet_func=iousers_ip_packet;
+       } else if(!strncmp(optarg,"conv,ipv6",7)){
+               if(optarg[7]==','){
+                       filter=optarg+10;
+               } else {
+                       filter=NULL;
+               }
+               tap_type="ipv6";
+               tap_type_name="IPv6";
+               packet_func=iousers_ipv6_packet;
        } else if(!strncmp(optarg,"conv,sctp",9)) {
                if(optarg[9]==','){
                                filter=optarg+10;
@@ -669,7 +736,7 @@ iousers_init(const char *optarg)
                tap_type_name="SCTP";
                packet_func=iousers_sctp_packet;
        } else {
-               fprintf(stderr, "tethereal: invalid \"-z conv,<type>[,<filter>]\" argument\n");
+               fprintf(stderr, "tshark: invalid \"-z conv,<type>[,<filter>]\" argument\n");
                fprintf(stderr,"   <type> must be one of\n");
                fprintf(stderr,"      \"eth\"\n");
                fprintf(stderr,"      \"fc\"\n");
@@ -688,18 +755,18 @@ iousers_init(const char *optarg)
        iu->items=NULL;
        iu->type=tap_type_name;
        if(filter){
-               iu->filter=strdup(filter);
+               iu->filter=g_strdup(filter);
        } else {
                iu->filter=NULL;
        }
 
-       error_string=register_tap_listener(tap_type, iu, filter, NULL, packet_func, iousers_draw);
+       error_string=register_tap_listener(tap_type, iu, filter, 0, NULL, packet_func, iousers_draw);
        if(error_string){
                if(iu->items){
                        g_free(iu->items);
                }
                g_free(iu);
-               fprintf(stderr, "tethereal: Couldn't register conversations tap: %s\n",
+               fprintf(stderr, "tshark: Couldn't register conversations tap: %s\n",
                    error_string->str);
                g_string_free(error_string, TRUE);
                exit(1);
@@ -710,5 +777,5 @@ iousers_init(const char *optarg)
 void
 register_tap_listener_iousers(void)
 {
-       register_tap_listener_cmd_arg("conv,", iousers_init);
+       register_stat_cmd_arg("conv,", iousers_init, NULL);
 }