+static void
+cdp_print_phys_loc(netdissect_options *ndo,
+ const u_char *cp, const u_int len)
+{
+ ND_PRINT("0x%02x", GET_U_1(cp));
+ if (len > 1) {
+ ND_PRINT("/");
+ nd_printjn(ndo, cp + 1, len - 1);
+ }
+}
+
+struct cdp_tlvinfo {
+ const char *name;
+ void (*printer)(netdissect_options *ndo, const u_char *, u_int);
+ int min_len, max_len;
+};
+
+#define T_DEV_ID 0x01
+#define T_MAX 0x17
+static const struct cdp_tlvinfo cdptlvs[T_MAX + 1] = {
+ /* 0x00 */
+ [ T_DEV_ID ] = { "Device-ID", cdp_print_string, -1, -1 },
+ [ 0x02 ] = { "Address", cdp_print_addr, -1, -1 },
+ [ 0x03 ] = { "Port-ID", cdp_print_string, -1, -1 },
+ [ 0x04 ] = { "Capability", cdp_print_capability, 4, 4 },
+ [ 0x05 ] = { "Version String", cdp_print_version, -1, -1 },
+ [ 0x06 ] = { "Platform", cdp_print_string, -1, -1 },
+ [ 0x07 ] = { "Prefixes", cdp_print_prefixes, -1, -1 },
+ /* not documented */
+ [ 0x08 ] = { "Protocol-Hello option", NULL, -1, -1 },
+ /* CDPv2 */
+ [ 0x09 ] = { "VTP Management Domain", cdp_print_string, -1, -1 },
+ /* CDPv2 */
+ [ 0x0a ] = { "Native VLAN ID", cdp_print_uint16, 2, 2 },
+ /* CDPv2 */
+ [ 0x0b ] = { "Duplex", cdp_print_duplex, 1, 1 },
+ /* 0x0c */
+ /* 0x0d */
+ /* incomplete doc. */
+ [ 0x0e ] = { "ATA-186 VoIP VLAN assignment", cdp_print_ata186, 3, 3 },
+ /* incomplete doc. */
+ [ 0x0f ] = { "ATA-186 VoIP VLAN request", cdp_print_ata186, 2, 3 },
+ /* not documented */
+ [ 0x10 ] = { "power consumption", cdp_print_power, 1, 3 },
+ /* not documented */
+ [ 0x11 ] = { "MTU", cdp_print_mtu, 4, 4 },
+ /* not documented */
+ [ 0x12 ] = { "AVVID trust bitmap", cdp_print_uint8x, 1, 1 },
+ /* not documented */
+ [ 0x13 ] = { "AVVID untrusted ports CoS", cdp_print_uint8x, 1, 1 },
+ /* not documented */
+ [ 0x14 ] = { "System Name", cdp_print_string, -1, -1 },
+ /* not documented */
+ [ 0x15 ] = { "System Object ID (not decoded)", NULL, -1, -1 },
+ [ 0x16 ] = { "Management Addresses", cdp_print_addr, 4, -1 },
+ /* not documented */
+ [ 0x17 ] = { "Physical Location", cdp_print_phys_loc, 1, -1 },
+};
+
+void
+cdp_print(netdissect_options *ndo,
+ const u_char *tptr, u_int length)
+{
+ u_int orig_length = length;
+ uint16_t checksum;
+
+ ndo->ndo_protocol = "cdp";
+
+ if (length < CDP_HEADER_LEN) {
+ ND_PRINT(" (packet length %u < %u)", length, CDP_HEADER_LEN);
+ goto invalid;
+ }
+ ND_PRINT("CDPv%u, ttl: %us",
+ GET_U_1(tptr + CDP_HEADER_VERSION_OFFSET),
+ GET_U_1(tptr + CDP_HEADER_TTL_OFFSET));
+ checksum = GET_BE_U_2(tptr + CDP_HEADER_CHECKSUM_OFFSET);