change a whole bunch of ethereal into wireshark
[obnox/wireshark/wip.git] / epan / dissectors / packet-cdp.c
index 1c3a1000968890dcbcf7b4d73fe455d12aa722f7..4e3630356c6e70ce53e0aab375ad17365c740727 100644 (file)
@@ -4,8 +4,8 @@
  *
  * $Id$
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
 #include <epan/packet.h>
 #include <epan/strutil.h>
 
-#include "oui.h"
-#include "nlpid.h"
+#include <epan/oui.h>
+#include <epan/nlpid.h>
 
 
 /*
  * See
  *
- *     http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
+ *     http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#xtocid12
  *
  * for some information on CDP.
  *
  * See
  *
- *     http://www.cisco.com/en/US/products/hw/switches/ps663/products_tech_note09186a0080094713.shtml
+ *     http://www.cisco.com/en/US/products/hw/switches/ps663/products_tech_note09186a0080094713.shtml#cdp
  *
  * for some more information on CDP version 2.
  */
@@ -87,11 +87,11 @@ add_multi_line_string_to_tree(proto_tree *tree, tvbuff_t *tvb, gint start,
 #define TYPE_VTP_MGMT_DOMAIN    0x0009 /* VTP Domain, CTPv2 - see second URL */
 #define TYPE_NATIVE_VLAN        0x000a /* Native VLAN, CTPv2 - see second URL */
 #define TYPE_DUPLEX             0x000b /* Full/Half Duplex - see second URL */
-/*                                     Somewhere in here there's a Power Draw TLV */
 /*                              0x000c */
 /*                              0x000d */
 #define TYPE_VOIP_VLAN_REPLY    0x000e /* VoIP VLAN reply */
 #define TYPE_VOIP_VLAN_QUERY    0x000f /* VoIP VLAN query */
+#define TYPE_POWER              0x0010 /* Power consumption */
 #define TYPE_MTU                0x0011 /* MTU */
 #define TYPE_TRUST_BITMAP       0x0012 /* Trust bitmap */
 #define TYPE_UNTRUSTED_COS      0x0013 /* Untrusted port CoS */
@@ -115,6 +115,7 @@ static const value_string type_vals[] = {
        { TYPE_DUPLEX,          "Duplex" },
        { TYPE_VOIP_VLAN_REPLY, "VoIP VLAN Reply" },
        { TYPE_VOIP_VLAN_QUERY, "VoIP VLAN Query" },
+       { TYPE_POWER,           "Power consumption" },
        { TYPE_MTU,             "MTU"},
        { TYPE_TRUST_BITMAP,    "Trust Bitmap" },
        { TYPE_UNTRUSTED_COS,   "Untrusted Port CoS" },
@@ -159,10 +160,10 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        /* CDP header */
        proto_tree_add_item(cdp_tree, hf_cdp_version, tvb, offset, 1, FALSE);
        offset += 1;
-       proto_tree_add_uint_format(cdp_tree, hf_cdp_ttl, tvb, offset, 1,
-                                  tvb_get_guint8(tvb, offset),
-                                  "TTL: %u seconds",
-                                  tvb_get_guint8(tvb, offset));
+       proto_tree_add_uint_format_value(cdp_tree, hf_cdp_ttl, tvb, offset, 1,
+                                        tvb_get_guint8(tvb, offset),
+                                        "%u seconds",
+                                        tvb_get_guint8(tvb, offset));
        offset += 1;
        proto_tree_add_item(cdp_tree, hf_cdp_checksum, tvb, offset, 2, FALSE);
        offset += 2;
@@ -360,10 +361,10 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                /*              proto_tree_add_text(tlv_tree, tvb, offset+9,
                                    length - 9, "Cluster Management");
                */
-               tvb_memcpy(tvb, (guint8 *)&ip_addr, offset+9, 4);
+               ip_addr = tvb_get_ipv4(tvb, offset+9);
                proto_tree_add_text(tlv_tree, tvb, offset+9, 4,
                                    "Cluster Master IP: %s",ip_to_str((guint8 *)&ip_addr));
-               tvb_memcpy(tvb, (guint8 *)&ip_addr, offset+13, 4);
+               ip_addr = tvb_get_ipv4(tvb, offset+13);
                proto_tree_add_text(tlv_tree, tvb, offset+13, 4,
                                    "UNKNOWN (IP?): 0x%08X (%s)",
                                    ip_addr, ip_to_str((guint8 *)&ip_addr));
@@ -444,29 +445,77 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                offset += length;
                break;
            case TYPE_VOIP_VLAN_REPLY:
-             tlvi = proto_tree_add_text(cdp_tree, tvb,
-                                        offset, length, "VoIP VLAN Reply");
+             if (length >= 7) {
+               tlvi = proto_tree_add_text(cdp_tree, tvb,
+                                          offset, length, "VoIP VLAN Reply: %u", tvb_get_ntohs(tvb, offset + 5));
+             } else {
+               /*
+                * XXX - what are these?  I've seen them in some captures;
+                * they have a length of 6, and run up to the end of
+                * the packet, so if we try to dissect it the same way
+                * we dissect the 7-byte ones, we report a malformed
+                * frame.
+                */
+               tlvi = proto_tree_add_text(cdp_tree, tvb,
+                                          offset, length, "VoIP VLAN Reply");
+             }
              tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
              proto_tree_add_uint(tlv_tree, hf_cdp_tlvtype, tvb,
                                  offset + TLV_TYPE, 2, type);
              proto_tree_add_uint(tlv_tree, hf_cdp_tlvlength, tvb,
                                  offset + TLV_LENGTH, 2, length);
              proto_tree_add_text(tlv_tree, tvb, offset + 4,
-                                 length - 4, "Data");
+                                 1, "Data");
+             if (length >= 7) {
+               proto_tree_add_text(tlv_tree, tvb, offset + 5,
+                                   2, "Voice VLAN: %u",
+                                   tvb_get_ntohs(tvb, offset + 5));
+             }
              offset += length;
              break;
            case TYPE_VOIP_VLAN_QUERY:
-             tlvi = proto_tree_add_text(cdp_tree, tvb,
-                                        offset, length, "VoIP VLAN Query");
+             if (length >= 7) {
+               tlvi = proto_tree_add_text(cdp_tree, tvb,
+                                          offset, length, "VoIP VLAN Query: %u", tvb_get_ntohs(tvb, offset + 5));
+             } else {
+               /*
+                * XXX - what are these?  I've seen them in some captures;
+                * they have a length of 6, and run up to the end of
+                * the packet, so if we try to dissect it the same way
+                * we dissect the 7-byte ones, we report a malformed
+                * frame.
+                */
+               tlvi = proto_tree_add_text(cdp_tree, tvb,
+                                          offset, length, "VoIP VLAN Query");
+             }
              tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
              proto_tree_add_uint(tlv_tree, hf_cdp_tlvtype, tvb,
                                  offset + TLV_TYPE, 2, type);
              proto_tree_add_uint(tlv_tree, hf_cdp_tlvlength, tvb,
                                  offset + TLV_LENGTH, 2, length);
              proto_tree_add_text(tlv_tree, tvb, offset + 4,
-                                 length - 4, "Data");
+                                 1, "Data");
+             if (length >= 7) {
+               proto_tree_add_text(tlv_tree, tvb, offset + 5,
+                                   2, "Voice VLAN: %u",
+                                   tvb_get_ntohs(tvb, offset + 5));
+             }
              offset += length;
              break;
