]> The Tcpdump Group git mirrors - tcpdump/blob - print-dtp.c
NDOize AH, BEEP and DTP decoders
[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 <tcpdump-stdinc.h>
25
26 #include "netdissect.h"
27 #include "addrtoname.h"
28 #include "extract.h"
29
30 #define DTP_HEADER_LEN 1
31 #define DTP_DOMAIN_TLV 0x0001
32 #define DTP_STATUS_TLV 0x0002
33 #define DTP_DTP_TYPE_TLV 0x0003
34 #define DTP_NEIGHBOR_TLV 0x0004
35
36 static const struct tok dtp_tlv_values[] = {
37 { DTP_DOMAIN_TLV, "Domain TLV"},
38 { DTP_STATUS_TLV, "Status TLV"},
39 { DTP_DTP_TYPE_TLV, "DTP type TLV"},
40 { DTP_NEIGHBOR_TLV, "Neighbor TLV"},
41 { 0, NULL}
42 };
43
44 void
45 dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
46 {
47 int type, len;
48 const u_char *tptr;
49
50 if (length < DTP_HEADER_LEN)
51 goto trunc;
52
53 tptr = pptr;
54
55 if (!ND_TTEST2(*tptr, DTP_HEADER_LEN))
56 goto trunc;
57
58 ND_PRINT((ndo, "DTPv%u, length %u",
59 (*tptr),
60 length));
61
62 /*
63 * In non-verbose mode, just print version.
64 */
65 if (ndo->ndo_vflag < 1) {
66 return;
67 }
68
69 tptr += DTP_HEADER_LEN;
70
71 while (tptr < (pptr+length)) {
72
73 if (!ND_TTEST2(*tptr, 4))
74 goto trunc;
75
76 type = EXTRACT_16BITS(tptr);
77 len = EXTRACT_16BITS(tptr+2);
78
79 /* infinite loop check */
80 if (type == 0 || len == 0) {
81 return;
82 }
83
84 ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
85 tok2str(dtp_tlv_values, "Unknown", type),
86 type, len));
87
88 switch (type) {
89 case DTP_DOMAIN_TLV:
90 ND_PRINT((ndo, ", %s", tptr+4));
91 break;
92
93 case DTP_STATUS_TLV:
94 case DTP_DTP_TYPE_TLV:
95 ND_PRINT((ndo, ", 0x%x", *(tptr+4)));
96 break;
97
98 case DTP_NEIGHBOR_TLV:
99 ND_PRINT((ndo, ", %s", etheraddr_string(tptr+4)));
100 break;
101
102 default:
103 break;
104 }
105 tptr += len;
106 }
107
108 return;
109
110 trunc:
111 ND_PRINT((ndo, "[|dtp]"));
112 }
113
114 /*
115 * Local Variables:
116 * c-style: whitesmith
117 * c-basic-offset: 4
118 * End:
119 */