Stuart Stanley's ISIS dissection support.
[obnox/wireshark/wip.git] / packet-cdp.c
index 29dd383672032ed02a30e6469ad3755609a81007..95a826953cbf85e057959c292c847e9e5f625d86 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for the disassembly of the "Cisco Discovery Protocol"
  * (c) Copyright Hannes R. Boehm <hannes@boehm.org>
  *
- * $Id: packet-cdp.c,v 1.14 1999/09/17 05:56:53 guy Exp $
+ * $Id: packet-cdp.c,v 1.17 1999/11/16 11:42:28 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #define        TLV_LENGTH      2
 
 static int proto_cdp = -1;
+static int hf_cdp_version = -1;
+static int hf_cdp_flags = -1;
+static int hf_cdp_ttl = -1;
 static int hf_cdp_tlvtype = -1;
 static int hf_cdp_tlvlength = -1;
 
+static gint ett_cdp = -1;
+static gint ett_cdp_tlv = -1;
+
 static void
 add_multi_line_string_to_tree(proto_tree *tree, gint start, gint len,
   const gchar *prefix, const gchar *string);
@@ -85,16 +91,18 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
 
     if(tree){
         ti = proto_tree_add_item(tree, proto_cdp, offset, END_OF_FRAME, NULL);
-       cdp_tree = proto_item_add_subtree(ti, ETT_CDP);
+       cdp_tree = proto_item_add_subtree(ti, ett_cdp);
        
        /* CDP header */
-       proto_tree_add_text(cdp_tree, offset, 1, "Version: %u", pd[offset]);
+       proto_tree_add_item(cdp_tree, hf_cdp_version, offset, 1, pd[offset]);
        offset += 1;
-       proto_tree_add_text(cdp_tree, offset, 1, "Flags: %x (unknown)",
-           pd[offset]);
+       proto_tree_add_item_format(cdp_tree, hf_cdp_flags, offset, 1,
+                                  pd[offset], 
+                                  "Flags: %x (unknown)", pd[offset]);
        offset += 1;
-       proto_tree_add_text(cdp_tree, offset, 2, "TTL: %u (unknown)",
-           pntohs(&pd[offset]));
+       proto_tree_add_item_format(cdp_tree, hf_cdp_ttl, offset, 2, 
+                                  pntohs(&pd[offset]),
+                                  "TTL: %u (unknown)", pntohs(&pd[offset]));
        offset += 2;
 
        while( IS_DATA_IN_FRAME(offset) ){
@@ -112,7 +120,7 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                                    length + 4, "Type: %s, length: %u",
                                    type_str, length);
                                tlv_tree = proto_item_add_subtree(tlvi,
-                                   ETT_CDP_TLV);
+                                   ett_cdp_tlv);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvtype,
                                    offset + TLV_TYPE, 2, type);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvlength,
@@ -129,7 +137,7 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                                    length, "Chassis ID: %s",
                                    &pd[offset+4]);
                                tlv_tree = proto_item_add_subtree(tlvi,
-                                   ETT_CDP_TLV);
+                                   ett_cdp_tlv);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvtype,
                                    offset + TLV_TYPE, 2, type);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvlength,
@@ -148,7 +156,7 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                                    4, "Type: %u (unknown), second field: %u",
                                    type, length);
                                tlv_tree = proto_item_add_subtree(tlvi,
-                                   ETT_CDP_TLV);
+                                   ett_cdp_tlv);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvtype,
                                    offset + TLV_TYPE, 2, type);
                                proto_tree_add_text(tlv_tree,
@@ -162,7 +170,7 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                                    length, "Sent through Interface: %s",
                                    &pd[offset+4]);
                                tlv_tree = proto_item_add_subtree(tlvi,
-                                   ETT_CDP_TLV);
+                                   ett_cdp_tlv);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvtype,
                                    offset + TLV_TYPE, 2, type);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvlength,
@@ -188,7 +196,7 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                                    offset, length, "Platform: %s",
                                    stringmem);
                                tlv_tree = proto_item_add_subtree(tlvi,
-                                   ETT_CDP_TLV);
+                                   ett_cdp_tlv);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvtype,
                                    offset + TLV_TYPE, 2, type);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvlength,
@@ -206,7 +214,7 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                                    offset, length + 4, "Mgmt IP: %s",
                                    ip_to_str(&pd[offset+4]));
                                tlv_tree = proto_item_add_subtree(tlvi,
-                                   ETT_CDP_TLV);
+                                   ett_cdp_tlv);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvtype,
                                    offset + TLV_TYPE, 2, type);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvlength,
@@ -221,7 +229,7 @@ dissect_cdp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
                                    length, "Type: %s, length: %u",
                                    type_str, length);
                                tlv_tree = proto_item_add_subtree(tlvi,
-                                   ETT_CDP_TLV);
+                                   ett_cdp_tlv);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvtype,
                                    offset + TLV_TYPE, 2, type);
                                proto_tree_add_item(tlv_tree, hf_cdp_tlvlength,
@@ -279,13 +287,32 @@ void
 proto_register_cdp(void)
 {
         static hf_register_info hf[] = {
+                { &hf_cdp_version,
+                { "Version",           "cdp.version",  FT_UINT8, BASE_DEC, NULL, 0x0,
+                       "" }},
+
+                { &hf_cdp_flags,
+                { "Flags",             "cdp.flags", FT_UINT8, BASE_HEX, NULL, 0x0,
+                       "" }},
+
+                { &hf_cdp_ttl,
+                { "TTL",               "cdp.ttl", FT_UINT16, BASE_DEC, NULL, 0x0,
+                       "" }},
+
                 { &hf_cdp_tlvtype,
-                { "Type",              "cdp.tlv.type", FT_VALS_UINT16, VALS(type_vals) }},
+                { "Type",              "cdp.tlv.type", FT_UINT16, BASE_HEX, VALS(type_vals), 0x0,
+                       "" }},
 
                 { &hf_cdp_tlvlength,
-                { "Length",            "cdp.tlv.len", FT_UINT16, NULL }},
+                { "Length",            "cdp.tlv.len", FT_UINT16, BASE_DEC, NULL, 0x0,
+                       "" }},
         };
+       static gint *ett[] = {
+               &ett_cdp,
+               &ett_cdp_tlv,
+       };
 
         proto_cdp = proto_register_protocol("Cisco Discovery Protocol", "cdp");
         proto_register_field_array(proto_cdp, hf, array_length(hf));
+       proto_register_subtree_array(ett, array_length(ett));
 }