void udld_print (const u_char *pptr, u_int length) { int code, type, len; const u_char *tptr; if (length < UDLD_HEADER_LEN) goto trunc; tptr = pptr; if (!TTEST2(*tptr, UDLD_HEADER_LEN)) goto trunc; code = UDLD_EXTRACT_OPCODE(*tptr); printf("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u", UDLD_EXTRACT_VERSION(*tptr), tok2str(udld_code_values, "Reserved", code), code, bittok2str(udld_flags_values, "none", *(tptr+1)), *(tptr+1), length); /* * In non-verbose mode, just print version and opcode type */ if (vflag < 1) { return; } printf("\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr+2)); tptr += UDLD_HEADER_LEN; while (tptr < (pptr+length)) { if (!TTEST2(*tptr, 4)) goto trunc; type = EXTRACT_16BITS(tptr); len = EXTRACT_16BITS(tptr+2); len -= 4; tptr += 4; /* infinite loop check */ if (type == 0 || len == 0) { return; } printf("\n\t%s (0x%04x) TLV, length %u", tok2str(udld_tlv_values, "Unknown", type), type, len); switch (type) { case UDLD_DEVICE_ID_TLV: case UDLD_PORT_ID_TLV: case UDLD_ECHO_TLV: case UDLD_DEVICE_NAME_TLV: printf(", %s", tptr); break; case UDLD_MESSAGE_INTERVAL_TLV: case UDLD_TIMEOUT_INTERVAL_TLV: printf(", %us", (*tptr)); break; case UDLD_SEQ_NUMBER_TLV: printf(", %u", EXTRACT_32BITS(tptr)); break; default: break; } tptr += len; } return; trunc: printf("[|udld]"); }
void udld_print(netdissect_options *ndo, const u_char *pptr, u_int length) { int code, type, len; const u_char *tptr; ndo->ndo_protocol = "udld"; if (length < UDLD_HEADER_LEN) goto trunc; tptr = pptr; ND_TCHECK_LEN(tptr, UDLD_HEADER_LEN); code = UDLD_EXTRACT_OPCODE(EXTRACT_U_1(tptr)); ND_PRINT("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u", UDLD_EXTRACT_VERSION(EXTRACT_U_1(tptr)), tok2str(udld_code_values, "Reserved", code), code, bittok2str(udld_flags_values, "none", EXTRACT_U_1((tptr + 1))), EXTRACT_U_1((tptr + 1)), length); /* * In non-verbose mode, just print version and opcode type */ if (ndo->ndo_vflag < 1) { return; } ND_PRINT("\n\tChecksum 0x%04x (unverified)", EXTRACT_BE_U_2(tptr + 2)); tptr += UDLD_HEADER_LEN; while (tptr < (pptr+length)) { ND_TCHECK_4(tptr); type = EXTRACT_BE_U_2(tptr); len = EXTRACT_BE_U_2(tptr + 2); ND_PRINT("\n\t%s (0x%04x) TLV, length %u", tok2str(udld_tlv_values, "Unknown", type), type, len); if (type == 0) goto invalid; /* infinite loop check */ if (len <= 4) goto invalid; len -= 4; tptr += 4; ND_TCHECK_LEN(tptr, len); switch (type) { case UDLD_DEVICE_ID_TLV: case UDLD_PORT_ID_TLV: case UDLD_DEVICE_NAME_TLV: ND_PRINT(", "); nd_printzp(ndo, tptr, len, NULL); break; case UDLD_ECHO_TLV: ND_PRINT(", "); (void)nd_printn(ndo, tptr, len, NULL); break; case UDLD_MESSAGE_INTERVAL_TLV: case UDLD_TIMEOUT_INTERVAL_TLV: if (len != 1) goto invalid; ND_PRINT(", %us", (EXTRACT_U_1(tptr))); break; case UDLD_SEQ_NUMBER_TLV: if (len != 4) goto invalid; ND_PRINT(", %u", EXTRACT_BE_U_4(tptr)); break; default: break; } tptr += len; } return; invalid: ND_PRINT("%s", istr); return; trunc: nd_print_trunc(ndo); }