]> The Tcpdump Group git mirrors - tcpdump/blob - print-dtp.c
Remove debugging printouts.
[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 * Dynamic Trunk Protocol (DTP)
16 *
17 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
18 */
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 static const char tstr[] = " [|dtp]";
31 static const char istr[] = " (invalid)";
32
33 #define DTP_HEADER_LEN 1
34 #define DTP_DOMAIN_TLV 0x0001
35 #define DTP_STATUS_TLV 0x0002
36 #define DTP_DTP_TYPE_TLV 0x0003
37 #define DTP_NEIGHBOR_TLV 0x0004
38
39 static const struct tok dtp_tlv_values[] = {
40 { DTP_DOMAIN_TLV, "Domain TLV"},
41 { DTP_STATUS_TLV, "Status TLV"},
42 { DTP_DTP_TYPE_TLV, "DTP type TLV"},
43 { DTP_NEIGHBOR_TLV, "Neighbor TLV"},
44 { 0, NULL}
45 };
46
47 void
48 dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
49 {
50 int type, len;
51 const u_char *tptr;
52
53 if (length < DTP_HEADER_LEN)
54 goto trunc;
55
56 tptr = pptr;
57
58 ND_TCHECK2(*tptr, DTP_HEADER_LEN);
59
60 ND_PRINT((ndo, "DTPv%u, length %u",
61 (*tptr),
62 length));
63
64 /*
65 * In non-verbose mode, just print version.
66 */
67 if (ndo->ndo_vflag < 1) {
68 return;
69 }
70
71 tptr += DTP_HEADER_LEN;
72
73 while (tptr < (pptr+length)) {
74
75 ND_TCHECK2(*tptr, 4);
76 type = EXTRACT_16BITS(tptr);
77 len = EXTRACT_16BITS(tptr+2);
78 /* XXX: should not be but sometimes it is, see the test captures */
79 if (type == 0)
80 return;
81 ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
82 tok2str(dtp_tlv_values, "Unknown", type),
83 type, len));
84
85 /* infinite loop check */
86 if (len < 4)
87 goto invalid;
88 ND_TCHECK2(*tptr, len);
89
90 switch (type) {
91 case DTP_DOMAIN_TLV:
92 ND_PRINT((ndo, ", "));
93 fn_printzp(ndo, tptr+4, len-4, pptr+length);
94 break;
95
96 case DTP_STATUS_TLV:
97 case DTP_DTP_TYPE_TLV:
98 if (len < 5)
99 goto invalid;
100 ND_PRINT((ndo, ", 0x%x", *(tptr+4)));
101 break;
102
103 case DTP_NEIGHBOR_TLV:
104 if (len < 10)
105 goto invalid;
106 ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4)));
107 break;
108
109 default:
110 break;
111 }
112 tptr += len;
113 }
114
115 return;
116
117 invalid:
118 ND_PRINT((ndo, "%s", istr));
119 return;
120 trunc:
121 ND_PRINT((ndo, "%s", tstr));
122 }
123
124 /*
125 * Local Variables:
126 * c-style: whitesmith
127 * c-basic-offset: 4
128 * End:
129 */