Don't use PCRE if we have GRegex.
[obnox/wireshark/wip.git] / tap-protocolinfo.c
index dfaea88099fbdef8dc676a142601d63d7077cf09..588f8fb77597c7ea26ff9e2de3b22dbb5239df87 100644 (file)
@@ -40,6 +40,7 @@
 #include "epan/proto.h"
 #include <epan/tap.h>
 #include <epan/stat_cmd_args.h>
+#include <epan/strutil.h>
 #include "register.h"
 
 typedef struct _pci_t {
@@ -63,11 +64,11 @@ protocolinfo_packet(void *prs, packet_info *pinfo, epan_dissect_t *edt, const vo
         * 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.
+        * To prevent a crash, we check whether INFO column is writable
+        * and, if not, we report that error and exit.
         */
-       if (pinfo->cinfo == NULL) {
-               fprintf(stderr, "tshark: the proto,colinfo tap doesn't work if the columns aren't being printed.\n");
+       if (!check_col(pinfo->cinfo, COL_INFO)) {
+               fprintf(stderr, "tshark: the proto,colinfo tap doesn't work if the INFO column isn't being printed.\n");
                exit(1);
        }
        gp=proto_get_finfo_ptr_array(edt->tree, rs->hf_index);
@@ -117,21 +118,18 @@ protocolinfo_init(const char *optarg, void* userdata _U_)
        rs->hf_index=hfi->id;
        if((field-filter)>1){
                rs->filter=g_malloc(field-filter);
-               strncpy(rs->filter,filter,(field-filter)-1);
-               rs->filter[(field-filter)-1]=0;
+               g_strlcpy(rs->filter,filter,(field-filter));
        } else {
                rs->filter=NULL;
        }
 
-       error_string=register_tap_listener("frame", rs, rs->filter, NULL, protocolinfo_packet, NULL);
+       error_string=register_tap_listener("frame", rs, rs->filter, TL_REQUIRES_PROTO_TREE, NULL, protocolinfo_packet, NULL);
        if(error_string){
                /* error, we failed to attach to the tap. complain and clean up */
                fprintf(stderr, "tshark: Couldn't register proto,colinfo tap: %s\n",
                    error_string->str);
                g_string_free(error_string, TRUE);
-               if(rs->filter){
-                       g_free(rs->filter);
-               }
+               g_free(rs->filter);
                g_free(rs);
 
                exit(1);