Don't guard col_set_str (COL_PROTOCOL) with col_check
[obnox/wireshark/wip.git] / epan / dissectors / packet-fcoe.c
index 6ce4bc6ffdbc0f54ac939555856d72ca8dfbb728..11b60ebf581beb606be35dc241d58e156e04e249 100644 (file)
@@ -6,7 +6,7 @@
  * $Id$
  *
  * Wireshark - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * Based on packet-fcip.c, Copyright 2001, Dinesh G Dutt (ddutt@cisco.com)
@@ -95,8 +95,6 @@ static const value_string fcoe_sof_vals[] = {
     {0, NULL}
 };
 
-void proto_reg_handoff_fcoe(void);
-
 static int proto_fcoe          = -1;
 static int hf_fcoe_ver         = -1;
 static int hf_fcoe_len         = -1;
@@ -120,14 +118,14 @@ dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     gint frame_len = 0;
     gint header_len = FCOE_HEADER_LEN;
     guint version;
-    char *ver;
+    const char *ver;
     guint16  len_sof;
-    gint bytes_remaining = tvb_length(tvb);
+    gint bytes_remaining;
     guint8 sof = 0;
     guint8 eof = 0;
     const char *eof_str;
-    char *crc_msg;
-    char *len_msg;
+    const char *crc_msg;
+    const char *len_msg;
     proto_item *ti;
     proto_item *item;
     proto_tree *fcoe_tree = NULL;
@@ -150,13 +148,11 @@ dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         sof |= (sof < 8) ? 0x30 : 0x20;
         version = len_sof >> 14;
         ver = "pre-T11 ";
-        if (version != 0) {
-            int ver_buf_len = 24;
-            ver = ep_alloc(ver_buf_len);
-            g_snprintf(ver, ver_buf_len, "pre-T11 ver %d ", version);
-        }
+        if (version != 0)
+            ver = ep_strdup_printf(ver, "pre-T11 ver %d ", version);
     } else {
-        frame_len = bytes_remaining - FCOE_HEADER_LEN - FCOE_TRAILER_LEN;
+        frame_len = tvb_reported_length_remaining(tvb, 0) -
+          FCOE_HEADER_LEN - FCOE_TRAILER_LEN;
         sof = tvb_get_guint8(tvb, FCOE_HEADER_LEN - 1);
 
         /*
@@ -165,19 +161,16 @@ dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
          */
         ver = "";
         version = tvb_get_guint8(tvb, 0) >> 4;
-        if (version != 0) {
-            int ver_buf_len = 16;
-            ver = ep_alloc(ver_buf_len);
-            g_snprintf(ver, ver_buf_len, "ver %d ", version);
-        }
+        if (version != 0)
+            ver = ep_strdup_printf(ver, "ver %d ", version);
     }
-    if (frame_len < 0)
-        return;
-    if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
-        col_set_str(pinfo->cinfo, COL_PROTOCOL, "FCoE");
+    col_set_str(pinfo->cinfo, COL_PROTOCOL, "FCoE");
     crc_offset = header_len + frame_len;
     eof_offset = crc_offset + 4;
-    next_tvb = tvb_new_subset(tvb, header_len, frame_len, frame_len);
+    bytes_remaining = tvb_length_remaining(tvb, header_len);
+    if (bytes_remaining > frame_len)
+        bytes_remaining = frame_len;        /* backing length */
+    next_tvb = tvb_new_subset(tvb, header_len, bytes_remaining, frame_len);
     
     if (tree) {
 
@@ -225,7 +218,6 @@ dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         /*
          * Create the CRC information.
          */
-        item = ti;
         if (crc_exists) {
             if (crc == crc_computed) {
                 item = proto_tree_add_uint_format(fcoe_tree, hf_fcoe_crc, tvb,
@@ -241,6 +233,11 @@ dissect_fcoe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                        "Bad FC CRC %8.8x %8.x",
                                        crc, crc_computed);
             }
+            proto_tree_set_appendix(fcoe_tree, tvb, crc_offset, 
+                                    tvb_length_remaining (tvb, crc_offset));
+        } else {
+            item = proto_tree_add_text(fcoe_tree, tvb, crc_offset, 0, 
+                                       "CRC: [missing]");
         }
         crc_tree = proto_item_add_subtree(item, ett_fcoe_crc);
         ti = proto_tree_add_boolean(crc_tree, hf_fcoe_crc_bad, tvb,
@@ -292,25 +289,23 @@ proto_register_fcoe(void)
     static hf_register_info hf[] = {
         { &hf_fcoe_sof,
           {"SOF", "fcoe.sof", FT_UINT8, BASE_HEX, VALS(&fcoe_sof_vals), 0,
-           "", HFILL}},
+           NULL, HFILL}},
         { &hf_fcoe_eof,
           {"EOF", "fcoe.eof", FT_UINT8, BASE_HEX, VALS(&fcoe_eof_vals), 0,
-           "", HFILL}},
+           NULL, HFILL}},
         { &hf_fcoe_ver,
-          {"Version", "fcoe.ver", FT_UINT32, BASE_DEC, NULL, 0, "", HFILL}},
+          {"Version", "fcoe.ver", FT_UINT32, BASE_DEC, NULL, 0, NULL, HFILL}},
         { &hf_fcoe_len,
           {"Frame length", "fcoe.len", FT_UINT32,
-            BASE_DEC, NULL, 0, "", HFILL}},
+            BASE_DEC, NULL, 0, NULL, HFILL}},
         { &hf_fcoe_crc,
-          {"CRC", "fcoe.crc", FT_UINT32, BASE_HEX, NULL, 0, "", HFILL}},
+          {"CRC", "fcoe.crc", FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL}},
         { &hf_fcoe_crc_good,
-          {"CRC good", "fcoe.crc_good", FT_BOOLEAN, BASE_NONE, NULL, 0,
-            "True: CRC matches packet content; "
-            "False: doesn't match or not checked.", HFILL }},
+          {"CRC good", "fcoe.crc_good", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+            "True: CRC matches packet content; False: doesn't match or not checked.", HFILL }},
         { &hf_fcoe_crc_bad,
-          {"CRC bad", "fcoe.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0,
-            "True: CRC doesn't match packet content; "
-            "False: matches or not checked.", HFILL }}
+          {"CRC bad", "fcoe.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+            "True: CRC doesn't match packet content; False: matches or not checked.", HFILL }}
     };
     static gint *ett[] = {
         &ett_fcoe,
@@ -326,7 +321,7 @@ proto_register_fcoe(void)
     proto_register_field_array(proto_fcoe, hf, array_length(hf));
     proto_register_subtree_array(ett, array_length(ett));
 
-    fcoe_module = prefs_register_protocol(proto_fcoe, proto_reg_handoff_fcoe);
+    fcoe_module = prefs_register_protocol(proto_fcoe, NULL);
 
     prefs_register_obsolete_preference(fcoe_module, "ethertype");
 }