pcap-common.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. /*
  2. * Copyright (c) 1993, 1994, 1995, 1996, 1997
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that: (1) source code distributions
  7. * retain the above copyright notice and this paragraph in its entirety, (2)
  8. * distributions including binary code include the above copyright notice and
  9. * this paragraph in its entirety in the documentation or other materials
  10. * provided with the distribution, and (3) all advertising materials mentioning
  11. * features or use of this software display the following acknowledgement:
  12. * ``This product includes software developed by the University of California,
  13. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14. * the University nor the names of its contributors may be used to endorse
  15. * or promote products derived from this software without specific prior
  16. * written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * pcap-common.c - common code for pcap and pcapng files
  22. */
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26. #include <pcap-types.h>
  27. #include "pcap-int.h"
  28. #include "extract.h"
  29. #include "pcap/sll.h"
  30. #include "pcap/usb.h"
  31. #include "pcap/nflog.h"
  32. #include "pcap/can_socketcan.h"
  33. #include "pcap-common.h"
  34. /*
  35. * We don't write DLT_* values to capture files, because they're not the
  36. * same on all platforms.
  37. *
  38. * Unfortunately, the various flavors of BSD have not always used the same
  39. * numerical values for the same data types, and various patches to
  40. * libpcap for non-BSD OSes have added their own DLT_* codes for link
  41. * layer encapsulation types seen on those OSes, and those codes have had,
  42. * in some cases, values that were also used, on other platforms, for other
  43. * link layer encapsulation types.
  44. *
  45. * This means that capture files of a type whose numerical DLT_* code
  46. * means different things on different BSDs, or with different versions
  47. * of libpcap, can't always be read on systems other than those like
  48. * the one running on the machine on which the capture was made.
  49. *
  50. * Instead, we define here a set of LINKTYPE_* codes, and map DLT_* codes
  51. * to LINKTYPE_* codes when writing a savefile header, and map LINKTYPE_*
  52. * codes to DLT_* codes when reading a savefile header.
  53. *
  54. * For those DLT_* codes that have, as far as we know, the same values on
  55. * all platforms (DLT_NULL through DLT_FDDI), we define LINKTYPE_xxx as
  56. * DLT_xxx; that way, captures of those types can still be read by
  57. * versions of libpcap that map LINKTYPE_* values to DLT_* values, and
  58. * captures of those types written by versions of libpcap that map DLT_
  59. * values to LINKTYPE_ values can still be read by older versions
  60. * of libpcap.
  61. *
  62. * The other LINKTYPE_* codes are given values starting at 100, in the
  63. * hopes that no DLT_* code will be given one of those values.
  64. *
  65. * In order to ensure that a given LINKTYPE_* code's value will refer to
  66. * the same encapsulation type on all platforms, you should not allocate
  67. * a new LINKTYPE_* value without consulting
  68. * "tcpdump-workers@lists.tcpdump.org". The tcpdump developers will
  69. * allocate a value for you, and will not subsequently allocate it to
  70. * anybody else; that value will be added to the "pcap.h" in the
  71. * tcpdump.org Git repository, so that a future libpcap release will
  72. * include it.
  73. *
  74. * You should, if possible, also contribute patches to libpcap and tcpdump
  75. * to handle the new encapsulation type, so that they can also be checked
  76. * into the tcpdump.org Git repository and so that they will appear in
  77. * future libpcap and tcpdump releases.
  78. *
  79. * Do *NOT* assume that any values after the largest value in this file
  80. * are available; you might not have the most up-to-date version of this
  81. * file, and new values after that one might have been assigned. Also,
  82. * do *NOT* use any values below 100 - those might already have been
  83. * taken by one (or more!) organizations.
  84. *
  85. * Any platform that defines additional DLT_* codes should:
  86. *
  87. * request a LINKTYPE_* code and value from tcpdump.org,
  88. * as per the above;
  89. *
  90. * add, in their version of libpcap, an entry to map
  91. * those DLT_* codes to the corresponding LINKTYPE_*
  92. * code;
  93. *
  94. * redefine, in their "net/bpf.h", any DLT_* values
  95. * that collide with the values used by their additional
  96. * DLT_* codes, to remove those collisions (but without
  97. * making them collide with any of the LINKTYPE_*
  98. * values equal to 50 or above; they should also avoid
  99. * defining DLT_* values that collide with those
  100. * LINKTYPE_* values, either).
  101. */
  102. #define LINKTYPE_NULL DLT_NULL
  103. #define LINKTYPE_ETHERNET DLT_EN10MB /* also for 100Mb and up */
  104. #define LINKTYPE_EXP_ETHERNET DLT_EN3MB /* 3Mb experimental Ethernet */
  105. #define LINKTYPE_AX25 DLT_AX25
  106. #define LINKTYPE_PRONET DLT_PRONET
  107. #define LINKTYPE_CHAOS DLT_CHAOS
  108. #define LINKTYPE_IEEE802_5 DLT_IEEE802 /* DLT_IEEE802 is used for 802.5 Token Ring */
  109. #define LINKTYPE_ARCNET_BSD DLT_ARCNET /* BSD-style headers */
  110. #define LINKTYPE_SLIP DLT_SLIP
  111. #define LINKTYPE_PPP DLT_PPP
  112. #define LINKTYPE_FDDI DLT_FDDI
  113. /*
  114. * LINKTYPE_PPP is for use when there might, or might not, be an RFC 1662
  115. * PPP in HDLC-like framing header (with 0xff 0x03 before the PPP protocol
  116. * field) at the beginning of the packet.
  117. *
  118. * This is for use when there is always such a header; the address field
  119. * might be 0xff, for regular PPP, or it might be an address field for Cisco
  120. * point-to-point with HDLC framing as per section 4.3.1 of RFC 1547 ("Cisco
  121. * HDLC"). This is, for example, what you get with NetBSD's DLT_PPP_SERIAL.
  122. *
  123. * We give it the same value as NetBSD's DLT_PPP_SERIAL, in the hopes that
  124. * nobody else will choose a DLT_ value of 50, and so that DLT_PPP_SERIAL
  125. * captures will be written out with a link type that NetBSD's tcpdump
  126. * can read.
  127. */
  128. #define LINKTYPE_PPP_HDLC 50 /* PPP in HDLC-like framing */
  129. #define LINKTYPE_PPP_ETHER 51 /* NetBSD PPP-over-Ethernet */
  130. #define LINKTYPE_SYMANTEC_FIREWALL 99 /* Symantec Enterprise Firewall */
  131. /*
  132. * These correspond to DLT_s that have different values on different
  133. * platforms; we map between these values in capture files and
  134. * the DLT_ values as returned by pcap_datalink() and passed to
  135. * pcap_open_dead().
  136. */
  137. #define LINKTYPE_ATM_RFC1483 100 /* LLC/SNAP-encapsulated ATM */
  138. #define LINKTYPE_RAW 101 /* raw IP */
  139. #define LINKTYPE_SLIP_BSDOS 102 /* BSD/OS SLIP BPF header */
  140. #define LINKTYPE_PPP_BSDOS 103 /* BSD/OS PPP BPF header */
  141. /*
  142. * Values starting with 104 are used for newly-assigned link-layer
  143. * header type values; for those link-layer header types, the DLT_
  144. * value returned by pcap_datalink() and passed to pcap_open_dead(),
  145. * and the LINKTYPE_ value that appears in capture files, are the
  146. * same.
  147. *
  148. * LINKTYPE_MATCHING_MIN is the lowest such value; LINKTYPE_MATCHING_MAX
  149. * is the highest such value.
  150. */
  151. #define LINKTYPE_MATCHING_MIN 104 /* lowest value in the "matching" range */
  152. #define LINKTYPE_C_HDLC 104 /* Cisco HDLC */
  153. #define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 (wireless) */
  154. #define LINKTYPE_ATM_CLIP 106 /* Linux Classical IP over ATM */
  155. #define LINKTYPE_FRELAY 107 /* Frame Relay */
  156. #define LINKTYPE_LOOP 108 /* OpenBSD loopback */
  157. #define LINKTYPE_ENC 109 /* OpenBSD IPSEC enc */
  158. /*
  159. * These three types are reserved for future use.
  160. */
  161. #define LINKTYPE_LANE8023 110 /* ATM LANE + 802.3 */
  162. #define LINKTYPE_HIPPI 111 /* NetBSD HIPPI */
  163. #define LINKTYPE_HDLC 112 /* NetBSD HDLC framing */
  164. #define LINKTYPE_LINUX_SLL 113 /* Linux cooked socket capture */
  165. #define LINKTYPE_LTALK 114 /* Apple LocalTalk hardware */
  166. #define LINKTYPE_ECONET 115 /* Acorn Econet */
  167. /*
  168. * Reserved for use with OpenBSD ipfilter.
  169. */
  170. #define LINKTYPE_IPFILTER 116
  171. #define LINKTYPE_PFLOG 117 /* OpenBSD DLT_PFLOG */
  172. #define LINKTYPE_CISCO_IOS 118 /* For Cisco-internal use */
  173. #define LINKTYPE_IEEE802_11_PRISM 119 /* 802.11 plus Prism II monitor mode radio metadata header */
  174. #define LINKTYPE_IEEE802_11_AIRONET 120 /* 802.11 plus FreeBSD Aironet driver radio metadata header */
  175. /*
  176. * Reserved for Siemens HiPath HDLC.
  177. */
  178. #define LINKTYPE_HHDLC 121
  179. #define LINKTYPE_IP_OVER_FC 122 /* RFC 2625 IP-over-Fibre Channel */
  180. #define LINKTYPE_SUNATM 123 /* Solaris+SunATM */
  181. /*
  182. * Reserved as per request from Kent Dahlgren <kent@praesum.com>
  183. * for private use.
  184. */
  185. #define LINKTYPE_RIO 124 /* RapidIO */
  186. #define LINKTYPE_PCI_EXP 125 /* PCI Express */
  187. #define LINKTYPE_AURORA 126 /* Xilinx Aurora link layer */
  188. #define LINKTYPE_IEEE802_11_RADIOTAP 127 /* 802.11 plus radiotap radio metadata header */
  189. /*
  190. * Reserved for the TZSP encapsulation, as per request from
  191. * Chris Waters <chris.waters@networkchemistry.com>
  192. * TZSP is a generic encapsulation for any other link type,
  193. * which includes a means to include meta-information
  194. * with the packet, e.g. signal strength and channel
  195. * for 802.11 packets.
  196. */
  197. #define LINKTYPE_TZSP 128 /* Tazmen Sniffer Protocol */
  198. #define LINKTYPE_ARCNET_LINUX 129 /* Linux-style headers */
  199. /*
  200. * Juniper-private data link types, as per request from
  201. * Hannes Gredler <hannes@juniper.net>. The corresponding
  202. * DLT_s are used for passing on chassis-internal
  203. * metainformation such as QOS profiles, etc..
  204. */
  205. #define LINKTYPE_JUNIPER_MLPPP 130
  206. #define LINKTYPE_JUNIPER_MLFR 131
  207. #define LINKTYPE_JUNIPER_ES 132
  208. #define LINKTYPE_JUNIPER_GGSN 133
  209. #define LINKTYPE_JUNIPER_MFR 134
  210. #define LINKTYPE_JUNIPER_ATM2 135
  211. #define LINKTYPE_JUNIPER_SERVICES 136
  212. #define LINKTYPE_JUNIPER_ATM1 137
  213. #define LINKTYPE_APPLE_IP_OVER_IEEE1394 138 /* Apple IP-over-IEEE 1394 cooked header */
  214. #define LINKTYPE_MTP2_WITH_PHDR 139
  215. #define LINKTYPE_MTP2 140
  216. #define LINKTYPE_MTP3 141
  217. #define LINKTYPE_SCCP 142
  218. #define LINKTYPE_DOCSIS 143 /* DOCSIS MAC frames */
  219. #define LINKTYPE_LINUX_IRDA 144 /* Linux-IrDA */
  220. /*
  221. * Reserved for IBM SP switch and IBM Next Federation switch.
  222. */
  223. #define LINKTYPE_IBM_SP 145
  224. #define LINKTYPE_IBM_SN 146
  225. /*
  226. * Reserved for private use. If you have some link-layer header type
  227. * that you want to use within your organization, with the capture files
  228. * using that link-layer header type not ever be sent outside your
  229. * organization, you can use these values.
  230. *
  231. * No libpcap release will use these for any purpose, nor will any
  232. * tcpdump release use them, either.
  233. *
  234. * Do *NOT* use these in capture files that you expect anybody not using
  235. * your private versions of capture-file-reading tools to read; in
  236. * particular, do *NOT* use them in products, otherwise you may find that
  237. * people won't be able to use tcpdump, or snort, or Ethereal, or... to
  238. * read capture files from your firewall/intrusion detection/traffic
  239. * monitoring/etc. appliance, or whatever product uses that LINKTYPE_ value,
  240. * and you may also find that the developers of those applications will
  241. * not accept patches to let them read those files.
  242. *
  243. * Also, do not use them if somebody might send you a capture using them
  244. * for *their* private type and tools using them for *your* private type
  245. * would have to read them.
  246. *
  247. * Instead, in those cases, ask "tcpdump-workers@lists.tcpdump.org" for a
  248. * new DLT_ and LINKTYPE_ value, as per the comment in pcap/bpf.h, and use
  249. * the type you're given.
  250. */
  251. #define LINKTYPE_USER0 147
  252. #define LINKTYPE_USER1 148
  253. #define LINKTYPE_USER2 149
  254. #define LINKTYPE_USER3 150
  255. #define LINKTYPE_USER4 151
  256. #define LINKTYPE_USER5 152
  257. #define LINKTYPE_USER6 153
  258. #define LINKTYPE_USER7 154
  259. #define LINKTYPE_USER8 155
  260. #define LINKTYPE_USER9 156
  261. #define LINKTYPE_USER10 157
  262. #define LINKTYPE_USER11 158
  263. #define LINKTYPE_USER12 159
  264. #define LINKTYPE_USER13 160
  265. #define LINKTYPE_USER14 161
  266. #define LINKTYPE_USER15 162
  267. /*
  268. * For future use with 802.11 captures - defined by AbsoluteValue
  269. * Systems to store a number of bits of link-layer information
  270. * including radio information:
  271. *
  272. * http://www.shaftnet.org/~pizza/software/capturefrm.txt
  273. */
  274. #define LINKTYPE_IEEE802_11_AVS 163 /* 802.11 plus AVS radio metadata header */
  275. /*
  276. * Juniper-private data link type, as per request from
  277. * Hannes Gredler <hannes@juniper.net>. The corresponding
  278. * DLT_s are used for passing on chassis-internal
  279. * metainformation such as QOS profiles, etc..
  280. */
  281. #define LINKTYPE_JUNIPER_MONITOR 164
  282. /*
  283. * BACnet MS/TP frames.
  284. */
  285. #define LINKTYPE_BACNET_MS_TP 165
  286. /*
  287. * Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
  288. *
  289. * This is used in some OSes to allow a kernel socket filter to distinguish
  290. * between incoming and outgoing packets, on a socket intended to
  291. * supply pppd with outgoing packets so it can do dial-on-demand and
  292. * hangup-on-lack-of-demand; incoming packets are filtered out so they
  293. * don't cause pppd to hold the connection up (you don't want random
  294. * input packets such as port scans, packets from old lost connections,
  295. * etc. to force the connection to stay up).
  296. *
  297. * The first byte of the PPP header (0xff03) is modified to accomodate
  298. * the direction - 0x00 = IN, 0x01 = OUT.
  299. */
  300. #define LINKTYPE_PPP_PPPD 166
  301. /*
  302. * Juniper-private data link type, as per request from
  303. * Hannes Gredler <hannes@juniper.net>. The DLT_s are used
  304. * for passing on chassis-internal metainformation such as
  305. * QOS profiles, cookies, etc..
  306. */
  307. #define LINKTYPE_JUNIPER_PPPOE 167
  308. #define LINKTYPE_JUNIPER_PPPOE_ATM 168
  309. #define LINKTYPE_GPRS_LLC 169 /* GPRS LLC */
  310. #define LINKTYPE_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */
  311. #define LINKTYPE_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */
  312. /*
  313. * Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
  314. * monitoring equipment.
  315. */
  316. #define LINKTYPE_GCOM_T1E1 172
  317. #define LINKTYPE_GCOM_SERIAL 173
  318. /*
  319. * Juniper-private data link type, as per request from
  320. * Hannes Gredler <hannes@juniper.net>. The DLT_ is used
  321. * for internal communication to Physical Interface Cards (PIC)
  322. */
  323. #define LINKTYPE_JUNIPER_PIC_PEER 174
  324. /*
  325. * Link types requested by Gregor Maier <gregor@endace.com> of Endace
  326. * Measurement Systems. They add an ERF header (see
  327. * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
  328. * the link-layer header.
  329. */
  330. #define LINKTYPE_ERF_ETH 175 /* Ethernet */
  331. #define LINKTYPE_ERF_POS 176 /* Packet-over-SONET */
  332. /*
  333. * Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
  334. * for vISDN (http://www.orlandi.com/visdn/). Its link-layer header
  335. * includes additional information before the LAPD header, so it's
  336. * not necessarily a generic LAPD header.
  337. */
  338. #define LINKTYPE_LINUX_LAPD 177
  339. /*
  340. * Juniper-private data link type, as per request from
  341. * Hannes Gredler <hannes@juniper.net>.
  342. * The Link Types are used for prepending meta-information
  343. * like interface index, interface name
  344. * before standard Ethernet, PPP, Frelay & C-HDLC Frames
  345. */
  346. #define LINKTYPE_JUNIPER_ETHER 178
  347. #define LINKTYPE_JUNIPER_PPP 179
  348. #define LINKTYPE_JUNIPER_FRELAY 180
  349. #define LINKTYPE_JUNIPER_CHDLC 181
  350. /*
  351. * Multi Link Frame Relay (FRF.16)
  352. */
  353. #define LINKTYPE_MFR 182
  354. /*
  355. * Juniper-private data link type, as per request from
  356. * Hannes Gredler <hannes@juniper.net>.
  357. * The DLT_ is used for internal communication with a
  358. * voice Adapter Card (PIC)
  359. */
  360. #define LINKTYPE_JUNIPER_VP 183
  361. /*
  362. * Arinc 429 frames.
  363. * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
  364. * Every frame contains a 32bit A429 label.
  365. * More documentation on Arinc 429 can be found at
  366. * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf
  367. */
  368. #define LINKTYPE_A429 184
  369. /*
  370. * Arinc 653 Interpartition Communication messages.
  371. * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
  372. * Please refer to the A653-1 standard for more information.
  373. */
  374. #define LINKTYPE_A653_ICM 185
  375. /*
  376. * This used to be "USB packets, beginning with a USB setup header;
  377. * requested by Paolo Abeni <paolo.abeni@email.it>."
  378. *
  379. * However, that header didn't work all that well - it left out some
  380. * useful information - and was abandoned in favor of the DLT_USB_LINUX
  381. * header.
  382. *
  383. * This is now used by FreeBSD for its BPF taps for USB; that has its
  384. * own headers. So it is written, so it is done.
  385. */
  386. #define LINKTYPE_USB_FREEBSD 186
  387. /*
  388. * Bluetooth HCI UART transport layer (part H:4); requested by
  389. * Paolo Abeni.
  390. */
  391. #define LINKTYPE_BLUETOOTH_HCI_H4 187
  392. /*
  393. * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz
  394. * <cruz_petagay@bah.com>.
  395. */
  396. #define LINKTYPE_IEEE802_16_MAC_CPS 188
  397. /*
  398. * USB packets, beginning with a Linux USB header; requested by
  399. * Paolo Abeni <paolo.abeni@email.it>.
  400. */
  401. #define LINKTYPE_USB_LINUX 189
  402. /*
  403. * Controller Area Network (CAN) v. 2.0B packets.
  404. * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
  405. * Used to dump CAN packets coming from a CAN Vector board.
  406. * More documentation on the CAN v2.0B frames can be found at
  407. * http://www.can-cia.org/downloads/?269
  408. */
  409. #define LINKTYPE_CAN20B 190
  410. /*
  411. * IEEE 802.15.4, with address fields padded, as is done by Linux
  412. * drivers; requested by Juergen Schimmer.
  413. */
  414. #define LINKTYPE_IEEE802_15_4_LINUX 191
  415. /*
  416. * Per Packet Information encapsulated packets.
  417. * LINKTYPE_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
  418. */
  419. #define LINKTYPE_PPI 192
  420. /*
  421. * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header;
  422. * requested by Charles Clancy.
  423. */
  424. #define LINKTYPE_IEEE802_16_MAC_CPS_RADIO 193
  425. /*
  426. * Juniper-private data link type, as per request from
  427. * Hannes Gredler <hannes@juniper.net>.
  428. * The DLT_ is used for internal communication with a
  429. * integrated service module (ISM).
  430. */
  431. #define LINKTYPE_JUNIPER_ISM 194
  432. /*
  433. * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
  434. * nothing), and with the FCS at the end of the frame; requested by
  435. * Mikko Saarnivala <mikko.saarnivala@sensinode.com>.
  436. *
  437. * This should only be used if the FCS is present at the end of the
  438. * frame; if the frame has no FCS, DLT_IEEE802_15_4_NOFCS should be
  439. * used.
  440. */
  441. #define LINKTYPE_IEEE802_15_4_WITHFCS 195
  442. /*
  443. * Various link-layer types, with a pseudo-header, for SITA
  444. * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com).
  445. */
  446. #define LINKTYPE_SITA 196
  447. /*
  448. * Various link-layer types, with a pseudo-header, for Endace DAG cards;
  449. * encapsulates Endace ERF records. Requested by Stephen Donnelly
  450. * <stephen@endace.com>.
  451. */
  452. #define LINKTYPE_ERF 197
  453. /*
  454. * Special header prepended to Ethernet packets when capturing from a
  455. * u10 Networks board. Requested by Phil Mulholland
  456. * <phil@u10networks.com>.
  457. */
  458. #define LINKTYPE_RAIF1 198
  459. /*
  460. * IPMB packet for IPMI, beginning with the I2C slave address, followed
  461. * by the netFn and LUN, etc.. Requested by Chanthy Toeung
  462. * <chanthy.toeung@ca.kontron.com>.
  463. */
  464. #define LINKTYPE_IPMB 199
  465. /*
  466. * Juniper-private data link type, as per request from
  467. * Hannes Gredler <hannes@juniper.net>.
  468. * The DLT_ is used for capturing data on a secure tunnel interface.
  469. */
  470. #define LINKTYPE_JUNIPER_ST 200
  471. /*
  472. * Bluetooth HCI UART transport layer (part H:4), with pseudo-header
  473. * that includes direction information; requested by Paolo Abeni.
  474. */
  475. #define LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR 201
  476. /*
  477. * AX.25 packet with a 1-byte KISS header; see
  478. *
  479. * http://www.ax25.net/kiss.htm
  480. *
  481. * as per Richard Stearn <richard@rns-stearn.demon.co.uk>.
  482. */
  483. #define LINKTYPE_AX25_KISS 202
  484. /*
  485. * LAPD packets from an ISDN channel, starting with the address field,
  486. * with no pseudo-header.
  487. * Requested by Varuna De Silva <varunax@gmail.com>.
  488. */
  489. #define LINKTYPE_LAPD 203
  490. /*
  491. * Variants of various link-layer headers, with a one-byte direction
  492. * pseudo-header prepended - zero means "received by this host",
  493. * non-zero (any non-zero value) means "sent by this host" - as per
  494. * Will Barker <w.barker@zen.co.uk>.
  495. */
  496. #define LINKTYPE_PPP_WITH_DIR 204 /* PPP */
  497. #define LINKTYPE_C_HDLC_WITH_DIR 205 /* Cisco HDLC */
  498. #define LINKTYPE_FRELAY_WITH_DIR 206 /* Frame Relay */
  499. #define LINKTYPE_LAPB_WITH_DIR 207 /* LAPB */
  500. /*
  501. * 208 is reserved for an as-yet-unspecified proprietary link-layer
  502. * type, as requested by Will Barker.
  503. */
  504. /*
  505. * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman
  506. * <avn@pigeonpoint.com>.
  507. */
  508. #define LINKTYPE_IPMB_LINUX 209
  509. /*
  510. * FlexRay automotive bus - http://www.flexray.com/ - as requested
  511. * by Hannes Kaelber <hannes.kaelber@x2e.de>.
  512. */
  513. #define LINKTYPE_FLEXRAY 210
  514. /*
  515. * Media Oriented Systems Transport (MOST) bus for multimedia
  516. * transport - http://www.mostcooperation.com/ - as requested
  517. * by Hannes Kaelber <hannes.kaelber@x2e.de>.
  518. */
  519. #define LINKTYPE_MOST 211
  520. /*
  521. * Local Interconnect Network (LIN) bus for vehicle networks -
  522. * http://www.lin-subbus.org/ - as requested by Hannes Kaelber
  523. * <hannes.kaelber@x2e.de>.
  524. */
  525. #define LINKTYPE_LIN 212
  526. /*
  527. * X2E-private data link type used for serial line capture,
  528. * as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
  529. */
  530. #define LINKTYPE_X2E_SERIAL 213
  531. /*
  532. * X2E-private data link type used for the Xoraya data logger
  533. * family, as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
  534. */
  535. #define LINKTYPE_X2E_XORAYA 214
  536. /*
  537. * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
  538. * nothing), but with the PHY-level data for non-ASK PHYs (4 octets
  539. * of 0 as preamble, one octet of SFD, one octet of frame length+
  540. * reserved bit, and then the MAC-layer data, starting with the
  541. * frame control field).
  542. *
  543. * Requested by Max Filippov <jcmvbkbc@gmail.com>.
  544. */
  545. #define LINKTYPE_IEEE802_15_4_NONASK_PHY 215
  546. /*
  547. * David Gibson <david@gibson.dropbear.id.au> requested this for
  548. * captures from the Linux kernel /dev/input/eventN devices. This
  549. * is used to communicate keystrokes and mouse movements from the
  550. * Linux kernel to display systems, such as Xorg.
  551. */
  552. #define LINKTYPE_LINUX_EVDEV 216
  553. /*
  554. * GSM Um and Abis interfaces, preceded by a "gsmtap" header.
  555. *
  556. * Requested by Harald Welte <laforge@gnumonks.org>.
  557. */
  558. #define LINKTYPE_GSMTAP_UM 217
  559. #define LINKTYPE_GSMTAP_ABIS 218
  560. /*
  561. * MPLS, with an MPLS label as the link-layer header.
  562. * Requested by Michele Marchetto <michele@openbsd.org> on behalf
  563. * of OpenBSD.
  564. */
  565. #define LINKTYPE_MPLS 219
  566. /*
  567. * USB packets, beginning with a Linux USB header, with the USB header
  568. * padded to 64 bytes; required for memory-mapped access.
  569. */
  570. #define LINKTYPE_USB_LINUX_MMAPPED 220
  571. /*
  572. * DECT packets, with a pseudo-header; requested by
  573. * Matthias Wenzel <tcpdump@mazzoo.de>.
  574. */
  575. #define LINKTYPE_DECT 221
  576. /*
  577. * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" <eric.lidwa-1@nasa.gov>
  578. * Date: Mon, 11 May 2009 11:18:30 -0500
  579. *
  580. * DLT_AOS. We need it for AOS Space Data Link Protocol.
  581. * I have already written dissectors for but need an OK from
  582. * legal before I can submit a patch.
  583. *
  584. */
  585. #define LINKTYPE_AOS 222
  586. /*
  587. * Wireless HART (Highway Addressable Remote Transducer)
  588. * From the HART Communication Foundation
  589. * IES/PAS 62591
  590. *
  591. * Requested by Sam Roberts <vieuxtech@gmail.com>.
  592. */
  593. #define LINKTYPE_WIHART 223
  594. /*
  595. * Fibre Channel FC-2 frames, beginning with a Frame_Header.
  596. * Requested by Kahou Lei <kahou82@gmail.com>.
  597. */
  598. #define LINKTYPE_FC_2 224
  599. /*
  600. * Fibre Channel FC-2 frames, beginning with an encoding of the
  601. * SOF, and ending with an encoding of the EOF.
  602. *
  603. * The encodings represent the frame delimiters as 4-byte sequences
  604. * representing the corresponding ordered sets, with K28.5
  605. * represented as 0xBC, and the D symbols as the corresponding
  606. * byte values; for example, SOFi2, which is K28.5 - D21.5 - D1.2 - D21.2,
  607. * is represented as 0xBC 0xB5 0x55 0x55.
  608. *
  609. * Requested by Kahou Lei <kahou82@gmail.com>.
  610. */
  611. #define LINKTYPE_FC_2_WITH_FRAME_DELIMS 225
  612. /*
  613. * Solaris ipnet pseudo-header; requested by Darren Reed <Darren.Reed@Sun.COM>.
  614. *
  615. * The pseudo-header starts with a one-byte version number; for version 2,
  616. * the pseudo-header is:
  617. *
  618. * struct dl_ipnetinfo {
  619. * uint8_t dli_version;
  620. * uint8_t dli_family;
  621. * uint16_t dli_htype;
  622. * uint32_t dli_pktlen;
  623. * uint32_t dli_ifindex;
  624. * uint32_t dli_grifindex;
  625. * uint32_t dli_zsrc;
  626. * uint32_t dli_zdst;
  627. * };
  628. *
  629. * dli_version is 2 for the current version of the pseudo-header.
  630. *
  631. * dli_family is a Solaris address family value, so it's 2 for IPv4
  632. * and 26 for IPv6.
  633. *
  634. * dli_htype is a "hook type" - 0 for incoming packets, 1 for outgoing
  635. * packets, and 2 for packets arriving from another zone on the same
  636. * machine.
  637. *
  638. * dli_pktlen is the length of the packet data following the pseudo-header
  639. * (so the captured length minus dli_pktlen is the length of the
  640. * pseudo-header, assuming the entire pseudo-header was captured).
  641. *
  642. * dli_ifindex is the interface index of the interface on which the
  643. * packet arrived.
  644. *
  645. * dli_grifindex is the group interface index number (for IPMP interfaces).
  646. *
  647. * dli_zsrc is the zone identifier for the source of the packet.
  648. *
  649. * dli_zdst is the zone identifier for the destination of the packet.
  650. *
  651. * A zone number of 0 is the global zone; a zone number of 0xffffffff
  652. * means that the packet arrived from another host on the network, not
  653. * from another zone on the same machine.
  654. *
  655. * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates
  656. * which of those it is.
  657. */
  658. #define LINKTYPE_IPNET 226
  659. /*
  660. * CAN (Controller Area Network) frames, with a pseudo-header as supplied
  661. * by Linux SocketCAN, and with multi-byte numerical fields in that header
  662. * in big-endian byte order.
  663. *
  664. * See Documentation/networking/can.txt in the Linux source.
  665. *
  666. * Requested by Felix Obenhuber <felix@obenhuber.de>.
  667. */
  668. #define LINKTYPE_CAN_SOCKETCAN 227
  669. /*
  670. * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies
  671. * whether it's v4 or v6. Requested by Darren Reed <Darren.Reed@Sun.COM>.
  672. */
  673. #define LINKTYPE_IPV4 228
  674. #define LINKTYPE_IPV6 229
  675. /*
  676. * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
  677. * nothing), and with no FCS at the end of the frame; requested by
  678. * Jon Smirl <jonsmirl@gmail.com>.
  679. */
  680. #define LINKTYPE_IEEE802_15_4_NOFCS 230
  681. /*
  682. * Raw D-Bus:
  683. *
  684. * http://www.freedesktop.org/wiki/Software/dbus
  685. *
  686. * messages:
  687. *
  688. * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages
  689. *
  690. * starting with the endianness flag, followed by the message type, etc.,
  691. * but without the authentication handshake before the message sequence:
  692. *
  693. * http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
  694. *
  695. * Requested by Martin Vidner <martin@vidner.net>.
  696. */
  697. #define LINKTYPE_DBUS 231
  698. /*
  699. * Juniper-private data link type, as per request from
  700. * Hannes Gredler <hannes@juniper.net>.
  701. */
  702. #define LINKTYPE_JUNIPER_VS 232
  703. #define LINKTYPE_JUNIPER_SRX_E2E 233
  704. #define LINKTYPE_JUNIPER_FIBRECHANNEL 234
  705. /*
  706. * DVB-CI (DVB Common Interface for communication between a PC Card
  707. * module and a DVB receiver). See
  708. *
  709. * http://www.kaiser.cx/pcap-dvbci.html
  710. *
  711. * for the specification.
  712. *
  713. * Requested by Martin Kaiser <martin@kaiser.cx>.
  714. */
  715. #define LINKTYPE_DVB_CI 235
  716. /*
  717. * Variant of 3GPP TS 27.010 multiplexing protocol. Requested
  718. * by Hans-Christoph Schemmel <hans-christoph.schemmel@cinterion.com>.
  719. */
  720. #define LINKTYPE_MUX27010 236
  721. /*
  722. * STANAG 5066 D_PDUs. Requested by M. Baris Demiray
  723. * <barisdemiray@gmail.com>.
  724. */
  725. #define LINKTYPE_STANAG_5066_D_PDU 237
  726. /*
  727. * Juniper-private data link type, as per request from
  728. * Hannes Gredler <hannes@juniper.net>.
  729. */
  730. #define LINKTYPE_JUNIPER_ATM_CEMIC 238
  731. /*
  732. * NetFilter LOG messages
  733. * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets)
  734. *
  735. * Requested by Jakub Zawadzki <darkjames-ws@darkjames.pl>
  736. */
  737. #define LINKTYPE_NFLOG 239
  738. /*
  739. * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type
  740. * for Ethernet packets with a 4-byte pseudo-header and always
  741. * with the payload including the FCS, as supplied by their
  742. * netANALYZER hardware and software.
  743. *
  744. * Requested by Holger P. Frommer <HPfrommer@hilscher.com>
  745. */
  746. #define LINKTYPE_NETANALYZER 240
  747. /*
  748. * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type
  749. * for Ethernet packets with a 4-byte pseudo-header and FCS and
  750. * 1 byte of SFD, as supplied by their netANALYZER hardware and
  751. * software.
  752. *
  753. * Requested by Holger P. Frommer <HPfrommer@hilscher.com>
  754. */
  755. #define LINKTYPE_NETANALYZER_TRANSPARENT 241
  756. /*
  757. * IP-over-InfiniBand, as specified by RFC 4391.
  758. *
  759. * Requested by Petr Sumbera <petr.sumbera@oracle.com>.
  760. */
  761. #define LINKTYPE_IPOIB 242
  762. /*
  763. * MPEG-2 transport stream (ISO 13818-1/ITU-T H.222.0).
  764. *
  765. * Requested by Guy Martin <gmsoft@tuxicoman.be>.
  766. */
  767. #define LINKTYPE_MPEG_2_TS 243
  768. /*
  769. * ng4T GmbH's UMTS Iub/Iur-over-ATM and Iub/Iur-over-IP format as
  770. * used by their ng40 protocol tester.
  771. *
  772. * Requested by Jens Grimmer <jens.grimmer@ng4t.com>.
  773. */
  774. #define LINKTYPE_NG40 244
  775. /*
  776. * Pseudo-header giving adapter number and flags, followed by an NFC
  777. * (Near-Field Communications) Logical Link Control Protocol (LLCP) PDU,
  778. * as specified by NFC Forum Logical Link Control Protocol Technical
  779. * Specification LLCP 1.1.
  780. *
  781. * Requested by Mike Wakerly <mikey@google.com>.
  782. */
  783. #define LINKTYPE_NFC_LLCP 245
  784. /*
  785. * pfsync output; DLT_PFSYNC is 18, which collides with DLT_CIP in
  786. * SuSE 6.3, on OpenBSD, NetBSD, DragonFly BSD, and macOS, and
  787. * is 121, which collides with DLT_HHDLC, in FreeBSD. We pick a
  788. * shiny new link-layer header type value that doesn't collide with
  789. * anything, in the hopes that future pfsync savefiles, if any,
  790. * won't require special hacks to distinguish from other savefiles.
  791. *
  792. */
  793. #define LINKTYPE_PFSYNC 246
  794. /*
  795. * Raw InfiniBand packets, starting with the Local Routing Header.
  796. *
  797. * Requested by Oren Kladnitsky <orenk@mellanox.com>.
  798. */
  799. #define LINKTYPE_INFINIBAND 247
  800. /*
  801. * SCTP, with no lower-level protocols (i.e., no IPv4 or IPv6).
  802. *
  803. * Requested by Michael Tuexen <Michael.Tuexen@lurchi.franken.de>.
  804. */
  805. #define LINKTYPE_SCTP 248
  806. /*
  807. * USB packets, beginning with a USBPcap header.
  808. *
  809. * Requested by Tomasz Mon <desowin@gmail.com>
  810. */
  811. #define LINKTYPE_USBPCAP 249
  812. /*
  813. * Schweitzer Engineering Laboratories "RTAC" product serial-line
  814. * packets.
  815. *
  816. * Requested by Chris Bontje <chris_bontje@selinc.com>.
  817. */
  818. #define DLT_RTAC_SERIAL 250
  819. /*
  820. * Bluetooth Low Energy air interface link-layer packets.
  821. *
  822. * Requested by Mike Kershaw <dragorn@kismetwireless.net>.
  823. */
  824. #define LINKTYPE_BLUETOOTH_LE_LL 251
  825. /*
  826. * Link-layer header type for upper-protocol layer PDU saves from wireshark.
  827. *
  828. * the actual contents are determined by two TAGs stored with each
  829. * packet:
  830. * EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the
  831. * original packet.
  832. *
  833. * EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector
  834. * that can make sense of the data stored.
  835. */
  836. #define LINKTYPE_WIRESHARK_UPPER_PDU 252
  837. /*
  838. * Link-layer header type for the netlink protocol (nlmon devices).
  839. */
  840. #define LINKTYPE_NETLINK 253
  841. /*
  842. * Bluetooth Linux Monitor headers for the BlueZ stack.
  843. */
  844. #define LINKTYPE_BLUETOOTH_LINUX_MONITOR 254
  845. /*
  846. * Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as
  847. * captured by Ubertooth.
  848. */
  849. #define LINKTYPE_BLUETOOTH_BREDR_BB 255
  850. /*
  851. * Bluetooth Low Energy link layer packets, as captured by Ubertooth.
  852. */
  853. #define LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR 256
  854. /*
  855. * PROFIBUS data link layer.
  856. */
  857. #define LINKTYPE_PROFIBUS_DL 257
  858. /*
  859. * Apple's DLT_PKTAP headers.
  860. *
  861. * Sadly, the folks at Apple either had no clue that the DLT_USERn values
  862. * are for internal use within an organization and partners only, and
  863. * didn't know that the right way to get a link-layer header type is to
  864. * ask tcpdump.org for one, or knew and didn't care, so they just
  865. * used DLT_USER2, which causes problems for everything except for
  866. * their version of tcpdump.
  867. *
  868. * So I'll just give them one; hopefully this will show up in a
  869. * libpcap release in time for them to get this into 10.10 Big Sur
  870. * or whatever Mavericks' successor is called. LINKTYPE_PKTAP
  871. * will be 258 *even on macOS*; that is *intentional*, so that
  872. * PKTAP files look the same on *all* OSes (different OSes can have
  873. * different numerical values for a given DLT_, but *MUST NOT* have
  874. * different values for what goes in a file, as files can be moved
  875. * between OSes!).
  876. */
  877. #define LINKTYPE_PKTAP 258
  878. /*
  879. * Ethernet packets preceded by a header giving the last 6 octets
  880. * of the preamble specified by 802.3-2012 Clause 65, section
  881. * 65.1.3.2 "Transmit".
  882. */
  883. #define LINKTYPE_EPON 259
  884. /*
  885. * IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format"
  886. * in the PICMG HPM.2 specification.
  887. */
  888. #define LINKTYPE_IPMI_HPM_2 260
  889. /*
  890. * per Joshua Wright <jwright@hasborg.com>, formats for Zwave captures.
  891. */
  892. #define LINKTYPE_ZWAVE_R1_R2 261
  893. #define LINKTYPE_ZWAVE_R3 262
  894. /*
  895. * per Steve Karg <skarg@users.sourceforge.net>, formats for Wattstopper
  896. * Digital Lighting Management room bus serial protocol captures.
  897. */
  898. #define LINKTYPE_WATTSTOPPER_DLM 263
  899. /*
  900. * ISO 14443 contactless smart card messages.
  901. */
  902. #define LINKTYPE_ISO_14443 264
  903. /*
  904. * Radio data system (RDS) groups. IEC 62106.
  905. * Per Jonathan Brucker <jonathan.brucke@gmail.com>.
  906. */
  907. #define LINKTYPE_RDS 265
  908. /*
  909. * USB packets, beginning with a Darwin (macOS, etc.) header.
  910. */
  911. #define LINKTYPE_USB_DARWIN 266
  912. /*
  913. * OpenBSD DLT_OPENFLOW.
  914. */
  915. #define LINKTYPE_OPENFLOW 267
  916. /*
  917. * SDLC frames containing SNA PDUs.
  918. */
  919. #define LINKTYPE_SDLC 268
  920. /*
  921. * per "Selvig, Bjorn" <b.selvig@ti.com> used for
  922. * TI protocol sniffer.
  923. */
  924. #define LINKTYPE_TI_LLN_SNIFFER 269
  925. /*
  926. * per: Erik de Jong <erikdejong at gmail.com> for
  927. * https://github.com/eriknl/LoRaTap/releases/tag/v0.1
  928. */
  929. #define LINKTYPE_LORATAP 270
  930. /*
  931. * per: Stefanha at gmail.com for
  932. * http://lists.sandelman.ca/pipermail/tcpdump-workers/2017-May/000772.html
  933. * and: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/vsockmon.h
  934. * for: http://qemu-project.org/Features/VirtioVsock
  935. */
  936. #define LINKTYPE_VSOCK 271
  937. /*
  938. * Nordic Semiconductor Bluetooth LE sniffer.
  939. */
  940. #define LINKTYPE_NORDIC_BLE 272
  941. /*
  942. * Excentis DOCSIS 3.1 RF sniffer (XRA-31)
  943. * per: bruno.verstuyft at excentis.com
  944. * http://www.xra31.com/xra-header
  945. */
  946. #define LINKTYPE_DOCSIS31_XRA31 273
  947. /*
  948. * mPackets, as specified by IEEE 802.3br Figure 99-4, starting
  949. * with the preamble and always ending with a CRC field.
  950. */
  951. #define LINKTYPE_ETHERNET_MPACKET 274
  952. /*
  953. * DisplayPort AUX channel monitoring data as specified by VESA
  954. * DisplayPort(DP) Standard preceeded by a pseudo-header.
  955. * per dirk.eibach at gdsys.cc
  956. */
  957. #define LINKTYPE_DISPLAYPORT_AUX 275
  958. #define LINKTYPE_MATCHING_MAX 275 /* highest value in the "matching" range */
  959. /*
  960. * The DLT_ and LINKTYPE_ values in the "matching" range should be the
  961. * same, so DLT_MATCHING_MAX and LINKTYPE_MATCHING_MAX should be the
  962. * same.
  963. */
  964. #if LINKTYPE_MATCHING_MAX != DLT_MATCHING_MAX
  965. #error The LINKTYPE_ matching range does not match the DLT_ matching range
  966. #endif
  967. static struct linktype_map {
  968. int dlt;
  969. int linktype;
  970. } map[] = {
  971. /*
  972. * These DLT_* codes have LINKTYPE_* codes with values identical
  973. * to the values of the corresponding DLT_* code.
  974. */
  975. { DLT_NULL, LINKTYPE_NULL },
  976. { DLT_EN10MB, LINKTYPE_ETHERNET },
  977. { DLT_EN3MB, LINKTYPE_EXP_ETHERNET },
  978. { DLT_AX25, LINKTYPE_AX25 },
  979. { DLT_PRONET, LINKTYPE_PRONET },
  980. { DLT_CHAOS, LINKTYPE_CHAOS },
  981. { DLT_IEEE802, LINKTYPE_IEEE802_5 },
  982. { DLT_ARCNET, LINKTYPE_ARCNET_BSD },
  983. { DLT_SLIP, LINKTYPE_SLIP },
  984. { DLT_PPP, LINKTYPE_PPP },
  985. { DLT_FDDI, LINKTYPE_FDDI },
  986. { DLT_SYMANTEC_FIREWALL, LINKTYPE_SYMANTEC_FIREWALL },
  987. /*
  988. * These DLT_* codes have different values on different
  989. * platforms; we map them to LINKTYPE_* codes that
  990. * have values that should never be equal to any DLT_*
  991. * code.
  992. */
  993. #ifdef DLT_FR
  994. /* BSD/OS Frame Relay */
  995. { DLT_FR, LINKTYPE_FRELAY },
  996. #endif
  997. { DLT_ATM_RFC1483, LINKTYPE_ATM_RFC1483 },
  998. { DLT_RAW, LINKTYPE_RAW },
  999. { DLT_SLIP_BSDOS, LINKTYPE_SLIP_BSDOS },
  1000. { DLT_PPP_BSDOS, LINKTYPE_PPP_BSDOS },
  1001. /* BSD/OS Cisco HDLC */
  1002. { DLT_C_HDLC, LINKTYPE_C_HDLC },
  1003. /*
  1004. * These DLT_* codes are not on all platforms, but, so far,
  1005. * there don't appear to be any platforms that define
  1006. * other codes with those values; we map them to
  1007. * different LINKTYPE_* values anyway, just in case.
  1008. */
  1009. /* Linux ATM Classical IP */
  1010. { DLT_ATM_CLIP, LINKTYPE_ATM_CLIP },
  1011. /* NetBSD sync/async serial PPP (or Cisco HDLC) */
  1012. { DLT_PPP_SERIAL, LINKTYPE_PPP_HDLC },
  1013. /* NetBSD PPP over Ethernet */
  1014. { DLT_PPP_ETHER, LINKTYPE_PPP_ETHER },
  1015. /*
  1016. * All LINKTYPE_ values between LINKTYPE_MATCHING_MIN
  1017. * and LINKTYPE_MATCHING_MAX are mapped to identical
  1018. * DLT_ values.
  1019. */
  1020. { -1, -1 }
  1021. };
  1022. int
  1023. dlt_to_linktype(int dlt)
  1024. {
  1025. int i;
  1026. /*
  1027. * DLTs that, on some platforms, have values in the matching range
  1028. * but that *don't* have the same value as the corresponding
  1029. * LINKTYPE because, for some reason, not all OSes have the
  1030. * same value for that DLT (note that the DLT's value might be
  1031. * outside the matching range on some of those OSes).
  1032. */
  1033. if (dlt == DLT_PFSYNC)
  1034. return (LINKTYPE_PFSYNC);
  1035. if (dlt == DLT_PKTAP)
  1036. return (LINKTYPE_PKTAP);
  1037. /*
  1038. * For all other values in the matching range, the DLT
  1039. * value is the same as the LINKTYPE value.
  1040. */
  1041. if (dlt >= DLT_MATCHING_MIN && dlt <= DLT_MATCHING_MAX)
  1042. return (dlt);
  1043. /*
  1044. * Map the values outside that range.
  1045. */
  1046. for (i = 0; map[i].dlt != -1; i++) {
  1047. if (map[i].dlt == dlt)
  1048. return (map[i].linktype);
  1049. }
  1050. /*
  1051. * If we don't have a mapping for this DLT, return an
  1052. * error; that means that this is a value with no corresponding
  1053. * LINKTYPE, and we need to assign one.
  1054. */
  1055. return (-1);
  1056. }
  1057. int
  1058. linktype_to_dlt(int linktype)
  1059. {
  1060. int i;
  1061. /*
  1062. * LINKTYPEs in the matching range that *don't*
  1063. * have the same value as the corresponding DLTs
  1064. * because, for some reason, not all OSes have the
  1065. * same value for that DLT.
  1066. */
  1067. if (linktype == LINKTYPE_PFSYNC)
  1068. return (DLT_PFSYNC);
  1069. if (linktype == LINKTYPE_PKTAP)
  1070. return (DLT_PKTAP);
  1071. /*
  1072. * For all other values in the matching range, the LINKTYPE
  1073. * value is the same as the DLT value.
  1074. */
  1075. if (linktype >= LINKTYPE_MATCHING_MIN &&
  1076. linktype <= LINKTYPE_MATCHING_MAX)
  1077. return (linktype);
  1078. /*
  1079. * Map the values outside that range.
  1080. */
  1081. for (i = 0; map[i].linktype != -1; i++) {
  1082. if (map[i].linktype == linktype)
  1083. return (map[i].dlt);
  1084. }
  1085. /*
  1086. * If we don't have an entry for this LINKTYPE, return
  1087. * the link type value; it may be a DLT from an older
  1088. * version of libpcap.
  1089. */
  1090. return linktype;
  1091. }
  1092. /*
  1093. * Return the maximum snapshot length for a given DLT_ value.
  1094. *
  1095. * For most link-layer types, we use MAXIMUM_SNAPLEN, but for DLT_DBUS,
  1096. * the maximum is 134217728, as per
  1097. *
  1098. * https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages
  1099. */
  1100. u_int
  1101. max_snaplen_for_dlt(int dlt)
  1102. {
  1103. if (dlt == DLT_DBUS)
  1104. return 134217728;
  1105. else
  1106. return MAXIMUM_SNAPLEN;
  1107. }
  1108. /*
  1109. * DLT_LINUX_SLL packets with a protocol type of LINUX_SLL_P_CAN or
  1110. * LINUX_SLL_P_CANFD have SocketCAN headers in front of the payload,
  1111. * with the CAN ID being in host byte order.
  1112. *
  1113. * When reading a DLT_LINUX_SLL capture file, we need to check for those
  1114. * packets and convert the CAN ID from the byte order of the host that
  1115. * wrote the file to this host's byte order.
  1116. */
  1117. static void
  1118. swap_linux_sll_header(const struct pcap_pkthdr *hdr, u_char *buf)
  1119. {
  1120. u_int caplen = hdr->caplen;
  1121. u_int length = hdr->len;
  1122. struct sll_header *shdr = (struct sll_header *)buf;
  1123. uint16_t protocol;
  1124. pcap_can_socketcan_hdr *chdr;
  1125. if (caplen < (u_int) sizeof(struct sll_header) ||
  1126. length < (u_int) sizeof(struct sll_header)) {
  1127. /* Not enough data to have the protocol field */
  1128. return;
  1129. }
  1130. protocol = EXTRACT_16BITS(&shdr->sll_protocol);
  1131. if (protocol != LINUX_SLL_P_CAN && protocol != LINUX_SLL_P_CANFD)
  1132. return;
  1133. /*
  1134. * SocketCAN packet; fix up the packet's header.
  1135. */
  1136. chdr = (pcap_can_socketcan_hdr *)(buf + sizeof(struct sll_header));
  1137. if (caplen < (u_int) sizeof(struct sll_header) + sizeof(chdr->can_id) ||
  1138. length < (u_int) sizeof(struct sll_header) + sizeof(chdr->can_id)) {
  1139. /* Not enough data to have the CAN ID */
  1140. return;
  1141. }
  1142. chdr->can_id = SWAPLONG(chdr->can_id);
  1143. }
  1144. /*
  1145. * The DLT_USB_LINUX and DLT_USB_LINUX_MMAPPED headers are in host
  1146. * byte order when capturing (it's supplied directly from a
  1147. * memory-mapped buffer shared by the kernel).
  1148. *
  1149. * When reading a DLT_USB_LINUX or DLT_USB_LINUX_MMAPPED capture file,
  1150. * we need to convert it from the byte order of the host that wrote
  1151. * the file to this host's byte order.
  1152. */
  1153. static void
  1154. swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
  1155. int header_len_64_bytes)
  1156. {
  1157. pcap_usb_header_mmapped *uhdr = (pcap_usb_header_mmapped *)buf;
  1158. bpf_u_int32 offset = 0;
  1159. /*
  1160. * "offset" is the offset *past* the field we're swapping;
  1161. * we skip the field *before* checking to make sure
  1162. * the captured data length includes the entire field.
  1163. */
  1164. /*
  1165. * The URB id is a totally opaque value; do we really need to
  1166. * convert it to the reading host's byte order???
  1167. */
  1168. offset += 8; /* skip past id */
  1169. if (hdr->caplen < offset)
  1170. return;
  1171. uhdr->id = SWAPLL(uhdr->id);
  1172. offset += 4; /* skip past various 1-byte fields */
  1173. offset += 2; /* skip past bus_id */
  1174. if (hdr->caplen < offset)
  1175. return;
  1176. uhdr->bus_id = SWAPSHORT(uhdr->bus_id);
  1177. offset += 2; /* skip past various 1-byte fields */
  1178. offset += 8; /* skip past ts_sec */
  1179. if (hdr->caplen < offset)
  1180. return;
  1181. uhdr->ts_sec = SWAPLL(uhdr->ts_sec);
  1182. offset += 4; /* skip past ts_usec */
  1183. if (hdr->caplen < offset)
  1184. return;
  1185. uhdr->ts_usec = SWAPLONG(uhdr->ts_usec);
  1186. offset += 4; /* skip past status */
  1187. if (hdr->caplen < offset)
  1188. return;
  1189. uhdr->status = SWAPLONG(uhdr->status);
  1190. offset += 4; /* skip past urb_len */
  1191. if (hdr->caplen < offset)
  1192. return;
  1193. uhdr->urb_len = SWAPLONG(uhdr->urb_len);
  1194. offset += 4; /* skip past data_len */
  1195. if (hdr->caplen < offset)
  1196. return;
  1197. uhdr->data_len = SWAPLONG(uhdr->data_len);
  1198. if (uhdr->transfer_type == URB_ISOCHRONOUS) {
  1199. offset += 4; /* skip past s.iso.error_count */
  1200. if (hdr->caplen < offset)
  1201. return;
  1202. uhdr->s.iso.error_count = SWAPLONG(uhdr->s.iso.error_count);
  1203. offset += 4; /* skip past s.iso.numdesc */
  1204. if (hdr->caplen < offset)
  1205. return;
  1206. uhdr->s.iso.numdesc = SWAPLONG(uhdr->s.iso.numdesc);
  1207. } else
  1208. offset += 8; /* skip USB setup header */
  1209. /*
  1210. * With the old header, there are no isochronous descriptors
  1211. * after the header.
  1212. *
  1213. * With the new header, the actual number of descriptors in
  1214. * the header is not s.iso.numdesc, it's ndesc - only the
  1215. * first N descriptors, for some value of N, are put into
  1216. * the header, and ndesc is set to the actual number copied.
  1217. * In addition, if s.iso.numdesc is negative, no descriptors
  1218. * are captured, and ndesc is set to 0.
  1219. */
  1220. if (header_len_64_bytes) {
  1221. /*
  1222. * This is either the "version 1" header, with
  1223. * 16 bytes of additional fields at the end, or
  1224. * a "version 0" header from a memory-mapped
  1225. * capture, with 16 bytes of zeroed-out padding
  1226. * at the end. Byte swap them as if this were
  1227. * a "version 1" header.
  1228. */
  1229. offset += 4; /* skip past interval */
  1230. if (hdr->caplen < offset)
  1231. return;
  1232. uhdr->interval = SWAPLONG(uhdr->interval);
  1233. offset += 4; /* skip past start_frame */
  1234. if (hdr->caplen < offset)
  1235. return;
  1236. uhdr->start_frame = SWAPLONG(uhdr->start_frame);
  1237. offset += 4; /* skip past xfer_flags */
  1238. if (hdr->caplen < offset)
  1239. return;
  1240. uhdr->xfer_flags = SWAPLONG(uhdr->xfer_flags);
  1241. offset += 4; /* skip past ndesc */
  1242. if (hdr->caplen < offset)
  1243. return;
  1244. uhdr->ndesc = SWAPLONG(uhdr->ndesc);
  1245. if (uhdr->transfer_type == URB_ISOCHRONOUS) {
  1246. /* swap the values in struct linux_usb_isodesc */
  1247. usb_isodesc *pisodesc;
  1248. uint32_t i;
  1249. pisodesc = (usb_isodesc *)(void *)(buf+offset);
  1250. for (i = 0; i < uhdr->ndesc; i++) {
  1251. offset += 4; /* skip past status */
  1252. if (hdr->caplen < offset)
  1253. return;
  1254. pisodesc->status = SWAPLONG(pisodesc->status);
  1255. offset += 4; /* skip past offset */
  1256. if (hdr->caplen < offset)
  1257. return;
  1258. pisodesc->offset = SWAPLONG(pisodesc->offset);
  1259. offset += 4; /* skip past len */
  1260. if (hdr->caplen < offset)
  1261. return;
  1262. pisodesc->len = SWAPLONG(pisodesc->len);
  1263. offset += 4; /* skip past padding */
  1264. pisodesc++;
  1265. }
  1266. }
  1267. }
  1268. }
  1269. /*
  1270. * The DLT_NFLOG "packets" have a mixture of big-endian and host-byte-order
  1271. * data. They begin with a fixed-length header with big-endian fields,
  1272. * followed by a set of TLVs, where the type and length are in host
  1273. * byte order but the values are either big-endian or are a raw byte
  1274. * sequence that's the same regardless of the host's byte order.
  1275. *
  1276. * When reading a DLT_NFLOG capture file, we need to convert the type
  1277. * and length values from the byte order of the host that wrote the
  1278. * file to the byte order of this host.
  1279. */
  1280. static void
  1281. swap_nflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
  1282. {
  1283. u_char *p = buf;
  1284. nflog_hdr_t *nfhdr = (nflog_hdr_t *)buf;
  1285. nflog_tlv_t *tlv;
  1286. u_int caplen = hdr->caplen;
  1287. u_int length = hdr->len;
  1288. uint16_t size;
  1289. if (caplen < (u_int) sizeof(nflog_hdr_t) ||
  1290. length < (u_int) sizeof(nflog_hdr_t)) {
  1291. /* Not enough data to have any TLVs. */
  1292. return;
  1293. }
  1294. if (nfhdr->nflog_version != 0) {
  1295. /* Unknown NFLOG version */
  1296. return;
  1297. }
  1298. length -= sizeof(nflog_hdr_t);
  1299. caplen -= sizeof(nflog_hdr_t);
  1300. p += sizeof(nflog_hdr_t);
  1301. while (caplen >= sizeof(nflog_tlv_t)) {
  1302. tlv = (nflog_tlv_t *) p;
  1303. /* Swap the type and length. */
  1304. tlv->tlv_type = SWAPSHORT(tlv->tlv_type);
  1305. tlv->tlv_length = SWAPSHORT(tlv->tlv_length);
  1306. /* Get the length of the TLV. */
  1307. size = tlv->tlv_length;
  1308. if (size % 4 != 0)
  1309. size += 4 - size % 4;
  1310. /* Is the TLV's length less than the minimum? */
  1311. if (size < sizeof(nflog_tlv_t)) {
  1312. /* Yes. Give up now. */
  1313. return;
  1314. }
  1315. /* Do we have enough data for the full TLV? */
  1316. if (caplen < size || length < size) {
  1317. /* No. */
  1318. return;
  1319. }
  1320. /* Skip over the TLV. */
  1321. length -= size;
  1322. caplen -= size;
  1323. p += size;
  1324. }
  1325. }
  1326. void
  1327. swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data)
  1328. {
  1329. /*
  1330. * Convert pseudo-headers from the byte order of
  1331. * the host on which the file was saved to our
  1332. * byte order, as necessary.
  1333. */
  1334. switch (linktype) {
  1335. case DLT_LINUX_SLL:
  1336. swap_linux_sll_header(hdr, data);
  1337. break;
  1338. case DLT_USB_LINUX:
  1339. swap_linux_usb_header(hdr, data, 0);
  1340. break;
  1341. case DLT_USB_LINUX_MMAPPED:
  1342. swap_linux_usb_header(hdr, data, 1);
  1343. break;
  1344. case DLT_NFLOG:
  1345. swap_nflog_header(hdr, data);
  1346. break;
  1347. }
  1348. }