replace *a lot* of file related calls by their GLib counterparts. This is necessary...
[obnox/wireshark/wip.git] / tap-protocolinfo.c
index c2025a3ae8fe931b44845e7ceaa93fab04493ae9..909ac8c240d6c9d9a3f6a73fc91487e9eb3acb93 100644 (file)
@@ -1,7 +1,7 @@
 /* tap-protocolinfo.c
  * protohierstat   2002 Ronnie Sahlberg
  *
- * $Id: tap-protocolinfo.c,v 1.3 2003/04/23 08:20:01 guy Exp $
+ * $Id$
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -38,7 +38,8 @@
 #include "epan/epan_dissect.h"
 #include "epan/column-utils.h"
 #include "epan/proto.h"
-#include "tap.h"
+#include <epan/tap.h>
+#include <epan/stat_cmd_args.h>
 #include "register.h"
 
 typedef struct _pci_t {
@@ -48,22 +49,37 @@ typedef struct _pci_t {
 
 
 static int
-protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *dummy _U_)
+protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const void *dummy _U_)
 {
        pci_t *rs=prs;
        GPtrArray *gp;
        guint i;
        char *str;
 
+       /*
+        * XXX - there needs to be a way for "protocolinfo_init()" to
+        * find out whether the columns are being generated and, if not,
+        * to report an error and exit, as the whole point of this tap
+        * is to modify the columns, and if the columns aren't being
+        * displayed, that makes this tap somewhat pointless.
+        *
+        * To prevent a crash, we check whether pinfo->cinfo is null
+        * and, if so, we report that error and exit.
+        */
+       if (pinfo->cinfo == NULL) {
+               fprintf(stderr, "tethereal: the proto,colinfo tap doesn't work if the columns aren't being printed.\n");
+               exit(1);
+       }
        gp=proto_get_finfo_ptr_array(edt->tree, rs->hf_index);
        if(!gp){
                return 0;
        }
 
        for(i=0;i<gp->len;i++){
-               str=proto_alloc_dfilter_string(gp->pdata[i], NULL);
-               col_append_fstr(pinfo->cinfo, COL_INFO, "  %s",str);
-               g_free(str);
+               str=proto_construct_dfilter_string(gp->pdata[i], NULL);
+               if(str){
+                       col_append_fstr(pinfo->cinfo, COL_INFO, "  %s",str);
+               }
        }
        return 0;
 }
@@ -71,11 +87,11 @@ protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, void *du
 
 
 static void
-protocolinfo_init(char *optarg)
+protocolinfo_init(const char *optarg)
 {
        pci_t *rs;
-       char *field=NULL;
-       char *filter=NULL;
+       const char *field=NULL;
+       const char *filter=NULL;
        header_field_info *hfi;
        GString *error_string;
 
@@ -93,7 +109,7 @@ protocolinfo_init(char *optarg)
 
        hfi=proto_registrar_get_byname(field);
        if(!hfi){
-               fprintf(stderr, "tethereal: Field \"%s\" does not exist.\n", field);
+               fprintf(stderr, "tethereal: Field \"%s\" doesn't exist.\n", field);
                exit(1);
        }
 
@@ -126,6 +142,6 @@ protocolinfo_init(char *optarg)
 void
 register_tap_listener_protocolinfo(void)
 {
-       register_ethereal_tap("proto,colinfo,", protocolinfo_init);
+       register_stat_cmd_arg("proto,colinfo,", protocolinfo_init);
 }