2 * Copyright (c) 1998-2007 The TCPDUMP project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
18 /* \summary: Dynamic Trunking Protocol (DTP) printer */
24 #include "netdissect-stdinc.h"
26 #define ND_LONGJMP_FROM_TCHECK
27 #include "netdissect.h"
28 #include "addrtoname.h"
32 #define DTP_HEADER_LEN 1
33 #define DTP_DOMAIN_TLV 0x0001
34 #define DTP_STATUS_TLV 0x0002
35 #define DTP_DTP_TYPE_TLV 0x0003
36 #define DTP_NEIGHBOR_TLV 0x0004
38 static const struct tok dtp_tlv_values[] = {
39 { DTP_DOMAIN_TLV, "Domain" },
40 { DTP_STATUS_TLV, "Status" },
41 { DTP_DTP_TYPE_TLV, "DTP type" },
42 { DTP_NEIGHBOR_TLV, "Neighbor" },
47 dtp_print(netdissect_options *ndo, const u_char *tptr, u_int length)
49 ndo->ndo_protocol = "dtp";
50 if (length < DTP_HEADER_LEN) {
51 ND_PRINT("[zero packet length]");
55 ND_PRINT("DTPv%u, length %u",
60 * In non-verbose mode, just print version.
62 if (ndo->ndo_vflag < 1) {
66 tptr += DTP_HEADER_LEN;
67 length -= DTP_HEADER_LEN;
73 ND_PRINT("[%u bytes remaining]", length);
76 type = GET_BE_U_2(tptr);
77 len = GET_BE_U_2(tptr + 2);
78 /* XXX: should not be but sometimes it is, see the test captures */
81 ND_PRINT("\n\t%s (0x%04x) TLV, length %u",
82 tok2str(dtp_tlv_values, "Unknown", type),
85 /* infinite loop check */
86 if (len < 4 || len > length) {
87 ND_PRINT("[invalid TLV length %u]", len);
94 nd_printjnp(ndo, tptr+4, len-4);
98 case DTP_DTP_TYPE_TLV:
101 ND_PRINT(", 0x%x", GET_U_1(tptr + 4));
104 case DTP_NEIGHBOR_TLV:
107 ND_PRINT(", %s", GET_ETHERADDR_STRING(tptr+4));
111 ND_TCHECK_LEN(tptr, len);
120 nd_print_invalid(ndo);
121 ND_TCHECK_LEN(tptr, length);