X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/e6511cc1a950fe1566b2236329d6b4bd0826cc7a..1a04b92e365f5ed01ca38619b41bcc4fc9cbd63c:/print-lldp.c diff --git a/print-lldp.c b/print-lldp.c index e87b16bd..f4752d49 100644 --- a/print-lldp.c +++ b/print-lldp.c @@ -617,8 +617,10 @@ print_ets_priority_assignment_table(netdissect_options *ndo, ND_PRINT((ndo, "\n\t Priority Assignment Table")); ND_PRINT((ndo, "\n\t Priority : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d", - ptr[0]>>4,ptr[0]&0x0f,ptr[1]>>4,ptr[1]&0x0f,ptr[2]>>4, - ptr[2] & 0x0f, ptr[3] >> 4, ptr[3] & 0x0f)); + EXTRACT_U_1(ptr) >> 4, EXTRACT_U_1(ptr) & 0x0f, + EXTRACT_U_1(ptr + 1) >> 4, EXTRACT_U_1(ptr + 1) & 0x0f, + EXTRACT_U_1(ptr + 2) >> 4, EXTRACT_U_1(ptr + 2) & 0x0f, + EXTRACT_U_1(ptr + 3) >> 4, EXTRACT_U_1(ptr + 3) & 0x0f)); } static void @@ -628,7 +630,9 @@ print_tc_bandwidth_table(netdissect_options *ndo, ND_PRINT((ndo, "\n\t TC Bandwidth Table")); ND_PRINT((ndo, "\n\t TC%% : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d", - ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7])); + EXTRACT_U_1(ptr), EXTRACT_U_1(ptr + 1), EXTRACT_U_1(ptr + 2), + EXTRACT_U_1(ptr + 3), EXTRACT_U_1(ptr + 4), EXTRACT_U_1(ptr + 5), + EXTRACT_U_1(ptr + 6), EXTRACT_U_1(ptr + 7))); } static void @@ -638,7 +642,9 @@ print_tsa_assignment_table(netdissect_options *ndo, ND_PRINT((ndo, "\n\t TSA Assignment Table")); ND_PRINT((ndo, "\n\t Traffic Class: 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : %-3d %-3d %-3d %-3d %-3d %-3d %-3d %-3d", - ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7])); + EXTRACT_U_1(ptr), EXTRACT_U_1(ptr + 1), EXTRACT_U_1(ptr + 2), + EXTRACT_U_1(ptr + 3), EXTRACT_U_1(ptr + 4), EXTRACT_U_1(ptr + 5), + EXTRACT_U_1(ptr + 6), EXTRACT_U_1(ptr + 7))); } /* @@ -656,7 +662,7 @@ lldp_private_8021_print(netdissect_options *ndo, if (tlv_len < 4) { return hexdump; } - subtype = *(tptr+3); + subtype = EXTRACT_U_1(tptr + 3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_8021_subtype_values, "unknown", subtype), @@ -668,26 +674,26 @@ lldp_private_8021_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t port vlan id (PVID): %u", - EXTRACT_16BITS(tptr + 4))); + EXTRACT_BE_U_2(tptr + 4))); break; case LLDP_PRIVATE_8021_SUBTYPE_PROTOCOL_VLAN_ID: if (tlv_len < 7) { return hexdump; } ND_PRINT((ndo, "\n\t port and protocol vlan id (PPVID): %u, flags [%s] (0x%02x)", - EXTRACT_16BITS(tptr+5), - bittok2str(lldp_8021_port_protocol_id_values, "none", *(tptr+4)), - *(tptr + 4))); + EXTRACT_BE_U_2(tptr + 5), + bittok2str(lldp_8021_port_protocol_id_values, "none", EXTRACT_U_1(tptr + 4)), + EXTRACT_U_1(tptr + 4))); break; case LLDP_PRIVATE_8021_SUBTYPE_VLAN_NAME: if (tlv_len < 6) { return hexdump; } - ND_PRINT((ndo, "\n\t vlan id (VID): %u", EXTRACT_16BITS(tptr + 4))); + ND_PRINT((ndo, "\n\t vlan id (VID): %u", EXTRACT_BE_U_2(tptr + 4))); if (tlv_len < 7) { return hexdump; } - sublen = *(tptr+6); + sublen = EXTRACT_U_1(tptr + 6); if (tlv_len < 7+sublen) { return hexdump; } @@ -698,7 +704,7 @@ lldp_private_8021_print(netdissect_options *ndo, if (tlv_len < 5) { return hexdump; } - sublen = *(tptr+4); + sublen = EXTRACT_U_1(tptr + 4); if (tlv_len < 5+sublen) { return hexdump; } @@ -709,13 +715,13 @@ lldp_private_8021_print(netdissect_options *ndo, if(tlv_len> i) & 0x01)); - tval=*(tptr+5); + tval=EXTRACT_U_1(tptr + 5); ND_PRINT((ndo, "\n\t Pre-Priority Ready Indicator")); ND_PRINT((ndo, "\n\t Priority : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : ")); @@ -727,7 +733,7 @@ lldp_private_8021_print(netdissect_options *ndo, if(tlv_len> 7, (tval >> 6) & 0x02, (tval >> 3) & 0x07, tval & 0x07)); @@ -746,7 +752,7 @@ lldp_private_8021_print(netdissect_options *ndo, if(tlv_len> 7, (tval >> 6) & 0x01, (tval >> 4) & 0x03, (tval & 0x0f))); ND_PRINT((ndo, "\n\t PFC Enable")); - tval=*(tptr+5); + tval=EXTRACT_U_1(tptr + 5); ND_PRINT((ndo, "\n\t Priority : 0 1 2 3 4 5 6 7")); ND_PRINT((ndo, "\n\t Value : ")); for(i=0;i> 5, (tval >> 3) & 0x03, (tval & 0x07), - EXTRACT_16BITS(tptr + i + 5))); + EXTRACT_BE_U_2(tptr + i + 5))); i=i+3; } break; @@ -798,20 +804,20 @@ lldp_private_8021_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t EVB Bridge Status")); - tval=*(tptr+4); + tval=EXTRACT_U_1(tptr + 4); ND_PRINT((ndo, "\n\t RES: %d, BGID: %d, RRCAP: %d, RRCTR: %d", tval >> 3, (tval >> 2) & 0x01, (tval >> 1) & 0x01, tval & 0x01)); ND_PRINT((ndo, "\n\t EVB Station Status")); - tval=*(tptr+5); + tval=EXTRACT_U_1(tptr + 5); ND_PRINT((ndo, "\n\t RES: %d, SGID: %d, RRREQ: %d,RRSTAT: %d", tval >> 4, (tval >> 3) & 0x01, (tval >> 2) & 0x01, tval & 0x03)); - tval=*(tptr+6); + tval=EXTRACT_U_1(tptr + 6); ND_PRINT((ndo, "\n\t R: %d, RTE: %d, ",tval >> 5, tval & 0x1f)); - tval=*(tptr+7); + tval=EXTRACT_U_1(tptr + 7); ND_PRINT((ndo, "EVB Mode: %s [%d]", tok2str(lldp_evb_mode_values, "unknown", tval >> 6), tval >> 6)); ND_PRINT((ndo, "\n\t ROL: %d, RWD: %d, ", (tval >> 5) & 0x01, tval & 0x1f)); - tval=*(tptr+8); + tval=EXTRACT_U_1(tptr + 8); ND_PRINT((ndo, "RES: %d, ROL: %d, RKA: %d", tval >> 6, (tval >> 5) & 0x01, tval & 0x1f)); break; @@ -819,17 +825,17 @@ lldp_private_8021_print(netdissect_options *ndo, if(tlv_len> 7, (tval >> 4) & 0x07, (tval >> 3) & 0x01)); - ND_PRINT((ndo, "ChnCap: %d", EXTRACT_16BITS(tptr + 6) & 0x0fff)); + ND_PRINT((ndo, "ChnCap: %d", EXTRACT_BE_U_2(tptr + 6) & 0x0fff)); sublen=tlv_len-8; if(sublen%3!=0) { return hexdump; } i=0; while(i> 12, tval & 0x000fff)); i=i+3; @@ -856,7 +862,7 @@ lldp_private_8023_print(netdissect_options *ndo, if (tlv_len < 4) { return hexdump; } - subtype = *(tptr+3); + subtype = EXTRACT_U_1(tptr + 3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_8023_subtype_values, "unknown", subtype), @@ -868,14 +874,14 @@ lldp_private_8023_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t autonegotiation [%s] (0x%02x)", - bittok2str(lldp_8023_autonegotiation_values, "none", *(tptr+4)), - *(tptr + 4))); + bittok2str(lldp_8023_autonegotiation_values, "none", EXTRACT_U_1(tptr + 4)), + EXTRACT_U_1(tptr + 4))); ND_PRINT((ndo, "\n\t PMD autoneg capability [%s] (0x%04x)", - bittok2str(lldp_pmd_capability_values,"unknown", EXTRACT_16BITS(tptr+5)), - EXTRACT_16BITS(tptr + 5))); + bittok2str(lldp_pmd_capability_values,"unknown", EXTRACT_BE_U_2(tptr + 5)), + EXTRACT_BE_U_2(tptr + 5))); ND_PRINT((ndo, "\n\t MAU type %s (0x%04x)", - tok2str(lldp_mau_types_values, "unknown", EXTRACT_16BITS(tptr+7)), - EXTRACT_16BITS(tptr + 7))); + tok2str(lldp_mau_types_values, "unknown", EXTRACT_BE_U_2(tptr + 7)), + EXTRACT_BE_U_2(tptr + 7))); break; case LLDP_PRIVATE_8023_SUBTYPE_MDIPOWER: @@ -883,9 +889,9 @@ lldp_private_8023_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t MDI power support [%s], power pair %s, power class %s", - bittok2str(lldp_mdi_values, "none", *(tptr+4)), - tok2str(lldp_mdi_power_pairs_values, "unknown", *(tptr+5)), - tok2str(lldp_mdi_power_class_values, "unknown", *(tptr + 6)))); + bittok2str(lldp_mdi_values, "none", EXTRACT_U_1((tptr + 4))), + tok2str(lldp_mdi_power_pairs_values, "unknown", EXTRACT_U_1((tptr + 5))), + tok2str(lldp_mdi_power_class_values, "unknown", EXTRACT_U_1((tptr + 6))))); break; case LLDP_PRIVATE_8023_SUBTYPE_LINKAGGR: @@ -893,15 +899,15 @@ lldp_private_8023_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t aggregation status [%s], aggregation port ID %u", - bittok2str(lldp_aggregation_values, "none", *(tptr+4)), - EXTRACT_32BITS(tptr + 5))); + bittok2str(lldp_aggregation_values, "none", EXTRACT_U_1((tptr + 4))), + EXTRACT_BE_U_4(tptr + 5))); break; case LLDP_PRIVATE_8023_SUBTYPE_MTU: if (tlv_len < 6) { return hexdump; } - ND_PRINT((ndo, "\n\t MTU size %u", EXTRACT_16BITS(tptr + 4))); + ND_PRINT((ndo, "\n\t MTU size %u", EXTRACT_BE_U_2(tptr + 4))); break; default: @@ -920,8 +926,8 @@ lldp_extract_latlon(const u_char *tptr) { uint64_t latlon; - latlon = *tptr & 0x3; - latlon = (latlon << 32) | EXTRACT_32BITS(tptr+1); + latlon = EXTRACT_U_1(tptr) & 0x3; + latlon = (latlon << 32) | EXTRACT_BE_U_4(tptr + 1); return latlon; } @@ -940,7 +946,7 @@ lldp_private_iana_print(netdissect_options *ndo, if (tlv_len < 8) { return hexdump; } - subtype = *(tptr+3); + subtype = EXTRACT_U_1(tptr + 3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_iana_subtype_values, "unknown", subtype), @@ -976,7 +982,7 @@ lldp_private_tia_print(netdissect_options *ndo, if (tlv_len < 4) { return hexdump; } - subtype = *(tptr+3); + subtype = EXTRACT_U_1(tptr + 3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_tia_subtype_values, "unknown", subtype), @@ -989,10 +995,10 @@ lldp_private_tia_print(netdissect_options *ndo, } ND_PRINT((ndo, "\n\t Media capabilities [%s] (0x%04x)", bittok2str(lldp_tia_capabilities_values, "none", - EXTRACT_16BITS(tptr + 4)), EXTRACT_16BITS(tptr + 4))); + EXTRACT_BE_U_2(tptr + 4)), EXTRACT_BE_U_2(tptr + 4))); ND_PRINT((ndo, "\n\t Device type [%s] (0x%02x)", - tok2str(lldp_tia_device_type_values, "unknown", *(tptr+6)), - *(tptr + 6))); + tok2str(lldp_tia_device_type_values, "unknown", EXTRACT_U_1(tptr + 6)), + EXTRACT_U_1(tptr + 6))); break; case LLDP_PRIVATE_TIA_SUBTYPE_NETWORK_POLICY: @@ -1000,23 +1006,23 @@ lldp_private_tia_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t Application type [%s] (0x%02x)", - tok2str(lldp_tia_application_type_values, "none", *(tptr+4)), - *(tptr + 4))); + tok2str(lldp_tia_application_type_values, "none", EXTRACT_U_1(tptr + 4)), + EXTRACT_U_1(tptr + 4))); ND_PRINT((ndo, ", Flags [%s]", bittok2str( - lldp_tia_network_policy_bits_values, "none", *(tptr + 5)))); + lldp_tia_network_policy_bits_values, "none", EXTRACT_U_1((tptr + 5))))); ND_PRINT((ndo, "\n\t Vlan id %u", - LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_16BITS(tptr + 5)))); + LLDP_EXTRACT_NETWORK_POLICY_VLAN(EXTRACT_BE_U_2(tptr + 5)))); ND_PRINT((ndo, ", L2 priority %u", - LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_16BITS(tptr + 6)))); + LLDP_EXTRACT_NETWORK_POLICY_L2_PRIORITY(EXTRACT_BE_U_2(tptr + 6)))); ND_PRINT((ndo, ", DSCP value %u", - LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_16BITS(tptr + 6)))); + LLDP_EXTRACT_NETWORK_POLICY_DSCP(EXTRACT_BE_U_2(tptr + 6)))); break; case LLDP_PRIVATE_TIA_SUBTYPE_LOCAL_ID: if (tlv_len < 5) { return hexdump; } - location_format = *(tptr+4); + location_format = EXTRACT_U_1(tptr + 4); ND_PRINT((ndo, "\n\t Location data format %s (0x%02x)", tok2str(lldp_tia_location_data_format_values, "unknown", location_format), location_format)); @@ -1027,25 +1033,25 @@ lldp_private_tia_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t Latitude resolution %u, latitude value %" PRIu64, - (*(tptr + 5) >> 2), lldp_extract_latlon(tptr + 5))); + (EXTRACT_U_1(tptr + 5) >> 2), lldp_extract_latlon(tptr + 5))); ND_PRINT((ndo, "\n\t Longitude resolution %u, longitude value %" PRIu64, - (*(tptr + 10) >> 2), lldp_extract_latlon(tptr + 10))); + (EXTRACT_U_1(tptr + 10) >> 2), lldp_extract_latlon(tptr + 10))); ND_PRINT((ndo, "\n\t Altitude type %s (%u)", - tok2str(lldp_tia_location_altitude_type_values, "unknown",(*(tptr+15)>>4)), - (*(tptr + 15) >> 4))); + tok2str(lldp_tia_location_altitude_type_values, "unknown",EXTRACT_U_1(tptr + 15) >> 4), + (EXTRACT_U_1(tptr + 15) >> 4))); ND_PRINT((ndo, "\n\t Altitude resolution %u, altitude value 0x%x", - (EXTRACT_16BITS(tptr+15)>>6)&0x3f, - ((EXTRACT_32BITS(tptr + 16) & 0x3fffffff)))); + (EXTRACT_BE_U_2(tptr + 15)>>6)&0x3f, + ((EXTRACT_BE_U_4(tptr + 16) & 0x3fffffff)))); ND_PRINT((ndo, "\n\t Datum %s (0x%02x)", - tok2str(lldp_tia_location_datum_type_values, "unknown", *(tptr+20)), - *(tptr + 20))); + tok2str(lldp_tia_location_datum_type_values, "unknown", EXTRACT_U_1(tptr + 20)), + EXTRACT_U_1(tptr + 20))); break; case LLDP_TIA_LOCATION_DATA_FORMAT_CIVIC_ADDRESS: if (tlv_len < 6) { return hexdump; } - lci_len = *(tptr+5); + lci_len = EXTRACT_U_1(tptr + 5); if (lci_len < 3) { return hexdump; } @@ -1054,8 +1060,8 @@ lldp_private_tia_print(netdissect_options *ndo, } ND_PRINT((ndo, "\n\t LCI length %u, LCI what %s (0x%02x), Country-code ", lci_len, - tok2str(lldp_tia_location_lci_what_values, "unknown", *(tptr+6)), - *(tptr + 6))); + tok2str(lldp_tia_location_lci_what_values, "unknown", EXTRACT_U_1(tptr + 6)), + EXTRACT_U_1(tptr + 6))); /* Country code */ safeputs(ndo, tptr + 7, 2); @@ -1068,8 +1074,8 @@ lldp_private_tia_print(netdissect_options *ndo, if (lci_len < 2) { return hexdump; } - ca_type = *(tptr); - ca_len = *(tptr+1); + ca_type = EXTRACT_U_1(tptr); + ca_len = EXTRACT_U_1(tptr + 1); tptr += 2; lci_len -= 2; @@ -1108,13 +1114,13 @@ lldp_private_tia_print(netdissect_options *ndo, return hexdump; } ND_PRINT((ndo, "\n\t Power type [%s]", - (*(tptr + 4) & 0xC0 >> 6) ? "PD device" : "PSE device")); + (EXTRACT_U_1(tptr + 4) & 0xC0 >> 6) ? "PD device" : "PSE device")); ND_PRINT((ndo, ", Power source [%s]", - tok2str(lldp_tia_power_source_values, "none", (*(tptr + 4) & 0x30) >> 4))); + tok2str(lldp_tia_power_source_values, "none", (EXTRACT_U_1((tptr + 4)) & 0x30) >> 4))); ND_PRINT((ndo, "\n\t Power priority [%s] (0x%02x)", - tok2str(lldp_tia_power_priority_values, "none", *(tptr+4)&0x0f), - *(tptr + 4) & 0x0f)); - power_val = EXTRACT_16BITS(tptr+5); + tok2str(lldp_tia_power_priority_values, "none", EXTRACT_U_1(tptr + 4) & 0x0f), + EXTRACT_U_1(tptr + 4) & 0x0f)); + power_val = EXTRACT_BE_U_2(tptr + 5); if (power_val < LLDP_TIA_POWER_VAL_MAX) { ND_PRINT((ndo, ", Power %.1f Watts", ((float)power_val) / 10)); } else { @@ -1159,7 +1165,7 @@ lldp_private_dcbx_print(netdissect_options *ndo, if (len < 4) { return hexdump; } - subtype = *(pptr+3); + subtype = EXTRACT_U_1(pptr + 3); ND_PRINT((ndo, "\n\t %s Subtype (%u)", tok2str(lldp_dcbx_subtype_values, "unknown", subtype), @@ -1174,9 +1180,9 @@ lldp_private_dcbx_print(netdissect_options *ndo, while (tlen >= sizeof(tlv)) { - ND_TCHECK2(*tptr, sizeof(tlv)); + ND_TCHECK_LEN(tptr, sizeof(tlv)); - tlv = EXTRACT_16BITS(tptr); + tlv = EXTRACT_BE_U_2(tptr); tlv_type = LLDP_EXTRACT_TYPE(tlv); tlv_len = LLDP_EXTRACT_LEN(tlv); @@ -1190,7 +1196,7 @@ lldp_private_dcbx_print(netdissect_options *ndo, break; } - ND_TCHECK2(*tptr, tlv_len); + ND_TCHECK_LEN(tptr, tlv_len); if (tlen < tlv_len) { goto trunc; } @@ -1203,11 +1209,11 @@ lldp_private_dcbx_print(netdissect_options *ndo, } ND_PRINT((ndo, "\n\t Control - Protocol Control (type 0x%x, length %d)", LLDP_DCBX_CONTROL_TLV, tlv_len)); - ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); - ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); - ND_PRINT((ndo, "\n\t Sequence Number: %d", EXTRACT_32BITS(tptr + 2))); + ND_PRINT((ndo, "\n\t Oper_Version: %d", EXTRACT_U_1(tptr))); + ND_PRINT((ndo, "\n\t Max_Version: %d", EXTRACT_U_1(tptr + 1))); + ND_PRINT((ndo, "\n\t Sequence Number: %d", EXTRACT_BE_U_4(tptr + 2))); ND_PRINT((ndo, "\n\t Acknowledgement Number: %d", - EXTRACT_32BITS(tptr + 6))); + EXTRACT_BE_U_4(tptr + 6))); break; case LLDP_DCBX_PRIORITY_GROUPS_TLV: if (tlv_len < 17) { @@ -1215,29 +1221,29 @@ lldp_private_dcbx_print(netdissect_options *ndo, } ND_PRINT((ndo, "\n\t Feature - Priority Group (type 0x%x, length %d)", LLDP_DCBX_PRIORITY_GROUPS_TLV, tlv_len)); - ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); - ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); - ND_PRINT((ndo, "\n\t Info block(0x%02X): ", *(tptr + 2))); - tval = *(tptr+2); + ND_PRINT((ndo, "\n\t Oper_Version: %d", EXTRACT_U_1(tptr))); + ND_PRINT((ndo, "\n\t Max_Version: %d", EXTRACT_U_1(tptr + 1))); + ND_PRINT((ndo, "\n\t Info block(0x%02X): ", EXTRACT_U_1(tptr + 2))); + tval = EXTRACT_U_1(tptr + 2); ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d", (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0, (tval & 0x20) ? 1 : 0)); - ND_PRINT((ndo, "\n\t SubType: %d", *(tptr + 3))); + ND_PRINT((ndo, "\n\t SubType: %d", EXTRACT_U_1(tptr + 3))); ND_PRINT((ndo, "\n\t Priority Allocation")); /* * Array of 8 4-bit priority group ID values; we fetch all * 32 bits and extract each nibble. */ - pgval = EXTRACT_32BITS(tptr+4); + pgval = EXTRACT_BE_U_4(tptr + 4); for (i = 0; i <= 7; i++) { ND_PRINT((ndo, "\n\t PgId_%d: %d", i, (pgval >> (28 - 4 * i)) & 0xF)); } ND_PRINT((ndo, "\n\t Priority Group Allocation")); for (i = 0; i <= 7; i++) - ND_PRINT((ndo, "\n\t Pg percentage[%d]: %d", i, *(tptr + 8 + i))); - ND_PRINT((ndo, "\n\t NumTCsSupported: %d", *(tptr + 8 + 8))); + ND_PRINT((ndo, "\n\t Pg percentage[%d]: %d", i, EXTRACT_U_1(tptr + 8 + i))); + ND_PRINT((ndo, "\n\t NumTCsSupported: %d", EXTRACT_U_1(tptr + 8 + 8))); break; case LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV: if (tlv_len < 6) { @@ -1246,20 +1252,20 @@ lldp_private_dcbx_print(netdissect_options *ndo, ND_PRINT((ndo, "\n\t Feature - Priority Flow Control")); ND_PRINT((ndo, " (type 0x%x, length %d)", LLDP_DCBX_PRIORITY_FLOW_CONTROL_TLV, tlv_len)); - ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); - ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); - ND_PRINT((ndo, "\n\t Info block(0x%02X): ", *(tptr + 2))); - tval = *(tptr+2); + ND_PRINT((ndo, "\n\t Oper_Version: %d", EXTRACT_U_1(tptr))); + ND_PRINT((ndo, "\n\t Max_Version: %d", EXTRACT_U_1(tptr + 1))); + ND_PRINT((ndo, "\n\t Info block(0x%02X): ", EXTRACT_U_1(tptr + 2))); + tval = EXTRACT_U_1(tptr + 2); ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d", (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0, (tval & 0x20) ? 1 : 0)); - ND_PRINT((ndo, "\n\t SubType: %d", *(tptr + 3))); - tval = *(tptr+4); - ND_PRINT((ndo, "\n\t PFC Config (0x%02X)", *(tptr + 4))); + ND_PRINT((ndo, "\n\t SubType: %d", EXTRACT_U_1(tptr + 3))); + tval = EXTRACT_U_1(tptr + 4); + ND_PRINT((ndo, "\n\t PFC Config (0x%02X)", EXTRACT_U_1(tptr + 4))); for (i = 0; i <= 7; i++) ND_PRINT((ndo, "\n\t Priority Bit %d: %s", i, (tval & (1 << i)) ? "Enabled" : "Disabled")); - ND_PRINT((ndo, "\n\t NumTCPFCSupported: %d", *(tptr + 5))); + ND_PRINT((ndo, "\n\t NumTCPFCSupported: %d", EXTRACT_U_1(tptr + 5))); break; case LLDP_DCBX_APPLICATION_TLV: if (tlv_len < 4) { @@ -1267,26 +1273,26 @@ lldp_private_dcbx_print(netdissect_options *ndo, } ND_PRINT((ndo, "\n\t Feature - Application (type 0x%x, length %d)", LLDP_DCBX_APPLICATION_TLV, tlv_len)); - ND_PRINT((ndo, "\n\t Oper_Version: %d", *tptr)); - ND_PRINT((ndo, "\n\t Max_Version: %d", *(tptr + 1))); - ND_PRINT((ndo, "\n\t Info block(0x%02X): ", *(tptr + 2))); - tval = *(tptr+2); + ND_PRINT((ndo, "\n\t Oper_Version: %d", EXTRACT_U_1(tptr))); + ND_PRINT((ndo, "\n\t Max_Version: %d", EXTRACT_U_1(tptr + 1))); + ND_PRINT((ndo, "\n\t Info block(0x%02X): ", EXTRACT_U_1(tptr + 2))); + tval = EXTRACT_U_1(tptr + 2); ND_PRINT((ndo, "Enable bit: %d, Willing bit: %d, Error Bit: %d", (tval & 0x80) ? 1 : 0, (tval & 0x40) ? 1 : 0, (tval & 0x20) ? 1 : 0)); - ND_PRINT((ndo, "\n\t SubType: %d", *(tptr + 3))); + ND_PRINT((ndo, "\n\t SubType: %d", EXTRACT_U_1(tptr + 3))); tval = tlv_len - 4; mptr = tptr + 4; while (tval >= 6) { ND_PRINT((ndo, "\n\t Application Value")); ND_PRINT((ndo, "\n\t Application Protocol ID: 0x%04x", - EXTRACT_16BITS(mptr))); - uval = EXTRACT_24BITS(mptr+2); + EXTRACT_BE_U_2(mptr))); + uval = EXTRACT_BE_U_3(mptr + 2); ND_PRINT((ndo, "\n\t SF (0x%x) Application Protocol ID is %s", (uval >> 22), (uval >> 22) ? "Socket Number" : "L2 EtherType")); ND_PRINT((ndo, "\n\t OUI: 0x%06x", uval & 0x3fffff)); - ND_PRINT((ndo, "\n\t User Priority Map: 0x%02x", *(mptr + 5))); + ND_PRINT((ndo, "\n\t User Priority Map: 0x%02x", EXTRACT_U_1(mptr + 5))); tval = tval - 6; mptr = mptr + 6; } @@ -1319,7 +1325,7 @@ lldp_network_addr_print(netdissect_options *ndo, const u_char *tptr, u_int len) if (len < 1) return NULL; len--; - af = *tptr; + af = EXTRACT_U_1(tptr); switch (af) { case AFNUM_INET: if (len < 4) @@ -1369,7 +1375,8 @@ lldp_mgmt_addr_tlv_print(netdissect_options *ndo, if (tlen < 1) { return 0; } - mgmt_addr_len = *tptr++; + mgmt_addr_len = EXTRACT_U_1(tptr); + tptr++; tlen--; if (tlen < mgmt_addr_len) { @@ -1389,11 +1396,11 @@ lldp_mgmt_addr_tlv_print(netdissect_options *ndo, return 0; } - intf_num_subtype = *tptr; + intf_num_subtype = EXTRACT_U_1(tptr); ND_PRINT((ndo, "\n\t %s Interface Numbering (%u): %u", tok2str(lldp_intf_numb_subtype_values, "Unknown", intf_num_subtype), intf_num_subtype, - EXTRACT_32BITS(tptr + 1))); + EXTRACT_BE_U_4(tptr + 1))); tptr += LLDP_INTF_NUM_LEN; tlen -= LLDP_INTF_NUM_LEN; @@ -1402,7 +1409,7 @@ lldp_mgmt_addr_tlv_print(netdissect_options *ndo, * The OID is optional. */ if (tlen) { - oid_len = *tptr; + oid_len = EXTRACT_U_1(tptr); if (tlen < 1U + oid_len) { return 0; @@ -1418,7 +1425,7 @@ lldp_mgmt_addr_tlv_print(netdissect_options *ndo, void lldp_print(netdissect_options *ndo, - register const u_char *pptr, register u_int len) + const u_char *pptr, u_int len) { uint8_t subtype; uint16_t tlv, cap, ena_cap; @@ -1433,9 +1440,9 @@ lldp_print(netdissect_options *ndo, while (tlen >= sizeof(tlv)) { - ND_TCHECK2(*tptr, sizeof(tlv)); + ND_TCHECK_LEN(tptr, sizeof(tlv)); - tlv = EXTRACT_16BITS(tptr); + tlv = EXTRACT_BE_U_2(tptr); tlv_type = LLDP_EXTRACT_TYPE(tlv); tlv_len = LLDP_EXTRACT_LEN(tlv); @@ -1455,7 +1462,7 @@ lldp_print(netdissect_options *ndo, break; } - ND_TCHECK2(*tptr, tlv_len); + ND_TCHECK_LEN(tptr, tlv_len); if (tlen < tlv_len) { goto trunc; } @@ -1467,7 +1474,7 @@ lldp_print(netdissect_options *ndo, if (tlv_len < 2) { goto trunc; } - subtype = *tptr; + subtype = EXTRACT_U_1(tptr); ND_PRINT((ndo, "\n\t Subtype %s (%u): ", tok2str(lldp_chassis_subtype_values, "Unknown", subtype), subtype)); @@ -1508,7 +1515,7 @@ lldp_print(netdissect_options *ndo, if (tlv_len < 2) { goto trunc; } - subtype = *tptr; + subtype = EXTRACT_U_1(tptr); ND_PRINT((ndo, "\n\t Subtype %s (%u): ", tok2str(lldp_port_subtype_values, "Unknown", subtype), subtype)); @@ -1549,7 +1556,7 @@ lldp_print(netdissect_options *ndo, if (tlv_len < 2) { goto trunc; } - ND_PRINT((ndo, ": TTL %us", EXTRACT_16BITS(tptr))); + ND_PRINT((ndo, ": TTL %us", EXTRACT_BE_U_2(tptr))); } break; @@ -1587,8 +1594,8 @@ lldp_print(netdissect_options *ndo, if (tlv_len < 4) { goto trunc; } - cap = EXTRACT_16BITS(tptr); - ena_cap = EXTRACT_16BITS(tptr+2); + cap = EXTRACT_BE_U_2(tptr); + ena_cap = EXTRACT_BE_U_2(tptr + 2); ND_PRINT((ndo, "\n\t System Capabilities [%s] (0x%04x)", bittok2str(lldp_cap_values, "none", cap), cap)); ND_PRINT((ndo, "\n\t Enabled Capabilities [%s] (0x%04x)", @@ -1609,7 +1616,7 @@ lldp_print(netdissect_options *ndo, if (tlv_len < 3) { goto trunc; } - oui = EXTRACT_24BITS(tptr); + oui = EXTRACT_BE_U_3(tptr); ND_PRINT((ndo, ": OUI %s (0x%06x)", tok2str(oui_values, "Unknown", oui), oui)); switch (oui) {