replace *a lot* of file related calls by their GLib counterparts. This is necessary...
[obnox/wireshark/wip.git] / tap-protohierstat.c
index ba2c0bf2e9ef3167f29cb9b89c1eb30a7ed69229..7b79a70a8bf1e0a50914d79c4760373e4dad8353 100644 (file)
@@ -1,7 +1,7 @@
 /* tap-protohierstat.c
  * protohierstat   2002 Ronnie Sahlberg
  *
- * $Id: tap-protohierstat.c,v 1.4 2003/11/24 22:11:53 guy Exp $
+ * $Id$
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -38,7 +38,8 @@
 #include "epan/packet_info.h"
 #include "epan/epan_dissect.h"
 #include "epan/proto.h"
-#include "tap.h"
+#include <epan/tap.h>
+#include <epan/stat_cmd_args.h>
 #include "register.h"
 
 typedef struct _phs_t {
@@ -47,7 +48,7 @@ typedef struct _phs_t {
        struct _phs_t *parent;
        char *filter;
        int protocol;
-       char *proto_name;
+       const char *proto_name;
        guint32 frames;
        guint32 bytes;
 } phs_t;
@@ -71,7 +72,7 @@ new_phs_t(phs_t *parent)
 
 
 static int
-protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *dummy _U_)
+protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_)
 {
        phs_t *rs=prs;
        phs_t *tmprs;
@@ -84,17 +85,17 @@ protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *d
        if(!edt->tree){
                return 0;
        }
-       if(!edt->tree->children){
+       if(!edt->tree->first_child){
                return 0;
        }
 
-       for(tree=edt->tree->children;tree;tree=tree->next){
+       for(tree=edt->tree->first_child;tree;tree=tree->next){
                fi=PITEM_FINFO(tree);
 
                /* first time we saw a protocol at this leaf */
                if(rs->protocol==-1){
-                       rs->protocol=fi->ptr_u.hfinfo->id;
-                       rs->proto_name=fi->ptr_u.hfinfo->abbrev;
+                       rs->protocol=fi->hfinfo->id;
+                       rs->proto_name=fi->hfinfo->abbrev;
                        rs->frames=1;
                        rs->bytes=pinfo->fd->pkt_len;
                        rs->child=new_phs_t(rs);
@@ -104,7 +105,7 @@ protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *d
 
                /* find this protocol in the list of siblings */
                for(tmprs=rs;tmprs;tmprs=tmprs->sibling){
-                       if(tmprs->protocol==fi->ptr_u.hfinfo->id){
+                       if(tmprs->protocol==fi->hfinfo->id){
                                break;
                        }
                }
@@ -115,8 +116,8 @@ protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *d
                                ;
                        tmprs->sibling=new_phs_t(rs->parent);
                        rs=tmprs->sibling;
-                       rs->protocol=fi->ptr_u.hfinfo->id;
-                       rs->proto_name=fi->ptr_u.hfinfo->abbrev;
+                       rs->protocol=fi->hfinfo->id;
+                       rs->proto_name=fi->hfinfo->abbrev;
                } else {
                        rs=tmprs;
                }
@@ -135,17 +136,23 @@ protohierstat_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *d
 static void
 phs_draw(phs_t *rs, int indentation)
 {
-       int i;
-       char str[80];
+       int i, stroff;
+#define MAXPHSLINE 80
+       char str[MAXPHSLINE];
        for(;rs;rs=rs->sibling){
                if(rs->protocol==-1){
                        return;
                }
                str[0]=0;
+               stroff=0;
                for(i=0;i<indentation;i++){
-                       strcat(str,"  ");
+                       if(i>15){
+                               stroff+=g_snprintf(str+stroff, MAXPHSLINE-stroff, "...");
+                               break;
+                       }
+                       stroff+=g_snprintf(str+stroff, MAXPHSLINE-stroff, "  ");
                }
-               strcat(str, rs->proto_name);
+               stroff+=g_snprintf(str+stroff, MAXPHSLINE-stroff, rs->proto_name);
                printf("%-40s frames:%d bytes:%d\n",str, rs->frames, rs->bytes);
                phs_draw(rs->child, indentation+1);
        }
@@ -166,11 +173,11 @@ protohierstat_draw(void *prs)
 
 
 static void
-protohierstat_init(char *optarg)
+protohierstat_init(const char *optarg)
 {
        phs_t *rs;
        int pos=0;
-       char *filter=NULL;
+       const char *filter=NULL;
        GString *error_string;
 
        if(!strcmp("io,phs",optarg)){
@@ -216,6 +223,6 @@ protohierstat_init(char *optarg)
 void
 register_tap_listener_protohierstat(void)
 {
-       register_ethereal_tap("io,phs", protohierstat_init);
+       register_stat_cmd_arg("io,phs", protohierstat_init);
 }