forked from osmocom/wireshark
Rewrote some "if(tree)" code inside a switch-case to avoid unused code
(which did not work as expected). switch(type) { case 1: ... break; if(tree) { case 2: ... break; } } svn path=/trunk/; revision=24284
This commit is contained in:
parent
ad5e6ad06b
commit
64d9306f29
|
@ -122,7 +122,6 @@ static const value_string type_vals[] = {
|
|||
{ TYPE_VTP_MGMT_DOMAIN, "VTP Management Domain" },
|
||||
{ TYPE_NATIVE_VLAN, "Native VLAN" },
|
||||
{ TYPE_DUPLEX, "Duplex" },
|
||||
|
||||
{ TYPE_VOIP_VLAN_REPLY, "VoIP VLAN Reply" },
|
||||
{ TYPE_VOIP_VLAN_QUERY, "VoIP VLAN Query" },
|
||||
{ TYPE_POWER, "Power consumption" },
|
||||
|
@ -156,8 +155,8 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
guint16 type;
|
||||
guint16 length, packet_checksum, computed_checksum, data_length;
|
||||
gboolean checksum_good, checksum_bad;
|
||||
proto_item *tlvi;
|
||||
proto_tree *tlv_tree;
|
||||
proto_item *tlvi = NULL;
|
||||
proto_tree *tlv_tree = NULL;
|
||||
int real_length;
|
||||
guint32 naddresses;
|
||||
guint32 power_avail_len, power_avail;
|
||||
|
@ -301,9 +300,9 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
offset += real_length;
|
||||
break;
|
||||
|
||||
if(tree){
|
||||
case TYPE_ADDRESS:
|
||||
/* Addresses */
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb, offset,
|
||||
length, "Addresses");
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
|
||||
|
@ -311,11 +310,14 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_cdp_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
}
|
||||
offset += 4;
|
||||
length -= 4;
|
||||
naddresses = tvb_get_ntohl(tvb, offset);
|
||||
if (tree) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset, 4,
|
||||
"Number of addresses: %u", naddresses);
|
||||
}
|
||||
offset += 4;
|
||||
length -= 4;
|
||||
while (naddresses != 0) {
|
||||
|
@ -332,6 +334,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
break;
|
||||
|
||||
case TYPE_CAPABILITIES:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb, offset,
|
||||
length, "Capabilities");
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
|
||||
|
@ -339,6 +342,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_cdp_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
}
|
||||
offset += 4;
|
||||
length -= 4;
|
||||
dissect_capabilities(tvb, offset, length, tlv_tree);
|
||||
|
@ -346,6 +350,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
break;
|
||||
|
||||
case TYPE_IOS_VERSION:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb, offset,
|
||||
length, "Software Version");
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
|
||||
|
@ -355,11 +360,13 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
offset + TLV_LENGTH, 2, length);
|
||||
add_multi_line_string_to_tree(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Software Version: ");
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_PLATFORM:
|
||||
/* ??? platform */
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Platform: %s",
|
||||
tvb_format_text(tvb, offset + 4, length - 4));
|
||||
|
@ -371,12 +378,14 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Platform: %s",
|
||||
tvb_format_text(tvb, offset + 4, length - 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_IP_PREFIX:
|
||||
if (length == 8) {
|
||||
/* if length is 8 then this is default gw not prefix */
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb, offset,
|
||||
length, "ODR Default gateway: %s",
|
||||
ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
|
||||
|
@ -388,8 +397,10 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset+4, 4,
|
||||
"ODR Default gateway = %s",
|
||||
ip_to_str(tvb_get_ptr(tvb, offset+4, 4)));
|
||||
}
|
||||
offset += 8;
|
||||
} else {
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb, offset,
|
||||
length, "IP Prefixes: %d",length/5);
|
||||
|
||||
|
@ -402,13 +413,16 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_cdp_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
}
|
||||
offset += 4;
|
||||
length -= 4;
|
||||
while (length > 0) {
|
||||
if (tree) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset, 5,
|
||||
"IP Prefix = %s/%u",
|
||||
ip_to_str(tvb_get_ptr(tvb, offset, 4)),
|
||||
tvb_get_guint8(tvb,offset+4));
|
||||
}
|
||||
offset += 5;
|
||||
length -= 5;
|
||||
}
|
||||
|
@ -416,6 +430,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
break;
|
||||
|
||||
case TYPE_PROTOCOL_HELLO:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset,length, "Protocol Hello: %s",
|
||||
val_to_str(tvb_get_ntohs(tvb, offset+7), type_hello_vals, "Unknown (0x%04x)"));
|
||||
|
@ -432,6 +447,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
"Protocol ID: 0x%04X (%s)",
|
||||
tvb_get_ntohs(tvb, offset+7),
|
||||
val_to_str(tvb_get_ntohs(tvb, offset+7), type_hello_vals, "Unknown"));
|
||||
|
||||
switch(tvb_get_ntohs(tvb, offset+7)) {
|
||||
|
||||
case TYPE_HELLO_CLUSTER_MGMT:
|
||||
|
@ -475,10 +491,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
length - 9, "Unknown");
|
||||
break;
|
||||
}
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_VTP_MGMT_DOMAIN:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "VTP Management Domain: %s",
|
||||
tvb_format_text(tvb, offset + 4, length - 4));
|
||||
|
@ -490,10 +508,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "VTP Management Domain: %s",
|
||||
tvb_format_text(tvb, offset + 4, length - 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_NATIVE_VLAN:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Native VLAN: %u",
|
||||
tvb_get_ntohs(tvb, offset + 4));
|
||||
|
@ -505,10 +525,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Native VLAN: %u",
|
||||
tvb_get_ntohs(tvb, offset + 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_DUPLEX:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Duplex: %s",
|
||||
tvb_get_guint8(tvb, offset + 4) ?
|
||||
|
@ -522,13 +544,15 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
length - 4, "Duplex: %s",
|
||||
tvb_get_guint8(tvb, offset + 4) ?
|
||||
"Full" : "Half" );
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_VOIP_VLAN_REPLY:
|
||||
if (tree) {
|
||||
if (length >= 7) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "VoIP VLAN Reply: %u", tvb_get_ntohs(tvb, offset + 5));
|
||||
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;
|
||||
|
@ -552,10 +576,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
2, "Voice VLAN: %u",
|
||||
tvb_get_ntohs(tvb, offset + 5));
|
||||
}
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_VOIP_VLAN_QUERY:
|
||||
if (tree) {
|
||||
if (length >= 7) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "VoIP VLAN Query: %u", tvb_get_ntohs(tvb, offset + 5));
|
||||
|
@ -582,10 +608,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
2, "Voice VLAN: %u",
|
||||
tvb_get_ntohs(tvb, offset + 5));
|
||||
}
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_POWER:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Power Consumption: %u mW",
|
||||
tvb_get_ntohs(tvb, offset + 4));
|
||||
|
@ -597,10 +625,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
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:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "MTU: %u",
|
||||
tvb_get_ntohl(tvb,offset + 4));
|
||||
|
@ -612,10 +642,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "MTU: %u",
|
||||
tvb_get_ntohl(tvb,offset + 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_TRUST_BITMAP:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Trust Bitmap: 0x%02X",
|
||||
tvb_get_guint8(tvb, offset + 4));
|
||||
|
@ -627,10 +659,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Trust Bitmap: %02x",
|
||||
tvb_get_guint8(tvb, offset + 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_UNTRUSTED_COS:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Untrusted port CoS: 0x%02X",
|
||||
tvb_get_guint8(tvb, offset + 4));
|
||||
|
@ -642,10 +676,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Untrusted port CoS: %02x",
|
||||
tvb_get_guint8(tvb, offset + 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_SYSTEM_NAME:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "System Name: %s",
|
||||
tvb_format_text(tvb, offset + 4, length - 4));
|
||||
|
@ -657,10 +693,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "System Name: %s",
|
||||
tvb_format_text(tvb, offset + 4, length - 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_SYSTEM_OID:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "System Object Identifier");
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
|
||||
|
@ -671,10 +709,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "System Object Identifier: %s",
|
||||
tvb_bytes_to_str(tvb, offset + 4, length - 4));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
|
||||
case TYPE_MANAGEMENT_ADDR:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Management Addresses");
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
|
||||
|
@ -682,11 +722,14 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
offset + TLV_TYPE, 2, type);
|
||||
proto_tree_add_uint(tlv_tree, hf_cdp_tlvlength, tvb,
|
||||
offset + TLV_LENGTH, 2, length);
|
||||
}
|
||||
offset += 4;
|
||||
length -= 4;
|
||||
naddresses = tvb_get_ntohl(tvb, offset);
|
||||
if (tree) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset, 4,
|
||||
"Number of addresses: %u", naddresses);
|
||||
}
|
||||
offset += 4;
|
||||
length -= 4;
|
||||
while (naddresses != 0) {
|
||||
|
@ -703,6 +746,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
break;
|
||||
|
||||
case TYPE_LOCATION:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Location: %s",
|
||||
tvb_format_text(tvb, offset + 5, length - 5));
|
||||
|
@ -717,11 +761,12 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 5,
|
||||
length - 5, "Location: %s",
|
||||
tvb_format_text(tvb, offset + 5, length - 5));
|
||||
}
|
||||
offset += length;
|
||||
break;
|
||||
}
|
||||
|
||||
case TYPE_POWER_REQUESTED:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Power Request: ");
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
|
||||
|
@ -735,24 +780,29 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 6,
|
||||
2, "Management-ID: %u",
|
||||
tvb_get_ntohs(tvb, offset + 6));
|
||||
}
|
||||
power_req_len = (tvb_get_ntohs(tvb, offset + TLV_LENGTH)) - 8;
|
||||
/* Move offset to where the list of Power Request Values Exist */
|
||||
offset += 8;
|
||||
while(power_req_len) {
|
||||
if (power_req_len > 4) {
|
||||
power_req = tvb_get_ntohl(tvb, offset);
|
||||
if (tree) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset,
|
||||
4, "Power Requested: %u mW", power_req);
|
||||
proto_item_append_text(tlvi, "%u mW, ", power_req);
|
||||
}
|
||||
power_req_len -= 4;
|
||||
offset += 4;
|
||||
} else {
|
||||
if (power_req_len == 4) {
|
||||
power_req = tvb_get_ntohl(tvb, offset);
|
||||
if (tree) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset,
|
||||
4, "Power Requested: %u mW", power_req);
|
||||
proto_item_append_text(tlvi, "%u mW", power_req);
|
||||
}
|
||||
}
|
||||
offset += power_req_len;
|
||||
break;
|
||||
}
|
||||
|
@ -760,6 +810,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
break;
|
||||
|
||||
case TYPE_POWER_AVAILABLE:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb,
|
||||
offset, length, "Power Available: ");
|
||||
tlv_tree = proto_item_add_subtree(tlvi, ett_cdp_tlv);
|
||||
|
@ -773,24 +824,29 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
proto_tree_add_text(tlv_tree, tvb, offset + 6,
|
||||
2, "Management-ID: %u",
|
||||
tvb_get_ntohs(tvb, offset + 6));
|
||||
}
|
||||
power_avail_len = (tvb_get_ntohs(tvb, offset + TLV_LENGTH)) - 8;
|
||||
/* Move offset to where the list of Power Available Values Exist */
|
||||
offset += 8;
|
||||
while(power_avail_len) {
|
||||
if (power_avail_len > 4) {
|
||||
power_avail = tvb_get_ntohl(tvb, offset);
|
||||
if (tree) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset,
|
||||
4, "Power Available: %u mW", power_avail);
|
||||
proto_item_append_text(tlvi, "%u mW, ", power_avail);
|
||||
}
|
||||
power_avail_len -= 4;
|
||||
offset += 4;
|
||||
} else {
|
||||
if (power_avail_len == 4) {
|
||||
power_avail = tvb_get_ntohl(tvb, offset);
|
||||
if (tree) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset,
|
||||
4, "Power Available: %u mW", power_avail);
|
||||
proto_item_append_text(tlvi, "%u mW", power_avail);
|
||||
}
|
||||
}
|
||||
offset += power_avail_len;
|
||||
break;
|
||||
}
|
||||
|
@ -798,6 +854,7 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
break;
|
||||
|
||||
default:
|
||||
if (tree) {
|
||||
tlvi = proto_tree_add_text(cdp_tree, tvb, offset,
|
||||
length, "Type: %s, length: %u",
|
||||
val_to_str(type, type_vals, "Unknown (0x%04x)"),
|
||||
|
@ -810,8 +867,10 @@ dissect_cdp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
if (length > 4) {
|
||||
proto_tree_add_text(tlv_tree, tvb, offset + 4,
|
||||
length - 4, "Data");
|
||||
} else
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
offset += length;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue