Add a "contains" operator for byte-strings, strings, and tvbuffs (protocols).
[obnox/wireshark/wip.git] / packet-trmac.c
index 066a4fa558a40fbc07f096fc3125cefa2b4d0de6..0d15d53edddd20e9cf142fa831bba89e6b7d137b 100644 (file)
@@ -1,24 +1,23 @@
 /* packet-trmac.c
  * Routines for Token-Ring Media Access Control
- * Gilbert Ramirez <gram@xiexie.org>
+ * Gilbert Ramirez <gram@alumni.rice.edu>
  *
- * $Id: packet-trmac.c,v 1.25 2000/11/17 21:00:36 gram Exp $
+ * $Id: packet-trmac.c,v 1.38 2002/08/28 21:00:36 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * 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 "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
 #include <string.h>
 #include <glib.h>
-#include "packet.h"
+#include <epan/packet.h>
+#include "packet-frame.h"
 
 static int proto_trmac = -1;
 static int hf_trmac_mv = -1;
@@ -114,7 +110,16 @@ sv_text(tvbuff_t *tvb, int svoff, proto_tree *tree)
        proto_tree      *sv_tree;
        proto_item      *ti;
 
-       u_char          errors[6];      /* isolating or non-isolating */
+       guchar          errors[6];      /* isolating or non-isolating */
+
+       /* Check the SV length.
+          XXX - Should we do this in each case statement below, e.g. to force
+          an SV length of 6 for the NAUN address? */
+       if (sv_length < 1) {
+               proto_tree_add_protocol_format(tree, proto_malformed, tvb, svoff+0, 1,
+                       "Invalid subvector length: %d bytes", sv_length);
+               return sv_length;
+       }
 
        /* this just adds to the clutter on the screen...
        proto_tree_add_text(tree, tvb, svoff, 1,
@@ -135,7 +140,7 @@ sv_text(tvbuff_t *tvb, int svoff, proto_tree *tree)
                        break;
 
                case 0x02: /* NAUN */
-                       proto_tree_add_ether(tree, hf_trmac_naun, tvb, svoff+1, sv_length-1, 
+                       proto_tree_add_ether(tree, hf_trmac_naun, tvb, svoff+1, sv_length-1,
                                        tvb_get_ptr(tvb, svoff+2, 6));
                        break;
 
@@ -271,7 +276,7 @@ sv_text(tvbuff_t *tvb, int svoff, proto_tree *tree)
        return sv_length;
 }
 
-void
+static void
 dissect_trmac(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
        proto_tree      *mac_tree = NULL;
@@ -280,19 +285,18 @@ dissect_trmac(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        guint8          mv_val;
        char            *mv_text;
 
-       CHECK_DISPLAY_AS_DATA(proto_trmac, tvb, pinfo, tree);
-
-       pinfo->current_proto = "TR MAC";
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_add_str(pinfo->fd, COL_PROTOCOL, "TR MAC");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "TR MAC");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_clear(pinfo->cinfo, COL_INFO);
 
        mv_val = tvb_get_guint8(tvb, 3);
 
        /* Interpret the major vector */
        mv_text = val_to_str(mv_val, major_vector_vs, "Unknown Major Vector: %d\n");
 
-       if (check_col(pinfo->fd, COL_INFO))
-               col_add_str(pinfo->fd, COL_INFO, mv_text);
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_add_str(pinfo->cinfo, COL_INFO, mv_text);
 
        if (tree) {
                mv_length = tvb_get_ntohs(tvb, 0);
@@ -326,75 +330,75 @@ proto_register_trmac(void)
         static hf_register_info hf[] = {
                 { &hf_trmac_mv,
                 { "Major Vector",                      "trmac.mvec", FT_UINT8, BASE_HEX, major_vector_vs, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                 { &hf_trmac_length,
                 { "Total Length",                      "trmac.length", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                 { &hf_trmac_srcclass,
                 { "Source Class",                      "trmac.srcclass", FT_UINT8, BASE_HEX, classes_vs, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                 { &hf_trmac_dstclass,
                 { "Destination Class",                 "trmac.dstclass", FT_UINT8, BASE_HEX, classes_vs, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                 { &hf_trmac_sv,
                 { "Sub-Vector",                                "trmac.svec", FT_UINT8, BASE_HEX, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_iso,
                { "Isolating Errors",                   "trmac.errors.iso", FT_UINT16, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_line,
                { "Line Errors",                        "trmac.errors.line", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_internal,
                { "Internal Errors",                    "trmac.errors.internal", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_burst,
                { "Burst Errors",                       "trmac.errors.burst", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_ac,
                { "A/C Errors",                         "trmac.errors.ac", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_abort,
                { "Abort Delimiter Transmitted Errors", "trmac.errors.abort", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_noniso,
                { "Non-Isolating Errors",               "trmac.errors.noniso", FT_UINT16, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_lost,
                { "Lost Frame Errors",                  "trmac.errors.lost", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_congestion,
                { "Receiver Congestion Errors",         "trmac.errors.congestion", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_fc,
                { "Frame-Copied Errors",                "trmac.errors.fc", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_freq,
                { "Frequency Errors",                   "trmac.errors.freq", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_errors_token,
                { "Token Errors",                       "trmac.errors.token", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_trmac_naun,
                { "NAUN",                               "trmac.naun", FT_ETHER, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
         };
        static gint *ett[] = {
                &ett_tr_mac,
@@ -402,7 +406,10 @@ proto_register_trmac(void)
                &ett_tr_nerr_cnt,
        };
 
-        proto_trmac = proto_register_protocol("Token-Ring Media Access Control", "trmac");
+        proto_trmac = proto_register_protocol("Token-Ring Media Access Control",
+           "TR MAC", "trmac");
        proto_register_field_array(proto_trmac, hf, array_length(hf));
        proto_register_subtree_array(ett, array_length(ett));
+
+       register_dissector("trmac", dissect_trmac, proto_trmac);
 }