+           case TYPE_POWER:
+               tlvi = proto_tree_add_text(cdp_tree, tvb,
+                           offset, length, "Power consumption: %u mW",
+                                          tvb_get_ntohs(tvb, offset + 4));
+               tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
+               proto_tree_add_uint(tlv_tree, hf_cdp_tlvtype, tvb,
+                           offset + TLV_TYPE, 2, type);
+               proto_tree_add_uint(tlv_tree, hf_cdp_tlvlength, tvb,
+                           offset + TLV_LENGTH, 2, length);
+               proto_tree_add_text(tlv_tree, tvb, offset + 4,
+                           length - 4, "Power consumption: %u mW",
+                                   tvb_get_ntohs(tvb, offset + 4));
+               offset += length;
+               break;
            case TYPE_MTU:
              tlvi = proto_tree_add_text(cdp_tree, tvb,
                                         offset, length, "MTU: %u",
@@ -620,9 +669,9 @@ dissect_address_tlv(tvbuff_t *tvb, int offset, int length, proto_tree *tree)
     guint8 protocol_type;
     guint8 protocol_length;
     int nlpid;
-    char *protocol_str;
+    const char *protocol_str;
     guint16 address_length;
-    char *address_type_str;
+    const char *address_type_str;
     char *address_str;
 
     if (length < 1)