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