]> The Tcpdump Group git mirrors - tcpdump/blob - print-dtp.c
Print truncations with nd_print_trunc() instead of tstr[] strings
[tcpdump] / print-dtp.c
1 /*
2 * Copyright (c) 1998-2007 The TCPDUMP project
3 *
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.
14 *
15 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
16 */
17
18 /* \summary: Dynamic Trunking Protocol (DTP) printer */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "netdissect-stdinc.h"
25
26 #include "netdissect.h"
27 #include "addrtoname.h"
28 #include "extract.h"
29
30
31 #define DTP_HEADER_LEN 1
32 #define DTP_DOMAIN_TLV 0x0001
33 #define DTP_STATUS_TLV 0x0002
34 #define DTP_DTP_TYPE_TLV 0x0003
35 #define DTP_NEIGHBOR_TLV 0x0004
36
37 static const struct tok dtp_tlv_values[] = {
38 { DTP_DOMAIN_TLV, "Domain TLV"},
39 { DTP_STATUS_TLV, "Status TLV"},
40 { DTP_DTP_TYPE_TLV, "DTP type TLV"},
41 { DTP_NEIGHBOR_TLV, "Neighbor TLV"},
42 { 0, NULL}
43 };
44
45 void
46 dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
47 {
48 int type, len;
49 const u_char *tptr;
50
51 ndo->ndo_protocol = "dtp";
52 if (length < DTP_HEADER_LEN)
53 goto trunc;
54
55 tptr = pptr;
56
57 ND_TCHECK_LEN(tptr, DTP_HEADER_LEN);
58
59 ND_PRINT("DTPv%u, length %u",
60 EXTRACT_U_1(tptr),
61 length);
62
63 /*
64 * In non-verbose mode, just print version.
65 */
66 if (ndo->ndo_vflag < 1) {
67 return;
68 }
69
70 tptr += DTP_HEADER_LEN;
71
72 while (tptr < (pptr+length)) {
73
74 ND_TCHECK_4(tptr);
75 type = EXTRACT_BE_U_2(tptr);
76 len = EXTRACT_BE_U_2(tptr + 2);
77 /* XXX: should not be but sometimes it is, see the test captures */
78 if (type == 0)
79 return;
80 ND_PRINT("\n\t%s (0x%04x) TLV, length %u",
81 tok2str(dtp_tlv_values, "Unknown", type),
82 type, len);
83
84 /* infinite loop check */
85 if (len < 4)
86 goto invalid;
87 ND_TCHECK_LEN(tptr, len);
88
89 switch (type) {
90 case DTP_DOMAIN_TLV:
91 ND_PRINT(", ");
92 nd_printzp(ndo, tptr+4, len-4, pptr+length);
93 break;
94
95 case DTP_STATUS_TLV:
96 case DTP_DTP_TYPE_TLV:
97 if (len < 5)
98 goto invalid;
99 ND_PRINT(", 0x%x", EXTRACT_U_1(tptr + 4));
100 break;
101
102 case DTP_NEIGHBOR_TLV:
103 if (len < 10)
104 goto invalid;
105 ND_PRINT(", %s", etheraddr_string(ndo, tptr+4));
106 break;
107
108 default:
109 break;
110 }
111 tptr += len;
112 }
113
114 return;
115
116 invalid:
117 ND_PRINT("%s", istr);
118 return;
119 trunc:
120 nd_print_trunc(ndo);
121 }