-
Notifications
You must be signed in to change notification settings - Fork 17
/
cdpsnarf.h
179 lines (160 loc) · 4.58 KB
/
cdpsnarf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* CDPSnarf CDP packet sniffer
* Copyright (C) 2006-2010 Tasos "Zapotek" Laskos
* <tasos.laskos@gmail.com>
* <zapotek@segfault.gr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef SNARF_H_
#define SNARF_H_
typedef struct _assoc_array {
int value;
const char *string;
} assoc_array;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#include "includes/oui.h"
//#include "includes/crc16/crc.c"
struct address {
int proto_type;
int proto_len;
int proto;
int address_len;
int address;
} *addresses;
// Type codes of the CDP TLV
#define TYPE_DEVICE_ID 0x0001 // supported
#define TYPE_ADDRESS 0x0002 // supported
#define TYPE_PORT_ID 0x0003 // supported
#define TYPE_CAPABILITIES 0x0004 // supported
#define TYPE_IOS_VERSION 0x0005 // supported
#define TYPE_PLATFORM 0x0006 // supported
#define TYPE_IP_PREFIX 0x0007 // supported but needs further testing
#define TYPE_PROTOCOL_HELLO 0x0008 // supported
#define TYPE_VTP_MGMT_DOMAIN 0x0009 // supported
#define TYPE_NATIVE_VLAN 0x000a // supported
#define TYPE_DUPLEX 0x000b // supported
/* 0x000c */
/* 0x000d */
#define TYPE_VOIP_VLAN_REPLY 0x000e
#define TYPE_VOIP_VLAN_QUERY 0x000f
#define TYPE_POWER 0x0010
#define TYPE_MTU 0x0011 // supported
#define TYPE_TRUST_BITMAP 0x0012 // supported
#define TYPE_UNTRUSTED_COS 0x0013 // supported
#define TYPE_SYSTEM_NAME 0x0014 // supported
#define TYPE_SYSTEM_OID 0x0015 // supported
#define TYPE_MANAGEMENT_ADDR 0x0016 // supported
#define TYPE_LOCATION 0x0017
#define TYPE_EXT_PORT_ID 0x0018
#define TYPE_POWER_REQUESTED 0x0019
#define TYPE_POWER_AVAILABLE 0x001a // not fully supported
#define TYPE_PORT_UNIDIR 0x001b
// the names of the above type codes in the same order
static const char* TYPE_NAMES[] = {
NULL,
"Device ID",
"Addresses" ,
"Port ID" ,
"Capabilities" ,
"Software version" ,
"Platform" ,
"IP Prefix/Gateway (used for ODR)" ,
"Protocol Hello" ,
"VTP Management Domain" ,
"Native VLAN" ,
"Duplex" ,
NULL,
NULL,
"VoIP VLAN Reply" ,
"VoIP VLAN Query" ,
"Power consumption" ,
"MTU",
"Trust Bitmap" ,
"Untrusted Port CoS" ,
"System Name" ,
"System Object ID" ,
"Management Address" ,
"Location" ,
"External Port-ID" ,
"Power Requested" ,
"Power Available" ,
"Port Unidirectional" ,
};
#define TYPE_HELLO_CLUSTER_MGMT 0x0112
static assoc_array type_hello_vals[] = {
{ TYPE_HELLO_CLUSTER_MGMT, "Cluster Management" },
{ 0, NULL }
};
#define MAC_OFFSET 6
// bytes the from the beginning of the packet used for Ethernet and LLC
#define ENCAP_OFFSET 22
// sizes of the type and length fields in the TLV structure
#define TLV_TYPE_SIZE 2
#define TLV_LENGTH_SIZE 2
// layer 2 protocol type available
char *PROTO_TYPES[] = {
"Uknown",
"NLPID",
"802.2"
};
// IDs of Layer 3 protocols
// NOTE: Keep these in order
double long PROTO[] = {
0x81,
0xCC,
0x86DD, // Cisco says 0x0800 for IPv6 although it is 86DD
0x6003,
0x809B,
0x8137,
0x80c4,
0x0600,
0x8019
};
// Layer 3 protocols used
// NOTE: Keep these in order
char PROTO_NAMES[][15] = {
"ISO CLNS",
"IP",
"IPv6",
"DECNET Phase IV",
"AppleTalk",
"Novell IPX",
"Banyan VINES",
"XNS",
"Apollo Domain"
};
// bit masks for each available capability
int CAPABILITIES[] = {
0x01,
0x02,
0x04,
0x08,
0x10,
0x20,
0x40
};
// capability names
char CAPABILITIES_NAMES[7][19] = {
"Router",
"Transparent bridge",
"Source Route Bridge",
"Switch",
"Host",
"IGMP",
"Repeater"
};
#endif /*SNARF_H_*/