1 /* 2 * This file is part of the libusi++ packet capturing/sending framework. 3 * 4 * (C) 2000-2015 by Sebastian Krahmer, 5 * sebastian [dot] krahmer [at] gmail [dot] com 6 * 7 * libusi++ 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 3 of the License, or 10 * (at your option) any later version. 11 * 12 * libusi++ 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 18 * along with psc. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 // include this if you want uppercase enums for compatibility 22 23 #ifndef usipp_usi_structs_compat_h 24 #define usipp_usi_structs_compat_h 25 26 27 /* putting an own version of 28 * iphdr, udphdr, tcphdr, icmphdr and pseudohdr 29 * in usipp namespace to avoid collision with 30 * kernel ones. Mostly the IP etc. structs from system to system differ 31 * and are often broken. Some of this was just copied from standard .h files, 32 * but changed to an enum rather than a define. 33 */ 34 35 namespace usipp { 36 37 38 enum { 39 MAXHOSTLEN = 1000, 40 ETH_ALEN = 6, 41 ETH_A_LEN = 6 42 }; 43 44 45 /* 46 * These are the defined Ethernet Protocol ID's. 47 */ 48 enum { 49 ETH_P_LOOP = 0x0060, // Ethernet Loopback packet 50 ETH_P_ECHO = 0x0200, // Ethernet Echo packet 51 ETH_P_PUP = 0x0400, // Xerox PUP packet 52 ETH_P_IP = 0x0800, // Internet Protocol packet 53 ETH_P_X25 = 0x0805, // CCITT X.25 54 ETH_P_ARP = 0x0806, // Address Resolution packet 55 ETH_P_BPQ = 0x08FF, // G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] 56 ETH_P_DEC = 0x6000, // DEC Assigned proto 57 ETH_P_DNA_DL = 0x6001, // DEC DNA Dump/Load 58 ETH_P_DNA_RC = 0x6002, // DEC DNA Remote Console 59 ETH_P_DNA_RT = 0x6003, // DEC DNA Routing 60 ETH_P_LAT = 0x6004, // DEC LAT 61 ETH_P_DIAG = 0x6005, // DEC Diagnostics 62 ETH_P_CUST = 0x6006, // DEC Customer use 63 ETH_P_SCA = 0x6007, // DEC Systems Comms Arch 64 ETH_P_RARP = 0x8035, // Reverse Addr Res packet 65 ETH_P_ATALK = 0x809B, // Appletalk DDP 66 ETH_P_AARP = 0x80F3, // Appletalk AARP 67 ETH_P_IPX = 0x8137, // IPX over DIX 68 ETH_P_IPV6 = 0x86DD, // IPv6 over bluebook 69 ETH_P_EAPOL = 0x888E, // 802.1x EAP over LAN 70 ETH_P_PAE = ETH_P_EAPOL, // Port Access Entry 71 ETH_P_PRE_AUTH = 0x88C7, // WPA2 pre auth 72 73 /* 74 * Non DIX types. Won't clash for 1500 types. 75 */ 76 77 ETH_P_802_3 = 0x0001, // Dummy type for 802.3 frames 78 ETH_P_AX25 = 0x0002, // Dummy protocol id for AX.25 79 ETH_P_ALL = 0x0003, // Every packet (be careful!!!) 80 ETH_P_802_2 = 0x0004, // 802.2 frames 81 ETH_P_SNAP = 0x0005, // Internal only 82 ETH_P_DDCMP = 0x0006, // DEC DDCMP: Internal only 83 ETH_P_WAN_PPP = 0x0007, // Dummy type for WAN PPP frames 84 ETH_P_PPP_MP = 0x0008, // Dummy type for PPP MP frames 85 ETH_P_LOCALTALK = 0x0009, // Localtalk pseudo type 86 ETH_P_PPPTALK = 0x0010, // Dummy type for Atalk over PPP 87 ETH_P_TR_802_2 = 0x0011, // 802.2 frames 88 ETH_P_MOBITEX = 0x0015, // Mobitex (kaz@cafe.net) 89 ETH_P_CONTROL = 0x0016, // Card specific control frames 90 ETH_P_IRDA = 0x0017 // Linux/IR 91 }; 92 93 94 /* ARP protocol opcodes. */ 95 enum { 96 ARPOP_REQUEST = 1, // ARP request. 97 ARPOP_REPLY = 2, // ARP reply. 98 ARPOP_RREQUEST= 3, // RARP request. 99 ARPOP_RREPLY = 4, // RARP reply. 100 }; 101 102 103 /* ARP protocol HARDWARE identifiers. */ 104 enum { 105 ARPHRD_NETROM = 0, // From KA9Q: NET/ROM pseudo. 106 ARPHRD_ETHER = 1, // Ethernet 10/100Mbps. 107 ARPHRD_EETHER = 2, // Experimental Ethernet. 108 ARPHRD_AX25 = 3, // AX.25 Level 2. 109 ARPHRD_PRONET = 4, // PROnet token ring. 110 ARPHRD_CHAOS = 5, // Chaosnet. 111 ARPHRD_IEEE802 = 6, // IEEE 802.2 Ethernet/TR/TB. 112 ARPHRD_ARCNET = 7, // ARCnet. 113 ARPHRD_APPLETLK = 8, // APPLEtalk. 114 ARPHRD_DLCI = 15, // Frame Relay DLCI. 115 ARPHRD_METRICOM = 23, // Metricom STRIP (new IANA id). 116 117 /* Dummy types for non ARP hardware */ 118 ARPHRD_SLIP = 256, 119 ARPHRD_CSLIP = 257, 120 ARPHRD_SLIP6 = 258, 121 ARPHRD_CSLIP6 = 259, 122 ARPHRD_RSRVD = 260, /* Notional KISS type. */ 123 ARPHRD_ADAPT = 264, 124 ARPHRD_ROSE = 270, 125 ARPHRD_X25 = 271, /* CCITT X.25. */ 126 ARPHRD_PPP = 512, 127 ARPHRD_HDLC = 513, /* (Cisco) HDLC. */ 128 ARPHRD_LAPB = 516, /* LAPB. */ 129 130 ARPHRD_TUNNEL = 768, /* IPIP tunnel. */ 131 ARPHRD_TUNNEL6 = 769, /* IPIP6 tunnel. */ 132 ARPHRD_FRAD = 770, /* Frame Relay Access Device. */ 133 ARPHRD_SKIP = 771, /* SKIP vif. */ 134 ARPHRD_LOOPBACK = 772, /* Loopback device. */ 135 ARPHRD_LOCALTLK = 773, /* Localtalk device. */ 136 ARPHRD_FDDI = 774, /* Fiber Distributed Data Interface. */ 137 ARPHRD_BIF = 775, /* AP1000 BIF. */ 138 ARPHRD_SIT = 776, /* sit0 device - IPv6-in-IPv4. */ 139 ARPHRD_IPDDP = 777, /* IP-in-DDP tunnel. */ 140 ARPHRD_IPGRE = 778, /* GRE over IP. */ 141 ARPHRD_PIMREG = 779, /* PIMSM register interface. */ 142 ARPHRD_HIPPI = 780, /* High Performance Parallel I'face. */ 143 ARPHRD_ASH = 781, /* (Nexus Electronics) Ash. */ 144 ARPHRD_ECONET = 782, /* Acorn Econet. */ 145 ARPHRD_IRDA = 783, /* Linux/IR. */ 146 ARPHRD_FCPP = 784, /* Point to point fibrechanel. */ 147 ARPHRD_FCAL = 785, /* Fibrechanel arbitrated loop. */ 148 ARPHRD_FCPL = 786, /* Fibrechanel public loop. */ 149 ARPHRD_FCPFABRIC = 787 /* Fibrechanel fabric. */ 150 }; 151 152 153 enum { 154 ICMP_ECHOREPLY = 0, // Echo Reply 155 ICMP_DEST_UNREACH = 3, // Destination Unreachable 156 ICMP_SOURCE_QUENCH = 4, // Source Quench 157 ICMP_REDIRECT = 5, // Redirect (change route) 158 ICMP_ECHO = 8, // Echo Request 159 ICMP_TIME_EXCEEDED = 11, // Time Exceeded 160 ICMP_PARAMETERPROB = 12, // Parameter Problem 161 ICMP_TIMESTAMP = 13, // Timestamp Request 162 ICMP_TIMESTAMPREPLY= 14, // Timestamp Reply 163 ICMP_INFO_REQUEST = 15, // Information Request 164 ICMP_INFO_REPLY = 16, // Information Reply 165 ICMP_ADDRESS = 17, // Address Mask Reques 166 ICMP_ADDRESSREPLY = 18, // Address Mask Reply 167 NR_ICMP_TYPES = 18 168 }; 169 170 171 // Codes for UNREACH. 172 enum { 173 ICMP_NET_UNREACH = 0, // Network Unreachable 174 ICMP_HOST_UNREACH = 1, // Host Unreachable 175 ICMP_PROT_UNREACH = 2, // Protocol Unreachable 176 ICMP_PORT_UNREACH = 3, // Port Unreachable 177 ICMP_FRAG_NEEDED = 4, // Fragmentation Needed/DF set 178 ICMP_SR_FAILED = 5, // Source Route failed 179 ICMP_NET_UNKNOWN = 6, 180 ICMP_HOST_UNKNOWN = 7, 181 ICMP_HOST_ISOLATED = 8, 182 ICMP_NET_ANO = 9, 183 ICMP_HOST_ANO = 10, 184 ICMP_NET_UNR_TOS = 11, 185 ICMP_HOST_UNR_TOS = 12, 186 ICMP_PKT_FILTERED = 13, // Packet filtered 187 ICMP_PREC_VIOLATION = 14, // Precedence violation 188 ICMP_PREC_CUTOFF = 15, // Precedence cut off 189 NR_ICMP_UNREACH = 15 // instead of hardcoding immediate value 190 }; 191 192 193 // Codes for REDIRECT. 194 enum { 195 ICMP_REDIR_NET = 0, // Redirect Net 196 ICMP_REDIR_HOST = 1, // Redirect Host 197 ICMP_REDIR_NETTOS = 2, // Redirect Net for TOS 198 ICMP_REDIR_HOSTTOS = 3 // Redirect Host for TOS 199 }; 200 201 202 // Codes for TIME_EXCEEDED. 203 enum { 204 ICMP_EXC_TTL = 0, // TTL count exceeded 205 ICMP_EXC_FRAGTIME = 1 // Fragment Reass time exceeded 206 }; 207 208 209 enum { 210 TH_FIN = 0x001, 211 TH_SYN = 0x002, 212 TH_RST = 0x004, 213 TH_PUSH = 0x008, 214 TH_ACK = 0x010, 215 TH_URG = 0x020, 216 TH_ECE = 0x040, 217 TH_CWR = 0x080, 218 TH_NS = 0x100 219 }; 220 221 222 enum { 223 IP_RF = 0x8000, 224 IP_DF = 0x4000, 225 IP_MF = 0x2000, 226 IP_OFFMASK = 0x1fff 227 }; 228 229 230 enum { 231 TCPOPT_EOL = 0, 232 TCPOPT_NOP = 1, 233 TCPOPT_MAXSEG = 2, 234 TCPOLEN_MAXSEG = 4, 235 TCPOPT_WINDOW = 3, 236 TCPOLEN_WINDOW = 3, 237 TCPOPT_SACK_PERMITTED = 4, // Experimental 238 TCPOLEN_SACK_PERMITTED= 2, 239 TCPOPT_SACK = 5, // Experimental 240 TCPOPT_TIMESTAMP = 8, 241 TCPOLEN_TIMESTAMP = 10, 242 TCPOLEN_TSTAMP_APPA = (TCPOLEN_TIMESTAMP+2) // appendix A 243 }; 244 245 246 enum { 247 IPV6_FL_A_GET = 0, 248 IPV6_FL_A_PUT = 1, 249 IPV6_FL_A_RENEW = 2, 250 IPV6_FL_F_CREATE = 1, 251 IPV6_FL_F_EXCL = 2, 252 IPV6_FL_S_NONE = 0, 253 IPV6_FL_S_EXCL = 1, 254 IPV6_FL_S_PROCESS = 2, 255 IPV6_FL_S_USER = 3, 256 IPV6_FL_S_ANY = 255 257 }; 258 259 260 261 /* 262 * Bitmask constant declarations to help applications select out the 263 * flow label and priority fields. 264 * 265 * Note that this are in host byte order while the flowinfo field of 266 * sockaddr_in6 is in network byte order. 267 */ 268 269 enum { 270 IPV6_FLOWINFO_FLOWLABEL = 0x000fffff, 271 IPV6_FLOWINFO_PRIORITY = 0x0ff00000 272 }; 273 274 275 /* 276 * IPv6 TLV options. 277 */ 278 enum { 279 IPV6_TLV_PAD0 = 0, 280 IPV6_TLV_PADN = 1, 281 IPV6_TLV_ROUTERALERT = 5, 282 IPV6_TLV_JUMBO = 194 283 }; 284 285 286 287 // icmp6 types and options 288 enum { 289 ICMP6_DST_UNREACH = 1, 290 ICMP6_PACKET_TOO_BIG = 2, 291 ICMP6_TIME_EXCEEDED = 3, 292 ICMP6_PARAM_PROB = 4, 293 294 ICMP6_INFOMSG_MASK = 0x80, // all informational messages 295 296 ICMP6_ECHO_REQUEST = 128, 297 ICMP6_ECHO_REPLY = 129, 298 ICMP6_MEMBERSHIP_QUERY = 130, 299 ICMP6_MEMBERSHIP_REPORT = 131, 300 ICMP6_MEMBERSHIP_REDUCTION = 132, 301 302 ICMP6_DST_UNREACH_NOROUTE = 0, // no route to destination 303 ICMP6_DST_UNREACH_ADMIN = 1, // communication with destination 304 // administratively prohibited 305 ICMP6_DST_UNREACH_NOTNEIGHBOR = 2, // not a neighbor 306 ICMP6_DST_UNREACH_ADDR = 3, // address unreachable 307 ICMP6_DST_UNREACH_NOPORT = 4, // bad port 308 309 ICMP6_TIME_EXCEED_TRANSIT = 0, // Hop Limit == 0 in transit 310 ICMP6_TIME_EXCEED_REASSEMBLY = 1, // Reassembly time out 311 312 ICMP6_PARAMPROB_HEADER = 0, // erroneous header field 313 ICMP6_PARAMPROB_NEXTHEADER = 1, // unrecognized Next Header 314 ICMP6_PARAMPROB_OPTION = 2, // unrecognized IPv6 option 315 316 ICMP6_ND_ROUTER_SOLICIT = 133, 317 ICMP6_ND_ROUTER_ADVERT = 134, 318 ICMP6_ND_NEIGHBOR_SOLICIT = 135, 319 ICMP6_ND_NEIGHBOR_ADVERT = 136, 320 ICMP6_ND_REDIRECT = 137, 321 322 ND_OPT_SOURCE_LL_ADDR = 1, 323 ND_OPT_TARGET_LL_ADDR = 2, 324 ND_OPT_PREFIX_INFO = 3, 325 ND_OPT_REDIRECT_HDR = 4, 326 ND_OPT_MTU = 5, 327 ND_OPT_ROUTE_INFO = 24, 328 ND_OPT_RDNSS = 25, 329 ND_OPT_DNSSL = 31 330 }; 331 332 333 enum { 334 NEXT_HDR_HBH = 0, // hop by hop 335 NEXT_HDR_RH = 43, // routing header 336 NEXT_HDR_FH = 44, // fragmentation header 337 NEXT_HDR_DOH = 60, // destination option 338 NEXT_HDR_MOB = 135 // mobility header 339 }; 340 341 342 enum { 343 TX_TAG_NONE = 0, 344 RX_TAG_NONE = 0, 345 346 TX_TAG_IP = 0x1000, 347 TX_TAG_IP6, 348 TX_TAG_DNET_IP, 349 TX_TAG_DNET_ETH, 350 TX_TAG_PCAP, 351 TX_TAG_PCAP_ETH, 352 TX_TAG_STRING, 353 354 RX_TAG_PCAP = 0x2000 355 }; 356 357 358 // IANA assigned protocol numbers. OSX defines them in in.h so we need to #ifdef around it 359 enum { 360 #ifndef IPPROTO_IP 361 IPPROTO_IP = 0, 362 #endif 363 #ifndef IPPROTO_HOPOPTS 364 IPPROTO_HOPOPTS = 0, /* IPv6 Hop-by-Hop options. */ 365 #endif 366 #ifndef IPPROTO_ICMP 367 IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */ 368 #endif 369 #ifndef IPPROTO_IGMP 370 IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */ 371 #endif 372 #ifndef IPPROTO_IPIP 373 IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94). */ 374 #endif 375 #ifndef IPPROTO_TCP 376 IPPROTO_TCP = 6, /* Transmission Control Protocol. */ 377 #endif 378 #ifndef IPPROTO_EGP 379 IPPROTO_EGP = 8, /* Exterior Gateway Protocol. */ 380 #endif 381 #ifndef IPPROTO_PUP 382 IPPROTO_PUP = 12, /* PUP protocol. */ 383 #endif 384 #ifndef IPPROTO_UDP 385 IPPROTO_UDP = 17, /* User Datagram Protocol. */ 386 #endif 387 #ifndef IPPROTO_IDP 388 IPPROTO_IDP = 22, /* XNS IDP protocol. */ 389 #endif 390 #ifndef IPPROTO_TP 391 IPPROTO_TP = 29, /* SO Transport Protocol Class 4. */ 392 #endif 393 #ifndef IPPROTO_DCCP 394 IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol. */ 395 #endif 396 #ifndef IPPROTO_IPV6 397 IPPROTO_IPV6 = 41, /* IPv6 header. */ 398 #endif 399 #ifndef IPPROTO_ROUTING 400 IPPROTO_ROUTING = 43, /* IPv6 routing header. */ 401 #endif 402 #ifndef IPPROTO_FRAGMENT 403 IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header. */ 404 #endif 405 #ifndef IPPROTO_RSVP 406 IPPROTO_RSVP = 46, /* Reservation Protocol. */ 407 #endif 408 #ifndef IPPROTO_GRE 409 IPPROTO_GRE = 47, /* General Routing Encapsulation. */ 410 #endif 411 #ifndef IPPROTO_ESP 412 IPPROTO_ESP = 50, /* encapsulating security payload. */ 413 #endif 414 #ifndef IPPROTO_AH 415 IPPROTO_AH = 51, /* authentication header. */ 416 #endif 417 #ifndef IPPROTO_ICMPV6 418 IPPROTO_ICMPV6 = 58, /* ICMPv6. */ 419 #endif 420 #ifndef IPPROTO_NONE 421 IPPROTO_NONE = 59, /* IPv6 no next header. */ 422 #endif 423 #ifndef IPPROTO_DSTOPTS 424 IPPROTO_DSTOPTS = 60, /* IPv6 destination options. */ 425 #endif 426 #ifndef IPPROTO_MTP 427 IPPROTO_MTP = 92, /* Multicast Transport Protocol. */ 428 #endif 429 #ifndef IPPROTO_IPIP 430 IPOROTO_IPIP = 94, /* IP in IP encapsulation */ 431 #endif 432 #ifndef IPPROTO_ENCAP 433 IPPROTO_ENCAP = 98, /* Encapsulation Header. */ 434 #endif 435 #ifndef IPPROTO_PIM 436 IPPROTO_PIM = 103, /* Protocol Independent Multicast. */ 437 #endif 438 #ifndef IPPROTO_COMP 439 IPPROTO_COMP = 108, /* Compression Header Protocol. */ 440 #endif 441 #ifndef IPPROTO_SCTP 442 IPPROTO_SCTP = 132, /* Stream Control Transmission Protocol. */ 443 #endif 444 #ifndef IPPROTO_UDPLITE 445 IPPROTO_UDPLITE = 136, /* UDP-Lite protocol. */ 446 #endif 447 //IPPROTO_RAW = 255, /* Raw IP packets, use OS, its not a packet protocol */ 448 449 IPPROTO_USIPP = 255 /* dummy to have at least one enum */ 450 }; 451 452 453 454 } // namespace usipp 455 456 457 #endif 458 459