1214455Srpaulo/* 2214455Srpaulo * Copyright (c) 1993, 1994, 1995, 1996, 1997 3214455Srpaulo * The Regents of the University of California. All rights reserved. 4214455Srpaulo * 5214455Srpaulo * Redistribution and use in source and binary forms, with or without 6214455Srpaulo * modification, are permitted provided that: (1) source code distributions 7214455Srpaulo * retain the above copyright notice and this paragraph in its entirety, (2) 8214455Srpaulo * distributions including binary code include the above copyright notice and 9214455Srpaulo * this paragraph in its entirety in the documentation or other materials 10214455Srpaulo * provided with the distribution, and (3) all advertising materials mentioning 11214455Srpaulo * features or use of this software display the following acknowledgement: 12214455Srpaulo * ``This product includes software developed by the University of California, 13214455Srpaulo * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14214455Srpaulo * the University nor the names of its contributors may be used to endorse 15214455Srpaulo * or promote products derived from this software without specific prior 16214455Srpaulo * written permission. 17214455Srpaulo * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18214455Srpaulo * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19214455Srpaulo * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20214455Srpaulo * 21235426Sdelphij * pcap-common.c - common code for pcap and pcap-ng files 22214455Srpaulo */ 23214455Srpaulo 24214455Srpaulo#ifdef HAVE_CONFIG_H 25214455Srpaulo#include "config.h" 26214455Srpaulo#endif 27214455Srpaulo 28214455Srpaulo#ifdef WIN32 29214455Srpaulo#include <pcap-stdinc.h> 30214455Srpaulo#else /* WIN32 */ 31214455Srpaulo#if HAVE_INTTYPES_H 32214455Srpaulo#include <inttypes.h> 33214455Srpaulo#elif HAVE_STDINT_H 34214455Srpaulo#include <stdint.h> 35214455Srpaulo#endif 36214455Srpaulo#ifdef HAVE_SYS_BITYPES_H 37214455Srpaulo#include <sys/bitypes.h> 38214455Srpaulo#endif 39214455Srpaulo#include <sys/types.h> 40214455Srpaulo#endif /* WIN32 */ 41214455Srpaulo 42214455Srpaulo#include "pcap-int.h" 43214455Srpaulo#include "pcap/usb.h" 44276768Sdelphij#include "pcap/nflog.h" 45214455Srpaulo 46214455Srpaulo#include "pcap-common.h" 47214455Srpaulo 48214455Srpaulo/* 49214455Srpaulo * We don't write DLT_* values to capture files, because they're not the 50214455Srpaulo * same on all platforms. 51214455Srpaulo * 52214455Srpaulo * Unfortunately, the various flavors of BSD have not always used the same 53214455Srpaulo * numerical values for the same data types, and various patches to 54214455Srpaulo * libpcap for non-BSD OSes have added their own DLT_* codes for link 55214455Srpaulo * layer encapsulation types seen on those OSes, and those codes have had, 56214455Srpaulo * in some cases, values that were also used, on other platforms, for other 57214455Srpaulo * link layer encapsulation types. 58214455Srpaulo * 59214455Srpaulo * This means that capture files of a type whose numerical DLT_* code 60214455Srpaulo * means different things on different BSDs, or with different versions 61214455Srpaulo * of libpcap, can't always be read on systems other than those like 62214455Srpaulo * the one running on the machine on which the capture was made. 63214455Srpaulo * 64214455Srpaulo * Instead, we define here a set of LINKTYPE_* codes, and map DLT_* codes 65214455Srpaulo * to LINKTYPE_* codes when writing a savefile header, and map LINKTYPE_* 66214455Srpaulo * codes to DLT_* codes when reading a savefile header. 67214455Srpaulo * 68214455Srpaulo * For those DLT_* codes that have, as far as we know, the same values on 69214455Srpaulo * all platforms (DLT_NULL through DLT_FDDI), we define LINKTYPE_xxx as 70214455Srpaulo * DLT_xxx; that way, captures of those types can still be read by 71214455Srpaulo * versions of libpcap that map LINKTYPE_* values to DLT_* values, and 72214455Srpaulo * captures of those types written by versions of libpcap that map DLT_ 73214455Srpaulo * values to LINKTYPE_ values can still be read by older versions 74214455Srpaulo * of libpcap. 75214455Srpaulo * 76214455Srpaulo * The other LINKTYPE_* codes are given values starting at 100, in the 77214455Srpaulo * hopes that no DLT_* code will be given one of those values. 78214455Srpaulo * 79214455Srpaulo * In order to ensure that a given LINKTYPE_* code's value will refer to 80214455Srpaulo * the same encapsulation type on all platforms, you should not allocate 81214455Srpaulo * a new LINKTYPE_* value without consulting 82214455Srpaulo * "tcpdump-workers@lists.tcpdump.org". The tcpdump developers will 83214455Srpaulo * allocate a value for you, and will not subsequently allocate it to 84214455Srpaulo * anybody else; that value will be added to the "pcap.h" in the 85214455Srpaulo * tcpdump.org Git repository, so that a future libpcap release will 86214455Srpaulo * include it. 87214455Srpaulo * 88214455Srpaulo * You should, if possible, also contribute patches to libpcap and tcpdump 89214455Srpaulo * to handle the new encapsulation type, so that they can also be checked 90214455Srpaulo * into the tcpdump.org Git repository and so that they will appear in 91214455Srpaulo * future libpcap and tcpdump releases. 92214455Srpaulo * 93214455Srpaulo * Do *NOT* assume that any values after the largest value in this file 94214455Srpaulo * are available; you might not have the most up-to-date version of this 95214455Srpaulo * file, and new values after that one might have been assigned. Also, 96214455Srpaulo * do *NOT* use any values below 100 - those might already have been 97214455Srpaulo * taken by one (or more!) organizations. 98235426Sdelphij * 99235426Sdelphij * Any platform that defines additional DLT_* codes should: 100235426Sdelphij * 101235426Sdelphij * request a LINKTYPE_* code and value from tcpdump.org, 102235426Sdelphij * as per the above; 103235426Sdelphij * 104235426Sdelphij * add, in their version of libpcap, an entry to map 105235426Sdelphij * those DLT_* codes to the corresponding LINKTYPE_* 106235426Sdelphij * code; 107235426Sdelphij * 108235426Sdelphij * redefine, in their "net/bpf.h", any DLT_* values 109235426Sdelphij * that collide with the values used by their additional 110235426Sdelphij * DLT_* codes, to remove those collisions (but without 111235426Sdelphij * making them collide with any of the LINKTYPE_* 112235426Sdelphij * values equal to 50 or above; they should also avoid 113235426Sdelphij * defining DLT_* values that collide with those 114235426Sdelphij * LINKTYPE_* values, either). 115214455Srpaulo */ 116214455Srpaulo#define LINKTYPE_NULL DLT_NULL 117214455Srpaulo#define LINKTYPE_ETHERNET DLT_EN10MB /* also for 100Mb and up */ 118214455Srpaulo#define LINKTYPE_EXP_ETHERNET DLT_EN3MB /* 3Mb experimental Ethernet */ 119214455Srpaulo#define LINKTYPE_AX25 DLT_AX25 120214455Srpaulo#define LINKTYPE_PRONET DLT_PRONET 121214455Srpaulo#define LINKTYPE_CHAOS DLT_CHAOS 122241231Sdelphij#define LINKTYPE_IEEE802_5 DLT_IEEE802 /* DLT_IEEE802 is used for 802.5 Token Ring */ 123235426Sdelphij#define LINKTYPE_ARCNET_BSD DLT_ARCNET /* BSD-style headers */ 124214455Srpaulo#define LINKTYPE_SLIP DLT_SLIP 125214455Srpaulo#define LINKTYPE_PPP DLT_PPP 126214455Srpaulo#define LINKTYPE_FDDI DLT_FDDI 127214455Srpaulo 128214455Srpaulo/* 129214455Srpaulo * LINKTYPE_PPP is for use when there might, or might not, be an RFC 1662 130214455Srpaulo * PPP in HDLC-like framing header (with 0xff 0x03 before the PPP protocol 131214455Srpaulo * field) at the beginning of the packet. 132214455Srpaulo * 133214455Srpaulo * This is for use when there is always such a header; the address field 134214455Srpaulo * might be 0xff, for regular PPP, or it might be an address field for Cisco 135214455Srpaulo * point-to-point with HDLC framing as per section 4.3.1 of RFC 1547 ("Cisco 136214455Srpaulo * HDLC"). This is, for example, what you get with NetBSD's DLT_PPP_SERIAL. 137214455Srpaulo * 138214455Srpaulo * We give it the same value as NetBSD's DLT_PPP_SERIAL, in the hopes that 139214455Srpaulo * nobody else will choose a DLT_ value of 50, and so that DLT_PPP_SERIAL 140214455Srpaulo * captures will be written out with a link type that NetBSD's tcpdump 141214455Srpaulo * can read. 142214455Srpaulo */ 143214455Srpaulo#define LINKTYPE_PPP_HDLC 50 /* PPP in HDLC-like framing */ 144214455Srpaulo 145214455Srpaulo#define LINKTYPE_PPP_ETHER 51 /* NetBSD PPP-over-Ethernet */ 146214455Srpaulo 147214455Srpaulo#define LINKTYPE_SYMANTEC_FIREWALL 99 /* Symantec Enterprise Firewall */ 148214455Srpaulo 149235426Sdelphij/* 150235426Sdelphij * These correspond to DLT_s that have different values on different 151235426Sdelphij * platforms; we map between these values in capture files and 152235426Sdelphij * the DLT_ values as returned by pcap_datalink() and passed to 153235426Sdelphij * pcap_open_dead(). 154235426Sdelphij */ 155214455Srpaulo#define LINKTYPE_ATM_RFC1483 100 /* LLC/SNAP-encapsulated ATM */ 156214455Srpaulo#define LINKTYPE_RAW 101 /* raw IP */ 157214455Srpaulo#define LINKTYPE_SLIP_BSDOS 102 /* BSD/OS SLIP BPF header */ 158214455Srpaulo#define LINKTYPE_PPP_BSDOS 103 /* BSD/OS PPP BPF header */ 159235426Sdelphij 160235426Sdelphij/* 161235426Sdelphij * Values starting with 104 are used for newly-assigned link-layer 162235426Sdelphij * header type values; for those link-layer header types, the DLT_ 163235426Sdelphij * value returned by pcap_datalink() and passed to pcap_open_dead(), 164235426Sdelphij * and the LINKTYPE_ value that appears in capture files, are the 165235426Sdelphij * same. 166235426Sdelphij * 167235426Sdelphij * LINKTYPE_MATCHING_MIN is the lowest such value; LINKTYPE_MATCHING_MAX 168235426Sdelphij * is the highest such value. 169235426Sdelphij */ 170235426Sdelphij#define LINKTYPE_MATCHING_MIN 104 /* lowest value in the "matching" range */ 171235426Sdelphij 172214455Srpaulo#define LINKTYPE_C_HDLC 104 /* Cisco HDLC */ 173214455Srpaulo#define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 (wireless) */ 174214455Srpaulo#define LINKTYPE_ATM_CLIP 106 /* Linux Classical IP over ATM */ 175214455Srpaulo#define LINKTYPE_FRELAY 107 /* Frame Relay */ 176214455Srpaulo#define LINKTYPE_LOOP 108 /* OpenBSD loopback */ 177214455Srpaulo#define LINKTYPE_ENC 109 /* OpenBSD IPSEC enc */ 178214455Srpaulo 179214455Srpaulo/* 180214455Srpaulo * These three types are reserved for future use. 181214455Srpaulo */ 182214455Srpaulo#define LINKTYPE_LANE8023 110 /* ATM LANE + 802.3 */ 183214455Srpaulo#define LINKTYPE_HIPPI 111 /* NetBSD HIPPI */ 184214455Srpaulo#define LINKTYPE_HDLC 112 /* NetBSD HDLC framing */ 185214455Srpaulo 186214455Srpaulo#define LINKTYPE_LINUX_SLL 113 /* Linux cooked socket capture */ 187214455Srpaulo#define LINKTYPE_LTALK 114 /* Apple LocalTalk hardware */ 188214455Srpaulo#define LINKTYPE_ECONET 115 /* Acorn Econet */ 189214455Srpaulo 190214455Srpaulo/* 191214455Srpaulo * Reserved for use with OpenBSD ipfilter. 192214455Srpaulo */ 193214455Srpaulo#define LINKTYPE_IPFILTER 116 194214455Srpaulo 195214455Srpaulo#define LINKTYPE_PFLOG 117 /* OpenBSD DLT_PFLOG */ 196214455Srpaulo#define LINKTYPE_CISCO_IOS 118 /* For Cisco-internal use */ 197241231Sdelphij#define LINKTYPE_IEEE802_11_PRISM 119 /* 802.11 plus Prism II monitor mode radio metadata header */ 198241231Sdelphij#define LINKTYPE_IEEE802_11_AIRONET 120 /* 802.11 plus FreeBSD Aironet driver radio metadata header */ 199214455Srpaulo 200214455Srpaulo/* 201214455Srpaulo * Reserved for Siemens HiPath HDLC. 202214455Srpaulo */ 203214455Srpaulo#define LINKTYPE_HHDLC 121 204214455Srpaulo 205214455Srpaulo#define LINKTYPE_IP_OVER_FC 122 /* RFC 2625 IP-over-Fibre Channel */ 206214455Srpaulo#define LINKTYPE_SUNATM 123 /* Solaris+SunATM */ 207214455Srpaulo 208214455Srpaulo/* 209214455Srpaulo * Reserved as per request from Kent Dahlgren <kent@praesum.com> 210214455Srpaulo * for private use. 211214455Srpaulo */ 212214455Srpaulo#define LINKTYPE_RIO 124 /* RapidIO */ 213214455Srpaulo#define LINKTYPE_PCI_EXP 125 /* PCI Express */ 214214455Srpaulo#define LINKTYPE_AURORA 126 /* Xilinx Aurora link layer */ 215214455Srpaulo 216241231Sdelphij#define LINKTYPE_IEEE802_11_RADIOTAP 127 /* 802.11 plus radiotap radio metadata header */ 217214455Srpaulo 218214455Srpaulo/* 219214455Srpaulo * Reserved for the TZSP encapsulation, as per request from 220214455Srpaulo * Chris Waters <chris.waters@networkchemistry.com> 221214455Srpaulo * TZSP is a generic encapsulation for any other link type, 222214455Srpaulo * which includes a means to include meta-information 223214455Srpaulo * with the packet, e.g. signal strength and channel 224214455Srpaulo * for 802.11 packets. 225214455Srpaulo */ 226214455Srpaulo#define LINKTYPE_TZSP 128 /* Tazmen Sniffer Protocol */ 227214455Srpaulo 228214455Srpaulo#define LINKTYPE_ARCNET_LINUX 129 /* Linux-style headers */ 229214455Srpaulo 230214455Srpaulo/* 231214455Srpaulo * Juniper-private data link types, as per request from 232214455Srpaulo * Hannes Gredler <hannes@juniper.net>. The corresponding 233214455Srpaulo * DLT_s are used for passing on chassis-internal 234214455Srpaulo * metainformation such as QOS profiles, etc.. 235214455Srpaulo */ 236214455Srpaulo#define LINKTYPE_JUNIPER_MLPPP 130 237214455Srpaulo#define LINKTYPE_JUNIPER_MLFR 131 238214455Srpaulo#define LINKTYPE_JUNIPER_ES 132 239214455Srpaulo#define LINKTYPE_JUNIPER_GGSN 133 240214455Srpaulo#define LINKTYPE_JUNIPER_MFR 134 241214455Srpaulo#define LINKTYPE_JUNIPER_ATM2 135 242214455Srpaulo#define LINKTYPE_JUNIPER_SERVICES 136 243214455Srpaulo#define LINKTYPE_JUNIPER_ATM1 137 244214455Srpaulo 245214455Srpaulo#define LINKTYPE_APPLE_IP_OVER_IEEE1394 138 /* Apple IP-over-IEEE 1394 cooked header */ 246214455Srpaulo 247214455Srpaulo#define LINKTYPE_MTP2_WITH_PHDR 139 248214455Srpaulo#define LINKTYPE_MTP2 140 249214455Srpaulo#define LINKTYPE_MTP3 141 250214455Srpaulo#define LINKTYPE_SCCP 142 251214455Srpaulo 252214455Srpaulo#define LINKTYPE_DOCSIS 143 /* DOCSIS MAC frames */ 253214455Srpaulo 254214455Srpaulo#define LINKTYPE_LINUX_IRDA 144 /* Linux-IrDA */ 255214455Srpaulo 256214455Srpaulo/* 257214455Srpaulo * Reserved for IBM SP switch and IBM Next Federation switch. 258214455Srpaulo */ 259214455Srpaulo#define LINKTYPE_IBM_SP 145 260214455Srpaulo#define LINKTYPE_IBM_SN 146 261214455Srpaulo 262214455Srpaulo/* 263214455Srpaulo * Reserved for private use. If you have some link-layer header type 264214455Srpaulo * that you want to use within your organization, with the capture files 265214455Srpaulo * using that link-layer header type not ever be sent outside your 266214455Srpaulo * organization, you can use these values. 267214455Srpaulo * 268214455Srpaulo * No libpcap release will use these for any purpose, nor will any 269214455Srpaulo * tcpdump release use them, either. 270214455Srpaulo * 271214455Srpaulo * Do *NOT* use these in capture files that you expect anybody not using 272214455Srpaulo * your private versions of capture-file-reading tools to read; in 273214455Srpaulo * particular, do *NOT* use them in products, otherwise you may find that 274214455Srpaulo * people won't be able to use tcpdump, or snort, or Ethereal, or... to 275214455Srpaulo * read capture files from your firewall/intrusion detection/traffic 276214455Srpaulo * monitoring/etc. appliance, or whatever product uses that LINKTYPE_ value, 277214455Srpaulo * and you may also find that the developers of those applications will 278214455Srpaulo * not accept patches to let them read those files. 279214455Srpaulo * 280214455Srpaulo * Also, do not use them if somebody might send you a capture using them 281214455Srpaulo * for *their* private type and tools using them for *your* private type 282214455Srpaulo * would have to read them. 283214455Srpaulo * 284214455Srpaulo * Instead, in those cases, ask "tcpdump-workers@lists.tcpdump.org" for a 285214455Srpaulo * new DLT_ and LINKTYPE_ value, as per the comment in pcap/bpf.h, and use 286214455Srpaulo * the type you're given. 287214455Srpaulo */ 288214455Srpaulo#define LINKTYPE_USER0 147 289214455Srpaulo#define LINKTYPE_USER1 148 290214455Srpaulo#define LINKTYPE_USER2 149 291214455Srpaulo#define LINKTYPE_USER3 150 292214455Srpaulo#define LINKTYPE_USER4 151 293214455Srpaulo#define LINKTYPE_USER5 152 294214455Srpaulo#define LINKTYPE_USER6 153 295214455Srpaulo#define LINKTYPE_USER7 154 296214455Srpaulo#define LINKTYPE_USER8 155 297214455Srpaulo#define LINKTYPE_USER9 156 298214455Srpaulo#define LINKTYPE_USER10 157 299214455Srpaulo#define LINKTYPE_USER11 158 300214455Srpaulo#define LINKTYPE_USER12 159 301214455Srpaulo#define LINKTYPE_USER13 160 302214455Srpaulo#define LINKTYPE_USER14 161 303214455Srpaulo#define LINKTYPE_USER15 162 304214455Srpaulo 305214455Srpaulo/* 306214455Srpaulo * For future use with 802.11 captures - defined by AbsoluteValue 307214455Srpaulo * Systems to store a number of bits of link-layer information 308214455Srpaulo * including radio information: 309214455Srpaulo * 310214455Srpaulo * http://www.shaftnet.org/~pizza/software/capturefrm.txt 311214455Srpaulo */ 312241231Sdelphij#define LINKTYPE_IEEE802_11_AVS 163 /* 802.11 plus AVS radio metadata header */ 313214455Srpaulo 314214455Srpaulo/* 315214455Srpaulo * Juniper-private data link type, as per request from 316214455Srpaulo * Hannes Gredler <hannes@juniper.net>. The corresponding 317214455Srpaulo * DLT_s are used for passing on chassis-internal 318214455Srpaulo * metainformation such as QOS profiles, etc.. 319214455Srpaulo */ 320214455Srpaulo#define LINKTYPE_JUNIPER_MONITOR 164 321214455Srpaulo 322214455Srpaulo/* 323241231Sdelphij * BACnet MS/TP frames. 324214455Srpaulo */ 325214455Srpaulo#define LINKTYPE_BACNET_MS_TP 165 326214455Srpaulo 327214455Srpaulo/* 328214455Srpaulo * Another PPP variant as per request from Karsten Keil <kkeil@suse.de>. 329214455Srpaulo * 330214455Srpaulo * This is used in some OSes to allow a kernel socket filter to distinguish 331214455Srpaulo * between incoming and outgoing packets, on a socket intended to 332214455Srpaulo * supply pppd with outgoing packets so it can do dial-on-demand and 333214455Srpaulo * hangup-on-lack-of-demand; incoming packets are filtered out so they 334214455Srpaulo * don't cause pppd to hold the connection up (you don't want random 335214455Srpaulo * input packets such as port scans, packets from old lost connections, 336214455Srpaulo * etc. to force the connection to stay up). 337214455Srpaulo * 338214455Srpaulo * The first byte of the PPP header (0xff03) is modified to accomodate 339214455Srpaulo * the direction - 0x00 = IN, 0x01 = OUT. 340214455Srpaulo */ 341214455Srpaulo#define LINKTYPE_PPP_PPPD 166 342214455Srpaulo 343214455Srpaulo/* 344214455Srpaulo * Juniper-private data link type, as per request from 345214455Srpaulo * Hannes Gredler <hannes@juniper.net>. The DLT_s are used 346214455Srpaulo * for passing on chassis-internal metainformation such as 347214455Srpaulo * QOS profiles, cookies, etc.. 348214455Srpaulo */ 349214455Srpaulo#define LINKTYPE_JUNIPER_PPPOE 167 350214455Srpaulo#define LINKTYPE_JUNIPER_PPPOE_ATM 168 351214455Srpaulo 352214455Srpaulo#define LINKTYPE_GPRS_LLC 169 /* GPRS LLC */ 353214455Srpaulo#define LINKTYPE_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */ 354214455Srpaulo#define LINKTYPE_GPF_F 171 /* GPF-T (ITU-T G.7041/Y.1303) */ 355214455Srpaulo 356214455Srpaulo/* 357214455Srpaulo * Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line 358214455Srpaulo * monitoring equipment. 359214455Srpaulo */ 360214455Srpaulo#define LINKTYPE_GCOM_T1E1 172 361214455Srpaulo#define LINKTYPE_GCOM_SERIAL 173 362214455Srpaulo 363214455Srpaulo/* 364214455Srpaulo * Juniper-private data link type, as per request from 365214455Srpaulo * Hannes Gredler <hannes@juniper.net>. The DLT_ is used 366214455Srpaulo * for internal communication to Physical Interface Cards (PIC) 367214455Srpaulo */ 368214455Srpaulo#define LINKTYPE_JUNIPER_PIC_PEER 174 369214455Srpaulo 370214455Srpaulo/* 371214455Srpaulo * Link types requested by Gregor Maier <gregor@endace.com> of Endace 372214455Srpaulo * Measurement Systems. They add an ERF header (see 373214455Srpaulo * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of 374214455Srpaulo * the link-layer header. 375214455Srpaulo */ 376214455Srpaulo#define LINKTYPE_ERF_ETH 175 /* Ethernet */ 377214455Srpaulo#define LINKTYPE_ERF_POS 176 /* Packet-over-SONET */ 378214455Srpaulo 379214455Srpaulo/* 380214455Srpaulo * Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD 381214455Srpaulo * for vISDN (http://www.orlandi.com/visdn/). Its link-layer header 382214455Srpaulo * includes additional information before the LAPD header, so it's 383214455Srpaulo * not necessarily a generic LAPD header. 384214455Srpaulo */ 385214455Srpaulo#define LINKTYPE_LINUX_LAPD 177 386214455Srpaulo 387214455Srpaulo/* 388214455Srpaulo * Juniper-private data link type, as per request from 389214455Srpaulo * Hannes Gredler <hannes@juniper.net>. 390214455Srpaulo * The Link Types are used for prepending meta-information 391214455Srpaulo * like interface index, interface name 392214455Srpaulo * before standard Ethernet, PPP, Frelay & C-HDLC Frames 393214455Srpaulo */ 394214455Srpaulo#define LINKTYPE_JUNIPER_ETHER 178 395214455Srpaulo#define LINKTYPE_JUNIPER_PPP 179 396214455Srpaulo#define LINKTYPE_JUNIPER_FRELAY 180 397214455Srpaulo#define LINKTYPE_JUNIPER_CHDLC 181 398214455Srpaulo 399214455Srpaulo/* 400214455Srpaulo * Multi Link Frame Relay (FRF.16) 401214455Srpaulo */ 402214455Srpaulo#define LINKTYPE_MFR 182 403214455Srpaulo 404214455Srpaulo/* 405214455Srpaulo * Juniper-private data link type, as per request from 406214455Srpaulo * Hannes Gredler <hannes@juniper.net>. 407214455Srpaulo * The DLT_ is used for internal communication with a 408214455Srpaulo * voice Adapter Card (PIC) 409214455Srpaulo */ 410214455Srpaulo#define LINKTYPE_JUNIPER_VP 183 411214455Srpaulo 412214455Srpaulo/* 413214455Srpaulo * Arinc 429 frames. 414214455Srpaulo * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>. 415214455Srpaulo * Every frame contains a 32bit A429 label. 416214455Srpaulo * More documentation on Arinc 429 can be found at 417214455Srpaulo * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf 418214455Srpaulo */ 419214455Srpaulo#define LINKTYPE_A429 184 420214455Srpaulo 421214455Srpaulo/* 422214455Srpaulo * Arinc 653 Interpartition Communication messages. 423214455Srpaulo * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>. 424214455Srpaulo * Please refer to the A653-1 standard for more information. 425214455Srpaulo */ 426214455Srpaulo#define LINKTYPE_A653_ICM 185 427214455Srpaulo 428214455Srpaulo/* 429214455Srpaulo * USB packets, beginning with a USB setup header; requested by 430214455Srpaulo * Paolo Abeni <paolo.abeni@email.it>. 431214455Srpaulo */ 432214455Srpaulo#define LINKTYPE_USB 186 433214455Srpaulo 434214455Srpaulo/* 435214455Srpaulo * Bluetooth HCI UART transport layer (part H:4); requested by 436214455Srpaulo * Paolo Abeni. 437214455Srpaulo */ 438214455Srpaulo#define LINKTYPE_BLUETOOTH_HCI_H4 187 439214455Srpaulo 440214455Srpaulo/* 441214455Srpaulo * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz 442214455Srpaulo * <cruz_petagay@bah.com>. 443214455Srpaulo */ 444214455Srpaulo#define LINKTYPE_IEEE802_16_MAC_CPS 188 445214455Srpaulo 446214455Srpaulo/* 447214455Srpaulo * USB packets, beginning with a Linux USB header; requested by 448214455Srpaulo * Paolo Abeni <paolo.abeni@email.it>. 449214455Srpaulo */ 450214455Srpaulo#define LINKTYPE_USB_LINUX 189 451214455Srpaulo 452214455Srpaulo/* 453214455Srpaulo * Controller Area Network (CAN) v. 2.0B packets. 454214455Srpaulo * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>. 455214455Srpaulo * Used to dump CAN packets coming from a CAN Vector board. 456214455Srpaulo * More documentation on the CAN v2.0B frames can be found at 457214455Srpaulo * http://www.can-cia.org/downloads/?269 458214455Srpaulo */ 459214455Srpaulo#define LINKTYPE_CAN20B 190 460214455Srpaulo 461214455Srpaulo/* 462214455Srpaulo * IEEE 802.15.4, with address fields padded, as is done by Linux 463214455Srpaulo * drivers; requested by Juergen Schimmer. 464214455Srpaulo */ 465214455Srpaulo#define LINKTYPE_IEEE802_15_4_LINUX 191 466214455Srpaulo 467214455Srpaulo/* 468214455Srpaulo * Per Packet Information encapsulated packets. 469214455Srpaulo * LINKTYPE_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>. 470214455Srpaulo */ 471214455Srpaulo#define LINKTYPE_PPI 192 472214455Srpaulo 473214455Srpaulo/* 474214455Srpaulo * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header; 475214455Srpaulo * requested by Charles Clancy. 476214455Srpaulo */ 477214455Srpaulo#define LINKTYPE_IEEE802_16_MAC_CPS_RADIO 193 478214455Srpaulo 479214455Srpaulo/* 480214455Srpaulo * Juniper-private data link type, as per request from 481214455Srpaulo * Hannes Gredler <hannes@juniper.net>. 482214455Srpaulo * The DLT_ is used for internal communication with a 483214455Srpaulo * integrated service module (ISM). 484214455Srpaulo */ 485214455Srpaulo#define LINKTYPE_JUNIPER_ISM 194 486214455Srpaulo 487214455Srpaulo/* 488214455Srpaulo * IEEE 802.15.4, exactly as it appears in the spec (no padding, no 489214455Srpaulo * nothing); requested by Mikko Saarnivala <mikko.saarnivala@sensinode.com>. 490214455Srpaulo */ 491214455Srpaulo#define LINKTYPE_IEEE802_15_4 195 492214455Srpaulo 493214455Srpaulo/* 494214455Srpaulo * Various link-layer types, with a pseudo-header, for SITA 495214455Srpaulo * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com). 496214455Srpaulo */ 497214455Srpaulo#define LINKTYPE_SITA 196 498214455Srpaulo 499214455Srpaulo/* 500214455Srpaulo * Various link-layer types, with a pseudo-header, for Endace DAG cards; 501214455Srpaulo * encapsulates Endace ERF records. Requested by Stephen Donnelly 502214455Srpaulo * <stephen@endace.com>. 503214455Srpaulo */ 504214455Srpaulo#define LINKTYPE_ERF 197 505214455Srpaulo 506214455Srpaulo/* 507214455Srpaulo * Special header prepended to Ethernet packets when capturing from a 508214455Srpaulo * u10 Networks board. Requested by Phil Mulholland 509214455Srpaulo * <phil@u10networks.com>. 510214455Srpaulo */ 511214455Srpaulo#define LINKTYPE_RAIF1 198 512214455Srpaulo 513214455Srpaulo/* 514214455Srpaulo * IPMB packet for IPMI, beginning with the I2C slave address, followed 515214455Srpaulo * by the netFn and LUN, etc.. Requested by Chanthy Toeung 516214455Srpaulo * <chanthy.toeung@ca.kontron.com>. 517214455Srpaulo */ 518214455Srpaulo#define LINKTYPE_IPMB 199 519214455Srpaulo 520214455Srpaulo/* 521214455Srpaulo * Juniper-private data link type, as per request from 522214455Srpaulo * Hannes Gredler <hannes@juniper.net>. 523214455Srpaulo * The DLT_ is used for capturing data on a secure tunnel interface. 524214455Srpaulo */ 525214455Srpaulo#define LINKTYPE_JUNIPER_ST 200 526214455Srpaulo 527214455Srpaulo/* 528214455Srpaulo * Bluetooth HCI UART transport layer (part H:4), with pseudo-header 529214455Srpaulo * that includes direction information; requested by Paolo Abeni. 530214455Srpaulo */ 531214455Srpaulo#define LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR 201 532214455Srpaulo 533214455Srpaulo/* 534214455Srpaulo * AX.25 packet with a 1-byte KISS header; see 535214455Srpaulo * 536214455Srpaulo * http://www.ax25.net/kiss.htm 537214455Srpaulo * 538214455Srpaulo * as per Richard Stearn <richard@rns-stearn.demon.co.uk>. 539214455Srpaulo */ 540214455Srpaulo#define LINKTYPE_AX25_KISS 202 541214455Srpaulo 542214455Srpaulo/* 543214455Srpaulo * LAPD packets from an ISDN channel, starting with the address field, 544214455Srpaulo * with no pseudo-header. 545214455Srpaulo * Requested by Varuna De Silva <varunax@gmail.com>. 546214455Srpaulo */ 547214455Srpaulo#define LINKTYPE_LAPD 203 548214455Srpaulo 549214455Srpaulo/* 550214455Srpaulo * Variants of various link-layer headers, with a one-byte direction 551214455Srpaulo * pseudo-header prepended - zero means "received by this host", 552214455Srpaulo * non-zero (any non-zero value) means "sent by this host" - as per 553214455Srpaulo * Will Barker <w.barker@zen.co.uk>. 554214455Srpaulo */ 555214455Srpaulo#define LINKTYPE_PPP_WITH_DIR 204 /* PPP */ 556214455Srpaulo#define LINKTYPE_C_HDLC_WITH_DIR 205 /* Cisco HDLC */ 557214455Srpaulo#define LINKTYPE_FRELAY_WITH_DIR 206 /* Frame Relay */ 558214455Srpaulo#define LINKTYPE_LAPB_WITH_DIR 207 /* LAPB */ 559214455Srpaulo 560214455Srpaulo/* 561214455Srpaulo * 208 is reserved for an as-yet-unspecified proprietary link-layer 562214455Srpaulo * type, as requested by Will Barker. 563214455Srpaulo */ 564214455Srpaulo 565214455Srpaulo/* 566214455Srpaulo * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman 567214455Srpaulo * <avn@pigeonpoint.com>. 568214455Srpaulo */ 569235426Sdelphij#define LINKTYPE_IPMB_LINUX 209 570214455Srpaulo 571214455Srpaulo/* 572214455Srpaulo * FlexRay automotive bus - http://www.flexray.com/ - as requested 573214455Srpaulo * by Hannes Kaelber <hannes.kaelber@x2e.de>. 574214455Srpaulo */ 575235426Sdelphij#define LINKTYPE_FLEXRAY 210 576214455Srpaulo 577214455Srpaulo/* 578214455Srpaulo * Media Oriented Systems Transport (MOST) bus for multimedia 579214455Srpaulo * transport - http://www.mostcooperation.com/ - as requested 580214455Srpaulo * by Hannes Kaelber <hannes.kaelber@x2e.de>. 581214455Srpaulo */ 582235426Sdelphij#define LINKTYPE_MOST 211 583214455Srpaulo 584214455Srpaulo/* 585214455Srpaulo * Local Interconnect Network (LIN) bus for vehicle networks - 586214455Srpaulo * http://www.lin-subbus.org/ - as requested by Hannes Kaelber 587214455Srpaulo * <hannes.kaelber@x2e.de>. 588214455Srpaulo */ 589235426Sdelphij#define LINKTYPE_LIN 212 590214455Srpaulo 591214455Srpaulo/* 592214455Srpaulo * X2E-private data link type used for serial line capture, 593214455Srpaulo * as requested by Hannes Kaelber <hannes.kaelber@x2e.de>. 594214455Srpaulo */ 595235426Sdelphij#define LINKTYPE_X2E_SERIAL 213 596214455Srpaulo 597214455Srpaulo/* 598214455Srpaulo * X2E-private data link type used for the Xoraya data logger 599214455Srpaulo * family, as requested by Hannes Kaelber <hannes.kaelber@x2e.de>. 600214455Srpaulo */ 601235426Sdelphij#define LINKTYPE_X2E_XORAYA 214 602214455Srpaulo 603214455Srpaulo/* 604214455Srpaulo * IEEE 802.15.4, exactly as it appears in the spec (no padding, no 605214455Srpaulo * nothing), but with the PHY-level data for non-ASK PHYs (4 octets 606214455Srpaulo * of 0 as preamble, one octet of SFD, one octet of frame length+ 607214455Srpaulo * reserved bit, and then the MAC-layer data, starting with the 608214455Srpaulo * frame control field). 609214455Srpaulo * 610214455Srpaulo * Requested by Max Filippov <jcmvbkbc@gmail.com>. 611214455Srpaulo */ 612214455Srpaulo#define LINKTYPE_IEEE802_15_4_NONASK_PHY 215 613214455Srpaulo 614214455Srpaulo/* 615214455Srpaulo * David Gibson <david@gibson.dropbear.id.au> requested this for 616214455Srpaulo * captures from the Linux kernel /dev/input/eventN devices. This 617214455Srpaulo * is used to communicate keystrokes and mouse movements from the 618214455Srpaulo * Linux kernel to display systems, such as Xorg. 619214455Srpaulo */ 620235426Sdelphij#define LINKTYPE_LINUX_EVDEV 216 621214455Srpaulo 622214455Srpaulo/* 623214455Srpaulo * GSM Um and Abis interfaces, preceded by a "gsmtap" header. 624214455Srpaulo * 625214455Srpaulo * Requested by Harald Welte <laforge@gnumonks.org>. 626214455Srpaulo */ 627235426Sdelphij#define LINKTYPE_GSMTAP_UM 217 628235426Sdelphij#define LINKTYPE_GSMTAP_ABIS 218 629214455Srpaulo 630214455Srpaulo/* 631214455Srpaulo * MPLS, with an MPLS label as the link-layer header. 632214455Srpaulo * Requested by Michele Marchetto <michele@openbsd.org> on behalf 633214455Srpaulo * of OpenBSD. 634214455Srpaulo */ 635235426Sdelphij#define LINKTYPE_MPLS 219 636214455Srpaulo 637214455Srpaulo/* 638214455Srpaulo * USB packets, beginning with a Linux USB header, with the USB header 639214455Srpaulo * padded to 64 bytes; required for memory-mapped access. 640214455Srpaulo */ 641214455Srpaulo#define LINKTYPE_USB_LINUX_MMAPPED 220 642214455Srpaulo 643214455Srpaulo/* 644214455Srpaulo * DECT packets, with a pseudo-header; requested by 645214455Srpaulo * Matthias Wenzel <tcpdump@mazzoo.de>. 646214455Srpaulo */ 647235426Sdelphij#define LINKTYPE_DECT 221 648214455Srpaulo 649214455Srpaulo/* 650214455Srpaulo * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" <eric.lidwa-1@nasa.gov> 651214455Srpaulo * Date: Mon, 11 May 2009 11:18:30 -0500 652214455Srpaulo * 653214455Srpaulo * DLT_AOS. We need it for AOS Space Data Link Protocol. 654214455Srpaulo * I have already written dissectors for but need an OK from 655214455Srpaulo * legal before I can submit a patch. 656214455Srpaulo * 657214455Srpaulo */ 658235426Sdelphij#define LINKTYPE_AOS 222 659214455Srpaulo 660214455Srpaulo/* 661214455Srpaulo * Wireless HART (Highway Addressable Remote Transducer) 662214455Srpaulo * From the HART Communication Foundation 663214455Srpaulo * IES/PAS 62591 664214455Srpaulo * 665214455Srpaulo * Requested by Sam Roberts <vieuxtech@gmail.com>. 666214455Srpaulo */ 667235426Sdelphij#define LINKTYPE_WIHART 223 668214455Srpaulo 669214455Srpaulo/* 670214455Srpaulo * Fibre Channel FC-2 frames, beginning with a Frame_Header. 671214455Srpaulo * Requested by Kahou Lei <kahou82@gmail.com>. 672214455Srpaulo */ 673235426Sdelphij#define LINKTYPE_FC_2 224 674214455Srpaulo 675214455Srpaulo/* 676214455Srpaulo * Fibre Channel FC-2 frames, beginning with an encoding of the 677214455Srpaulo * SOF, and ending with an encoding of the EOF. 678214455Srpaulo * 679214455Srpaulo * The encodings represent the frame delimiters as 4-byte sequences 680214455Srpaulo * representing the corresponding ordered sets, with K28.5 681214455Srpaulo * represented as 0xBC, and the D symbols as the corresponding 682214455Srpaulo * byte values; for example, SOFi2, which is K28.5 - D21.5 - D1.2 - D21.2, 683214455Srpaulo * is represented as 0xBC 0xB5 0x55 0x55. 684214455Srpaulo * 685214455Srpaulo * Requested by Kahou Lei <kahou82@gmail.com>. 686214455Srpaulo */ 687214455Srpaulo#define LINKTYPE_FC_2_WITH_FRAME_DELIMS 225 688214455Srpaulo 689214455Srpaulo/* 690214455Srpaulo * Solaris ipnet pseudo-header; requested by Darren Reed <Darren.Reed@Sun.COM>. 691214455Srpaulo * 692214455Srpaulo * The pseudo-header starts with a one-byte version number; for version 2, 693214455Srpaulo * the pseudo-header is: 694214455Srpaulo * 695214455Srpaulo * struct dl_ipnetinfo { 696214455Srpaulo * u_int8_t dli_version; 697214455Srpaulo * u_int8_t dli_family; 698214455Srpaulo * u_int16_t dli_htype; 699214455Srpaulo * u_int32_t dli_pktlen; 700214455Srpaulo * u_int32_t dli_ifindex; 701214455Srpaulo * u_int32_t dli_grifindex; 702214455Srpaulo * u_int32_t dli_zsrc; 703214455Srpaulo * u_int32_t dli_zdst; 704214455Srpaulo * }; 705214455Srpaulo * 706214455Srpaulo * dli_version is 2 for the current version of the pseudo-header. 707214455Srpaulo * 708214455Srpaulo * dli_family is a Solaris address family value, so it's 2 for IPv4 709214455Srpaulo * and 26 for IPv6. 710214455Srpaulo * 711214455Srpaulo * dli_htype is a "hook type" - 0 for incoming packets, 1 for outgoing 712214455Srpaulo * packets, and 2 for packets arriving from another zone on the same 713214455Srpaulo * machine. 714214455Srpaulo * 715214455Srpaulo * dli_pktlen is the length of the packet data following the pseudo-header 716214455Srpaulo * (so the captured length minus dli_pktlen is the length of the 717214455Srpaulo * pseudo-header, assuming the entire pseudo-header was captured). 718214455Srpaulo * 719214455Srpaulo * dli_ifindex is the interface index of the interface on which the 720214455Srpaulo * packet arrived. 721214455Srpaulo * 722214455Srpaulo * dli_grifindex is the group interface index number (for IPMP interfaces). 723214455Srpaulo * 724214455Srpaulo * dli_zsrc is the zone identifier for the source of the packet. 725214455Srpaulo * 726214455Srpaulo * dli_zdst is the zone identifier for the destination of the packet. 727214455Srpaulo * 728214455Srpaulo * A zone number of 0 is the global zone; a zone number of 0xffffffff 729214455Srpaulo * means that the packet arrived from another host on the network, not 730214455Srpaulo * from another zone on the same machine. 731214455Srpaulo * 732214455Srpaulo * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates 733214455Srpaulo * which of those it is. 734214455Srpaulo */ 735235426Sdelphij#define LINKTYPE_IPNET 226 736214455Srpaulo 737214455Srpaulo/* 738214455Srpaulo * CAN (Controller Area Network) frames, with a pseudo-header as supplied 739214455Srpaulo * by Linux SocketCAN. See Documentation/networking/can.txt in the Linux 740214455Srpaulo * source. 741214455Srpaulo * 742214455Srpaulo * Requested by Felix Obenhuber <felix@obenhuber.de>. 743214455Srpaulo */ 744235426Sdelphij#define LINKTYPE_CAN_SOCKETCAN 227 745214455Srpaulo 746214455Srpaulo/* 747214455Srpaulo * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies 748214455Srpaulo * whether it's v4 or v6. Requested by Darren Reed <Darren.Reed@Sun.COM>. 749214455Srpaulo */ 750235426Sdelphij#define LINKTYPE_IPV4 228 751235426Sdelphij#define LINKTYPE_IPV6 229 752214455Srpaulo 753235426Sdelphij/* 754235426Sdelphij * IEEE 802.15.4, exactly as it appears in the spec (no padding, no 755235426Sdelphij * nothing), and with no FCS at the end of the frame; requested by 756235426Sdelphij * Jon Smirl <jonsmirl@gmail.com>. 757235426Sdelphij */ 758235426Sdelphij#define LINKTYPE_IEEE802_15_4_NOFCS 230 759214455Srpaulo 760235426Sdelphij/* 761235426Sdelphij * Raw D-Bus: 762235426Sdelphij * 763235426Sdelphij * http://www.freedesktop.org/wiki/Software/dbus 764235426Sdelphij * 765235426Sdelphij * messages: 766235426Sdelphij * 767235426Sdelphij * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages 768235426Sdelphij * 769235426Sdelphij * starting with the endianness flag, followed by the message type, etc., 770235426Sdelphij * but without the authentication handshake before the message sequence: 771235426Sdelphij * 772235426Sdelphij * http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol 773235426Sdelphij * 774235426Sdelphij * Requested by Martin Vidner <martin@vidner.net>. 775235426Sdelphij */ 776235426Sdelphij#define LINKTYPE_DBUS 231 777235426Sdelphij 778235426Sdelphij/* 779235426Sdelphij * Juniper-private data link type, as per request from 780235426Sdelphij * Hannes Gredler <hannes@juniper.net>. 781235426Sdelphij */ 782235426Sdelphij#define LINKTYPE_JUNIPER_VS 232 783235426Sdelphij#define LINKTYPE_JUNIPER_SRX_E2E 233 784235426Sdelphij#define LINKTYPE_JUNIPER_FIBRECHANNEL 234 785235426Sdelphij 786235426Sdelphij/* 787235426Sdelphij * DVB-CI (DVB Common Interface for communication between a PC Card 788235426Sdelphij * module and a DVB receiver). See 789235426Sdelphij * 790235426Sdelphij * http://www.kaiser.cx/pcap-dvbci.html 791235426Sdelphij * 792235426Sdelphij * for the specification. 793235426Sdelphij * 794235426Sdelphij * Requested by Martin Kaiser <martin@kaiser.cx>. 795235426Sdelphij */ 796235426Sdelphij#define LINKTYPE_DVB_CI 235 797235426Sdelphij 798235426Sdelphij/* 799235426Sdelphij * Variant of 3GPP TS 27.010 multiplexing protocol. Requested 800235426Sdelphij * by Hans-Christoph Schemmel <hans-christoph.schemmel@cinterion.com>. 801235426Sdelphij */ 802235426Sdelphij#define LINKTYPE_MUX27010 236 803235426Sdelphij 804235426Sdelphij/* 805235426Sdelphij * STANAG 5066 D_PDUs. Requested by M. Baris Demiray 806235426Sdelphij * <barisdemiray@gmail.com>. 807235426Sdelphij */ 808235426Sdelphij#define LINKTYPE_STANAG_5066_D_PDU 237 809235426Sdelphij 810235426Sdelphij/* 811235426Sdelphij * Juniper-private data link type, as per request from 812235426Sdelphij * Hannes Gredler <hannes@juniper.net>. 813235426Sdelphij */ 814235426Sdelphij#define LINKTYPE_JUNIPER_ATM_CEMIC 238 815235426Sdelphij 816235426Sdelphij/* 817235426Sdelphij * NetFilter LOG messages 818235426Sdelphij * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets) 819235426Sdelphij * 820235426Sdelphij * Requested by Jakub Zawadzki <darkjames-ws@darkjames.pl> 821235426Sdelphij */ 822235426Sdelphij#define LINKTYPE_NFLOG 239 823235426Sdelphij 824235426Sdelphij/* 825235426Sdelphij * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type 826235426Sdelphij * for Ethernet packets with a 4-byte pseudo-header and always 827235426Sdelphij * with the payload including the FCS, as supplied by their 828235426Sdelphij * netANALYZER hardware and software. 829235426Sdelphij * 830235426Sdelphij * Requested by Holger P. Frommer <HPfrommer@hilscher.com> 831235426Sdelphij */ 832235426Sdelphij#define LINKTYPE_NETANALYZER 240 833235426Sdelphij 834235426Sdelphij/* 835235426Sdelphij * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type 836235426Sdelphij * for Ethernet packets with a 4-byte pseudo-header and FCS and 837235426Sdelphij * 1 byte of SFD, as supplied by their netANALYZER hardware and 838235426Sdelphij * software. 839235426Sdelphij * 840235426Sdelphij * Requested by Holger P. Frommer <HPfrommer@hilscher.com> 841235426Sdelphij */ 842235426Sdelphij#define LINKTYPE_NETANALYZER_TRANSPARENT 241 843235426Sdelphij 844235426Sdelphij/* 845251129Sdelphij * IP-over-InfiniBand, as specified by RFC 4391. 846235426Sdelphij * 847235426Sdelphij * Requested by Petr Sumbera <petr.sumbera@oracle.com>. 848235426Sdelphij */ 849235426Sdelphij#define LINKTYPE_IPOIB 242 850235426Sdelphij 851241231Sdelphij/* 852241231Sdelphij * MPEG-2 transport stream (ISO 13818-1/ITU-T H.222.0). 853241231Sdelphij * 854241231Sdelphij * Requested by Guy Martin <gmsoft@tuxicoman.be>. 855241231Sdelphij */ 856241231Sdelphij#define LINKTYPE_MPEG_2_TS 243 857235426Sdelphij 858241231Sdelphij/* 859241231Sdelphij * ng4T GmbH's UMTS Iub/Iur-over-ATM and Iub/Iur-over-IP format as 860241231Sdelphij * used by their ng40 protocol tester. 861241231Sdelphij * 862241231Sdelphij * Requested by Jens Grimmer <jens.grimmer@ng4t.com>. 863241231Sdelphij */ 864241231Sdelphij#define LINKTYPE_NG40 244 865241231Sdelphij 866241231Sdelphij/* 867241231Sdelphij * Pseudo-header giving adapter number and flags, followed by an NFC 868241231Sdelphij * (Near-Field Communications) Logical Link Control Protocol (LLCP) PDU, 869241231Sdelphij * as specified by NFC Forum Logical Link Control Protocol Technical 870241231Sdelphij * Specification LLCP 1.1. 871241231Sdelphij * 872241231Sdelphij * Requested by Mike Wakerly <mikey@google.com>. 873241231Sdelphij */ 874241231Sdelphij#define LINKTYPE_NFC_LLCP 245 875241231Sdelphij 876241231Sdelphij/* 877241231Sdelphij * pfsync output; DLT_PFSYNC is 18, which collides with DLT_CIP in 878241231Sdelphij * SuSE 6.3, on OpenBSD, NetBSD, DragonFly BSD, and Mac OS X, and 879241231Sdelphij * is 121, which collides with DLT_HHDLC, in FreeBSD. We pick a 880241231Sdelphij * shiny new link-layer header type value that doesn't collide with 881241231Sdelphij * anything, in the hopes that future pfsync savefiles, if any, 882241231Sdelphij * won't require special hacks to distinguish from other savefiles. 883241231Sdelphij * 884241231Sdelphij */ 885241231Sdelphij#define LINKTYPE_PFSYNC 246 886241231Sdelphij 887251129Sdelphij/* 888251129Sdelphij * Raw InfiniBand packets, starting with the Local Routing Header. 889251129Sdelphij * 890251129Sdelphij * Requested by Oren Kladnitsky <orenk@mellanox.com>. 891251129Sdelphij */ 892251129Sdelphij#define LINKTYPE_INFINIBAND 247 893241231Sdelphij 894251129Sdelphij/* 895251129Sdelphij * SCTP, with no lower-level protocols (i.e., no IPv4 or IPv6). 896251129Sdelphij * 897251129Sdelphij * Requested by Michael Tuexen <Michael.Tuexen@lurchi.franken.de>. 898251129Sdelphij */ 899251129Sdelphij#define LINKTYPE_SCTP 248 900251129Sdelphij 901276768Sdelphij/* 902276768Sdelphij * USB packets, beginning with a USBPcap header. 903276768Sdelphij * 904276768Sdelphij * Requested by Tomasz Mon <desowin@gmail.com> 905276768Sdelphij */ 906276768Sdelphij#define LINKTYPE_USBPCAP 249 907251129Sdelphij 908276768Sdelphij/* 909276768Sdelphij * Schweitzer Engineering Laboratories "RTAC" product serial-line 910276768Sdelphij * packets. 911276768Sdelphij * 912276768Sdelphij * Requested by Chris Bontje <chris_bontje@selinc.com>. 913276768Sdelphij */ 914276768Sdelphij#define DLT_RTAC_SERIAL 250 915276768Sdelphij 916276768Sdelphij/* 917276768Sdelphij * Bluetooth Low Energy air interface link-layer packets. 918276768Sdelphij * 919276768Sdelphij * Requested by Mike Kershaw <dragorn@kismetwireless.net>. 920276768Sdelphij */ 921276768Sdelphij#define LINKTYPE_BLUETOOTH_LE_LL 251 922276768Sdelphij 923276768Sdelphij/* 924276768Sdelphij * Link-layer header type for upper-protocol layer PDU saves from wireshark. 925276768Sdelphij * 926276768Sdelphij * the actual contents are determined by two TAGs stored with each 927276768Sdelphij * packet: 928276768Sdelphij * EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the 929276768Sdelphij * original packet. 930276768Sdelphij * 931276768Sdelphij * EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector 932276768Sdelphij * that can make sense of the data stored. 933276768Sdelphij */ 934276768Sdelphij#define LINKTYPE_WIRESHARK_UPPER_PDU 252 935276768Sdelphij 936276768Sdelphij/* 937276768Sdelphij * Link-layer header type for the netlink protocol (nlmon devices). 938276768Sdelphij */ 939276768Sdelphij#define LINKTYPE_NETLINK 253 940276768Sdelphij 941276768Sdelphij/* 942276768Sdelphij * Bluetooth Linux Monitor headers for the BlueZ stack. 943276768Sdelphij */ 944276768Sdelphij#define LINKTYPE_BLUETOOTH_LINUX_MONITOR 254 945276768Sdelphij 946276768Sdelphij/* 947276768Sdelphij * Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as 948276768Sdelphij * captured by Ubertooth. 949276768Sdelphij */ 950276768Sdelphij#define LINKTYPE_BLUETOOTH_BREDR_BB 255 951276768Sdelphij 952276768Sdelphij/* 953276768Sdelphij * Bluetooth Low Energy link layer packets, as captured by Ubertooth. 954276768Sdelphij */ 955276768Sdelphij#define LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR 256 956276768Sdelphij 957276768Sdelphij/* 958276768Sdelphij * PROFIBUS data link layer. 959276768Sdelphij */ 960276768Sdelphij#define LINKTYPE_PROFIBUS_DL 257 961276768Sdelphij 962276768Sdelphij 963276768Sdelphij/* 964276768Sdelphij * Apple's DLT_PKTAP headers. 965276768Sdelphij * 966276768Sdelphij * Sadly, the folks at Apple either had no clue that the DLT_USERn values 967276768Sdelphij * are for internal use within an organization and partners only, and 968276768Sdelphij * didn't know that the right way to get a link-layer header type is to 969276768Sdelphij * ask tcpdump.org for one, or knew and didn't care, so they just 970276768Sdelphij * used DLT_USER2, which causes problems for everything except for 971276768Sdelphij * their version of tcpdump. 972276768Sdelphij * 973276768Sdelphij * So I'll just give them one; hopefully this will show up in a 974276768Sdelphij * libpcap release in time for them to get this into 10.10 Big Sur 975276768Sdelphij * or whatever Mavericks' successor is called. LINKTYPE_PKTAP 976276768Sdelphij * will be 258 *even on OS X*; that is *intentional*, so that 977276768Sdelphij * PKTAP files look the same on *all* OSes (different OSes can have 978276768Sdelphij * different numerical values for a given DLT_, but *MUST NOT* have 979276768Sdelphij * different values for what goes in a file, as files can be moved 980276768Sdelphij * between OSes!). 981276768Sdelphij */ 982276768Sdelphij#define LINKTYPE_PKTAP 258 983276768Sdelphij 984276768Sdelphij/* 985276768Sdelphij * Ethernet packets preceded by a header giving the last 6 octets 986276768Sdelphij * of the preamble specified by 802.3-2012 Clause 65, section 987276768Sdelphij * 65.1.3.2 "Transmit". 988276768Sdelphij */ 989276768Sdelphij#define LINKTYPE_EPON 259 990276768Sdelphij 991276768Sdelphij/* 992276768Sdelphij * IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format" 993276768Sdelphij * in the PICMG HPM.2 specification. 994276768Sdelphij */ 995276768Sdelphij#define LINKTYPE_IPMI_HPM_2 260 996276768Sdelphij 997276768Sdelphij#define LINKTYPE_MATCHING_MAX 260 /* highest value in the "matching" range */ 998276768Sdelphij 999214455Srpaulostatic struct linktype_map { 1000214455Srpaulo int dlt; 1001214455Srpaulo int linktype; 1002214455Srpaulo} map[] = { 1003214455Srpaulo /* 1004214455Srpaulo * These DLT_* codes have LINKTYPE_* codes with values identical 1005214455Srpaulo * to the values of the corresponding DLT_* code. 1006214455Srpaulo */ 1007214455Srpaulo { DLT_NULL, LINKTYPE_NULL }, 1008214455Srpaulo { DLT_EN10MB, LINKTYPE_ETHERNET }, 1009214455Srpaulo { DLT_EN3MB, LINKTYPE_EXP_ETHERNET }, 1010214455Srpaulo { DLT_AX25, LINKTYPE_AX25 }, 1011214455Srpaulo { DLT_PRONET, LINKTYPE_PRONET }, 1012214455Srpaulo { DLT_CHAOS, LINKTYPE_CHAOS }, 1013241231Sdelphij { DLT_IEEE802, LINKTYPE_IEEE802_5 }, 1014235426Sdelphij { DLT_ARCNET, LINKTYPE_ARCNET_BSD }, 1015214455Srpaulo { DLT_SLIP, LINKTYPE_SLIP }, 1016214455Srpaulo { DLT_PPP, LINKTYPE_PPP }, 1017214455Srpaulo { DLT_FDDI, LINKTYPE_FDDI }, 1018241231Sdelphij { DLT_SYMANTEC_FIREWALL, LINKTYPE_SYMANTEC_FIREWALL }, 1019214455Srpaulo 1020214455Srpaulo /* 1021214455Srpaulo * These DLT_* codes have different values on different 1022214455Srpaulo * platforms; we map them to LINKTYPE_* codes that 1023214455Srpaulo * have values that should never be equal to any DLT_* 1024214455Srpaulo * code. 1025214455Srpaulo */ 1026214455Srpaulo#ifdef DLT_FR 1027214455Srpaulo /* BSD/OS Frame Relay */ 1028214455Srpaulo { DLT_FR, LINKTYPE_FRELAY }, 1029214455Srpaulo#endif 1030214455Srpaulo 1031214455Srpaulo { DLT_ATM_RFC1483, LINKTYPE_ATM_RFC1483 }, 1032214455Srpaulo { DLT_RAW, LINKTYPE_RAW }, 1033214455Srpaulo { DLT_SLIP_BSDOS, LINKTYPE_SLIP_BSDOS }, 1034214455Srpaulo { DLT_PPP_BSDOS, LINKTYPE_PPP_BSDOS }, 1035214455Srpaulo 1036214455Srpaulo /* BSD/OS Cisco HDLC */ 1037214455Srpaulo { DLT_C_HDLC, LINKTYPE_C_HDLC }, 1038214455Srpaulo 1039214455Srpaulo /* 1040214455Srpaulo * These DLT_* codes are not on all platforms, but, so far, 1041214455Srpaulo * there don't appear to be any platforms that define 1042214455Srpaulo * other codes with those values; we map them to 1043214455Srpaulo * different LINKTYPE_* values anyway, just in case. 1044214455Srpaulo */ 1045214455Srpaulo 1046214455Srpaulo /* Linux ATM Classical IP */ 1047214455Srpaulo { DLT_ATM_CLIP, LINKTYPE_ATM_CLIP }, 1048214455Srpaulo 1049214455Srpaulo /* NetBSD sync/async serial PPP (or Cisco HDLC) */ 1050214455Srpaulo { DLT_PPP_SERIAL, LINKTYPE_PPP_HDLC }, 1051214455Srpaulo 1052214455Srpaulo /* NetBSD PPP over Ethernet */ 1053214455Srpaulo { DLT_PPP_ETHER, LINKTYPE_PPP_ETHER }, 1054214455Srpaulo 1055214455Srpaulo /* 1056235426Sdelphij * All LINKTYPE_ values between LINKTYPE_MATCHING_MIN 1057235426Sdelphij * and LINKTYPE_MATCHING_MAX are mapped to identical 1058235426Sdelphij * DLT_ values. 1059214455Srpaulo */ 1060214455Srpaulo 1061214455Srpaulo { -1, -1 } 1062214455Srpaulo}; 1063214455Srpaulo 1064214455Srpauloint 1065214455Srpaulodlt_to_linktype(int dlt) 1066214455Srpaulo{ 1067214455Srpaulo int i; 1068214455Srpaulo 1069235426Sdelphij /* 1070276768Sdelphij * DLTs that, on some platforms, have values in the matching range 1071276768Sdelphij * but that *don't* have the same value as the corresponding 1072276768Sdelphij * LINKTYPE because, for some reason, not all OSes have the 1073276768Sdelphij * same value for that DLT (note that the DLT's value might be 1074276768Sdelphij * outside the matching range on some of those OSes). 1075241231Sdelphij */ 1076241231Sdelphij if (dlt == DLT_PFSYNC) 1077241231Sdelphij return (LINKTYPE_PFSYNC); 1078276768Sdelphij if (dlt == DLT_PKTAP) 1079276768Sdelphij return (LINKTYPE_PKTAP); 1080241231Sdelphij 1081241231Sdelphij /* 1082276768Sdelphij * For all other values in the matching range, the DLT 1083276768Sdelphij * value is the same as the LINKTYPE value. 1084235426Sdelphij */ 1085235426Sdelphij if (dlt >= DLT_MATCHING_MIN && dlt <= DLT_MATCHING_MAX) 1086235426Sdelphij return (dlt); 1087235426Sdelphij 1088235426Sdelphij /* 1089235426Sdelphij * Map the values outside that range. 1090235426Sdelphij */ 1091214455Srpaulo for (i = 0; map[i].dlt != -1; i++) { 1092214455Srpaulo if (map[i].dlt == dlt) 1093214455Srpaulo return (map[i].linktype); 1094214455Srpaulo } 1095214455Srpaulo 1096214455Srpaulo /* 1097276768Sdelphij * If we don't have a mapping for this DLT, return an 1098235426Sdelphij * error; that means that this is a value with no corresponding 1099276768Sdelphij * LINKTYPE, and we need to assign one. 1100214455Srpaulo */ 1101214455Srpaulo return (-1); 1102214455Srpaulo} 1103214455Srpaulo 1104214455Srpauloint 1105214455Srpaulolinktype_to_dlt(int linktype) 1106214455Srpaulo{ 1107214455Srpaulo int i; 1108214455Srpaulo 1109235426Sdelphij /* 1110276768Sdelphij * LINKTYPEs in the matching range that *don't* 1111276768Sdelphij * have the same value as the corresponding DLTs 1112276768Sdelphij * because, for some reason, not all OSes have the 1113276768Sdelphij * same value for that DLT. 1114241231Sdelphij */ 1115241231Sdelphij if (linktype == LINKTYPE_PFSYNC) 1116241231Sdelphij return (DLT_PFSYNC); 1117276768Sdelphij if (linktype == LINKTYPE_PKTAP) 1118276768Sdelphij return (DLT_PKTAP); 1119241231Sdelphij 1120241231Sdelphij /* 1121276768Sdelphij * For all other values in the matching range, the LINKTYPE 1122276768Sdelphij * value is the same as the DLT value. 1123235426Sdelphij */ 1124235426Sdelphij if (linktype >= LINKTYPE_MATCHING_MIN && 1125235426Sdelphij linktype <= LINKTYPE_MATCHING_MAX) 1126235426Sdelphij return (linktype); 1127235426Sdelphij 1128235426Sdelphij /* 1129235426Sdelphij * Map the values outside that range. 1130235426Sdelphij */ 1131214455Srpaulo for (i = 0; map[i].linktype != -1; i++) { 1132214455Srpaulo if (map[i].linktype == linktype) 1133214455Srpaulo return (map[i].dlt); 1134214455Srpaulo } 1135214455Srpaulo 1136214455Srpaulo /* 1137276768Sdelphij * If we don't have an entry for this LINKTYPE, return 1138276768Sdelphij * the link type value; it may be a DLT from an older 1139276768Sdelphij * version of libpcap. 1140214455Srpaulo */ 1141214455Srpaulo return linktype; 1142214455Srpaulo} 1143214455Srpaulo 1144214455Srpaulo/* 1145214455Srpaulo * The DLT_USB_LINUX and DLT_USB_LINUX_MMAPPED headers are in host 1146214455Srpaulo * byte order when capturing (it's supplied directly from a 1147214455Srpaulo * memory-mapped buffer shared by the kernel). 1148214455Srpaulo * 1149214455Srpaulo * When reading a DLT_USB_LINUX or DLT_USB_LINUX_MMAPPED capture file, 1150276768Sdelphij * we need to convert it from the byte order of the host that wrote 1151276768Sdelphij * the file to this host's byte order. 1152214455Srpaulo */ 1153276768Sdelphijstatic void 1154214455Srpauloswap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf, 1155214455Srpaulo int header_len_64_bytes) 1156214455Srpaulo{ 1157214455Srpaulo pcap_usb_header_mmapped *uhdr = (pcap_usb_header_mmapped *)buf; 1158235426Sdelphij bpf_u_int32 offset = 0; 1159235426Sdelphij usb_isodesc *pisodesc; 1160235426Sdelphij int32_t numdesc, i; 1161214455Srpaulo 1162214455Srpaulo /* 1163235426Sdelphij * "offset" is the offset *past* the field we're swapping; 1164235426Sdelphij * we skip the field *before* checking to make sure 1165235426Sdelphij * the captured data length includes the entire field. 1166235426Sdelphij */ 1167235426Sdelphij 1168235426Sdelphij /* 1169214455Srpaulo * The URB id is a totally opaque value; do we really need to 1170214455Srpaulo * convert it to the reading host's byte order??? 1171214455Srpaulo */ 1172235426Sdelphij offset += 8; /* skip past id */ 1173235426Sdelphij if (hdr->caplen < offset) 1174214455Srpaulo return; 1175214455Srpaulo uhdr->id = SWAPLL(uhdr->id); 1176235426Sdelphij 1177235426Sdelphij offset += 4; /* skip past various 1-byte fields */ 1178235426Sdelphij 1179235426Sdelphij offset += 2; /* skip past bus_id */ 1180235426Sdelphij if (hdr->caplen < offset) 1181214455Srpaulo return; 1182214455Srpaulo uhdr->bus_id = SWAPSHORT(uhdr->bus_id); 1183235426Sdelphij 1184235426Sdelphij offset += 2; /* skip past various 1-byte fields */ 1185235426Sdelphij 1186235426Sdelphij offset += 8; /* skip past ts_sec */ 1187235426Sdelphij if (hdr->caplen < offset) 1188214455Srpaulo return; 1189214455Srpaulo uhdr->ts_sec = SWAPLL(uhdr->ts_sec); 1190235426Sdelphij 1191235426Sdelphij offset += 4; /* skip past ts_usec */ 1192235426Sdelphij if (hdr->caplen < offset) 1193214455Srpaulo return; 1194214455Srpaulo uhdr->ts_usec = SWAPLONG(uhdr->ts_usec); 1195235426Sdelphij 1196235426Sdelphij offset += 4; /* skip past status */ 1197235426Sdelphij if (hdr->caplen < offset) 1198214455Srpaulo return; 1199214455Srpaulo uhdr->status = SWAPLONG(uhdr->status); 1200235426Sdelphij 1201235426Sdelphij offset += 4; /* skip past urb_len */ 1202235426Sdelphij if (hdr->caplen < offset) 1203214455Srpaulo return; 1204214455Srpaulo uhdr->urb_len = SWAPLONG(uhdr->urb_len); 1205235426Sdelphij 1206235426Sdelphij offset += 4; /* skip past data_len */ 1207235426Sdelphij if (hdr->caplen < offset) 1208214455Srpaulo return; 1209214455Srpaulo uhdr->data_len = SWAPLONG(uhdr->data_len); 1210214455Srpaulo 1211235426Sdelphij if (uhdr->transfer_type == URB_ISOCHRONOUS) { 1212235426Sdelphij offset += 4; /* skip past s.iso.error_count */ 1213235426Sdelphij if (hdr->caplen < offset) 1214235426Sdelphij return; 1215235426Sdelphij uhdr->s.iso.error_count = SWAPLONG(uhdr->s.iso.error_count); 1216235426Sdelphij 1217235426Sdelphij offset += 4; /* skip past s.iso.numdesc */ 1218235426Sdelphij if (hdr->caplen < offset) 1219235426Sdelphij return; 1220235426Sdelphij uhdr->s.iso.numdesc = SWAPLONG(uhdr->s.iso.numdesc); 1221235426Sdelphij } else 1222235426Sdelphij offset += 8; /* skip USB setup header */ 1223235426Sdelphij 1224214455Srpaulo if (header_len_64_bytes) { 1225214455Srpaulo /* 1226214455Srpaulo * This is either the "version 1" header, with 1227214455Srpaulo * 16 bytes of additional fields at the end, or 1228214455Srpaulo * a "version 0" header from a memory-mapped 1229214455Srpaulo * capture, with 16 bytes of zeroed-out padding 1230214455Srpaulo * at the end. Byte swap them as if this were 1231214455Srpaulo * a "version 1" header. 1232214455Srpaulo */ 1233235426Sdelphij offset += 4; /* skip past interval */ 1234235426Sdelphij if (hdr->caplen < offset) 1235214455Srpaulo return; 1236214455Srpaulo uhdr->interval = SWAPLONG(uhdr->interval); 1237235426Sdelphij 1238235426Sdelphij offset += 4; /* skip past start_frame */ 1239235426Sdelphij if (hdr->caplen < offset) 1240214455Srpaulo return; 1241214455Srpaulo uhdr->start_frame = SWAPLONG(uhdr->start_frame); 1242235426Sdelphij 1243235426Sdelphij offset += 4; /* skip past xfer_flags */ 1244235426Sdelphij if (hdr->caplen < offset) 1245214455Srpaulo return; 1246214455Srpaulo uhdr->xfer_flags = SWAPLONG(uhdr->xfer_flags); 1247235426Sdelphij 1248235426Sdelphij offset += 4; /* skip past ndesc */ 1249235426Sdelphij if (hdr->caplen < offset) 1250214455Srpaulo return; 1251214455Srpaulo uhdr->ndesc = SWAPLONG(uhdr->ndesc); 1252214455Srpaulo } 1253235426Sdelphij 1254235426Sdelphij if (uhdr->transfer_type == URB_ISOCHRONOUS) { 1255235426Sdelphij /* swap the values in struct linux_usb_isodesc */ 1256235426Sdelphij pisodesc = (usb_isodesc *)(void *)(buf+offset); 1257235426Sdelphij numdesc = uhdr->s.iso.numdesc; 1258235426Sdelphij for (i = 0; i < numdesc; i++) { 1259235426Sdelphij offset += 4; /* skip past status */ 1260235426Sdelphij if (hdr->caplen < offset) 1261235426Sdelphij return; 1262235426Sdelphij pisodesc->status = SWAPLONG(pisodesc->status); 1263235426Sdelphij 1264235426Sdelphij offset += 4; /* skip past offset */ 1265235426Sdelphij if (hdr->caplen < offset) 1266235426Sdelphij return; 1267235426Sdelphij pisodesc->offset = SWAPLONG(pisodesc->offset); 1268235426Sdelphij 1269235426Sdelphij offset += 4; /* skip past len */ 1270235426Sdelphij if (hdr->caplen < offset) 1271235426Sdelphij return; 1272235426Sdelphij pisodesc->len = SWAPLONG(pisodesc->len); 1273235426Sdelphij 1274235426Sdelphij offset += 4; /* skip past padding */ 1275235426Sdelphij 1276235426Sdelphij pisodesc++; 1277235426Sdelphij } 1278235426Sdelphij } 1279214455Srpaulo} 1280276768Sdelphij 1281276768Sdelphij/* 1282276768Sdelphij * The DLT_NFLOG "packets" have a mixture of big-endian and host-byte-order 1283276768Sdelphij * data. They begin with a fixed-length header with big-endian fields, 1284276768Sdelphij * followed by a set of TLVs, where the type and length are in host 1285276768Sdelphij * byte order but the values are either big-endian or are a raw byte 1286276768Sdelphij * sequence that's the same regardless of the host's byte order. 1287276768Sdelphij * 1288276768Sdelphij * When reading a DLT_NFLOG capture file, we need to convert the type 1289276768Sdelphij * and length values from the byte order of the host that wrote the 1290276768Sdelphij * file to the byte order of this host. 1291276768Sdelphij */ 1292276768Sdelphijstatic void 1293276768Sdelphijswap_nflog_header(const struct pcap_pkthdr *hdr, u_char *buf) 1294276768Sdelphij{ 1295276768Sdelphij u_char *p = buf; 1296276768Sdelphij nflog_hdr_t *nfhdr = (nflog_hdr_t *)buf; 1297276768Sdelphij nflog_tlv_t *tlv; 1298276768Sdelphij u_int caplen = hdr->caplen; 1299276768Sdelphij u_int length = hdr->len; 1300276768Sdelphij u_int16_t size; 1301276768Sdelphij 1302276768Sdelphij if (caplen < (int) sizeof(nflog_hdr_t) || length < (int) sizeof(nflog_hdr_t)) { 1303276768Sdelphij /* Not enough data to have any TLVs. */ 1304276768Sdelphij return; 1305276768Sdelphij } 1306276768Sdelphij 1307276768Sdelphij if (!(nfhdr->nflog_version) == 0) { 1308276768Sdelphij /* Unknown NFLOG version */ 1309276768Sdelphij return; 1310276768Sdelphij } 1311276768Sdelphij 1312276768Sdelphij length -= sizeof(nflog_hdr_t); 1313276768Sdelphij caplen -= sizeof(nflog_hdr_t); 1314276768Sdelphij p += sizeof(nflog_hdr_t); 1315276768Sdelphij 1316276768Sdelphij while (caplen >= sizeof(nflog_tlv_t)) { 1317276768Sdelphij tlv = (nflog_tlv_t *) p; 1318276768Sdelphij 1319276768Sdelphij /* Swap the type and length. */ 1320276768Sdelphij tlv->tlv_type = SWAPSHORT(tlv->tlv_type); 1321276768Sdelphij tlv->tlv_length = SWAPSHORT(tlv->tlv_length); 1322276768Sdelphij 1323276768Sdelphij /* Get the length of the TLV. */ 1324276768Sdelphij size = tlv->tlv_length; 1325276768Sdelphij if (size % 4 != 0) 1326276768Sdelphij size += 4 - size % 4; 1327276768Sdelphij 1328276768Sdelphij /* Is the TLV's length less than the minimum? */ 1329276768Sdelphij if (size < sizeof(nflog_tlv_t)) { 1330276768Sdelphij /* Yes. Give up now. */ 1331276768Sdelphij return; 1332276768Sdelphij } 1333276768Sdelphij 1334276768Sdelphij /* Do we have enough data for the full TLV? */ 1335276768Sdelphij if (caplen < size || length < size) { 1336276768Sdelphij /* No. */ 1337276768Sdelphij return; 1338276768Sdelphij } 1339276768Sdelphij 1340276768Sdelphij /* Skip over the TLV. */ 1341276768Sdelphij length -= size; 1342276768Sdelphij caplen -= size; 1343276768Sdelphij p += size; 1344276768Sdelphij } 1345276768Sdelphij} 1346276768Sdelphij 1347276768Sdelphijvoid 1348276768Sdelphijswap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data) 1349276768Sdelphij{ 1350276768Sdelphij /* 1351276768Sdelphij * Convert pseudo-headers from the byte order of 1352276768Sdelphij * the host on which the file was saved to our 1353276768Sdelphij * byte order, as necessary. 1354276768Sdelphij */ 1355276768Sdelphij switch (linktype) { 1356276768Sdelphij 1357276768Sdelphij case DLT_USB_LINUX: 1358276768Sdelphij swap_linux_usb_header(hdr, data, 0); 1359276768Sdelphij break; 1360276768Sdelphij 1361276768Sdelphij case DLT_USB_LINUX_MMAPPED: 1362276768Sdelphij swap_linux_usb_header(hdr, data, 1); 1363276768Sdelphij break; 1364276768Sdelphij 1365276768Sdelphij case DLT_NFLOG: 1366276768Sdelphij swap_nflog_header(hdr, data); 1367276768Sdelphij break; 1368276768Sdelphij } 1369276768Sdelphij} 1370