2 * Copyright (c) 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
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
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.
21 * savefile.c - supports offline use of tcpdump
22 * Extraction/creation by Jeffrey Mogul, DECWRL
23 * Modified by Steve McCanne, LBL.
25 * Used to save the received packet headers, after filtering, to
26 * a file, and then read them later.
27 * The first record in the file contains saved values for the machine
28 * dependent values so we can print the dump file on any architecture.
32 static const char rcsid
[] _U_
=
33 "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.183 2008-12-23 20:13:29 guy Exp $ (LBL)";
41 #include <pcap-stdinc.h>
48 #ifdef HAVE_SYS_BITYPES_H
49 #include <sys/bitypes.h>
51 #include <sys/types.h>
57 #include "pcap-common.h"
60 * We don't write DLT_* values to capture files, because they're not the
61 * same on all platforms.
63 * Unfortunately, the various flavors of BSD have not always used the same
64 * numerical values for the same data types, and various patches to
65 * libpcap for non-BSD OSes have added their own DLT_* codes for link
66 * layer encapsulation types seen on those OSes, and those codes have had,
67 * in some cases, values that were also used, on other platforms, for other
68 * link layer encapsulation types.
70 * This means that capture files of a type whose numerical DLT_* code
71 * means different things on different BSDs, or with different versions
72 * of libpcap, can't always be read on systems other than those like
73 * the one running on the machine on which the capture was made.
75 * Instead, we define here a set of LINKTYPE_* codes, and map DLT_* codes
76 * to LINKTYPE_* codes when writing a savefile header, and map LINKTYPE_*
77 * codes to DLT_* codes when reading a savefile header.
79 * For those DLT_* codes that have, as far as we know, the same values on
80 * all platforms (DLT_NULL through DLT_FDDI), we define LINKTYPE_xxx as
81 * DLT_xxx; that way, captures of those types can still be read by
82 * versions of libpcap that map LINKTYPE_* values to DLT_* values, and
83 * captures of those types written by versions of libpcap that map DLT_
84 * values to LINKTYPE_ values can still be read by older versions
87 * The other LINKTYPE_* codes are given values starting at 100, in the
88 * hopes that no DLT_* code will be given one of those values.
90 * In order to ensure that a given LINKTYPE_* code's value will refer to
91 * the same encapsulation type on all platforms, you should not allocate
92 * a new LINKTYPE_* value without consulting
93 * "tcpdump-workers@lists.tcpdump.org". The tcpdump developers will
94 * allocate a value for you, and will not subsequently allocate it to
95 * anybody else; that value will be added to the "pcap.h" in the
96 * tcpdump.org CVS repository, so that a future libpcap release will
99 * You should, if possible, also contribute patches to libpcap and tcpdump
100 * to handle the new encapsulation type, so that they can also be checked
101 * into the tcpdump.org CVS repository and so that they will appear in
102 * future libpcap and tcpdump releases.
104 * Do *NOT* assume that any values after the largest value in this file
105 * are available; you might not have the most up-to-date version of this
106 * file, and new values after that one might have been assigned. Also,
107 * do *NOT* use any values below 100 - those might already have been
108 * taken by one (or more!) organizations.
110 #define LINKTYPE_NULL DLT_NULL
111 #define LINKTYPE_ETHERNET DLT_EN10MB /* also for 100Mb and up */
112 #define LINKTYPE_EXP_ETHERNET DLT_EN3MB /* 3Mb experimental Ethernet */
113 #define LINKTYPE_AX25 DLT_AX25
114 #define LINKTYPE_PRONET DLT_PRONET
115 #define LINKTYPE_CHAOS DLT_CHAOS
116 #define LINKTYPE_TOKEN_RING DLT_IEEE802 /* DLT_IEEE802 is used for Token Ring */
117 #define LINKTYPE_ARCNET DLT_ARCNET /* BSD-style headers */
118 #define LINKTYPE_SLIP DLT_SLIP
119 #define LINKTYPE_PPP DLT_PPP
120 #define LINKTYPE_FDDI DLT_FDDI
123 * LINKTYPE_PPP is for use when there might, or might not, be an RFC 1662
124 * PPP in HDLC-like framing header (with 0xff 0x03 before the PPP protocol
125 * field) at the beginning of the packet.
127 * This is for use when there is always such a header; the address field
128 * might be 0xff, for regular PPP, or it might be an address field for Cisco
129 * point-to-point with HDLC framing as per section 4.3.1 of RFC 1547 ("Cisco
130 * HDLC"). This is, for example, what you get with NetBSD's DLT_PPP_SERIAL.
132 * We give it the same value as NetBSD's DLT_PPP_SERIAL, in the hopes that
133 * nobody else will choose a DLT_ value of 50, and so that DLT_PPP_SERIAL
134 * captures will be written out with a link type that NetBSD's tcpdump
137 #define LINKTYPE_PPP_HDLC 50 /* PPP in HDLC-like framing */
139 #define LINKTYPE_PPP_ETHER 51 /* NetBSD PPP-over-Ethernet */
141 #define LINKTYPE_SYMANTEC_FIREWALL 99 /* Symantec Enterprise Firewall */
143 #define LINKTYPE_ATM_RFC1483 100 /* LLC/SNAP-encapsulated ATM */
144 #define LINKTYPE_RAW 101 /* raw IP */
145 #define LINKTYPE_SLIP_BSDOS 102 /* BSD/OS SLIP BPF header */
146 #define LINKTYPE_PPP_BSDOS 103 /* BSD/OS PPP BPF header */
147 #define LINKTYPE_C_HDLC 104 /* Cisco HDLC */
148 #define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 (wireless) */
149 #define LINKTYPE_ATM_CLIP 106 /* Linux Classical IP over ATM */
150 #define LINKTYPE_FRELAY 107 /* Frame Relay */
151 #define LINKTYPE_LOOP 108 /* OpenBSD loopback */
152 #define LINKTYPE_ENC 109 /* OpenBSD IPSEC enc */
155 * These three types are reserved for future use.
157 #define LINKTYPE_LANE8023 110 /* ATM LANE + 802.3 */
158 #define LINKTYPE_HIPPI 111 /* NetBSD HIPPI */
159 #define LINKTYPE_HDLC 112 /* NetBSD HDLC framing */
161 #define LINKTYPE_LINUX_SLL 113 /* Linux cooked socket capture */
162 #define LINKTYPE_LTALK 114 /* Apple LocalTalk hardware */
163 #define LINKTYPE_ECONET 115 /* Acorn Econet */
166 * Reserved for use with OpenBSD ipfilter.
168 #define LINKTYPE_IPFILTER 116
170 #define LINKTYPE_PFLOG 117 /* OpenBSD DLT_PFLOG */
171 #define LINKTYPE_CISCO_IOS 118 /* For Cisco-internal use */
172 #define LINKTYPE_PRISM_HEADER 119 /* 802.11+Prism II monitor mode */
173 #define LINKTYPE_AIRONET_HEADER 120 /* FreeBSD Aironet driver stuff */
176 * Reserved for Siemens HiPath HDLC.
178 #define LINKTYPE_HHDLC 121
180 #define LINKTYPE_IP_OVER_FC 122 /* RFC 2625 IP-over-Fibre Channel */
181 #define LINKTYPE_SUNATM 123 /* Solaris+SunATM */
184 * Reserved as per request from Kent Dahlgren <kent@praesum.com>
187 #define LINKTYPE_RIO 124 /* RapidIO */
188 #define LINKTYPE_PCI_EXP 125 /* PCI Express */
189 #define LINKTYPE_AURORA 126 /* Xilinx Aurora link layer */
191 #define LINKTYPE_IEEE802_11_RADIO 127 /* 802.11 plus BSD radio header */
194 * Reserved for the TZSP encapsulation, as per request from
195 * Chris Waters <chris.waters@networkchemistry.com>
196 * TZSP is a generic encapsulation for any other link type,
197 * which includes a means to include meta-information
198 * with the packet, e.g. signal strength and channel
199 * for 802.11 packets.
201 #define LINKTYPE_TZSP 128 /* Tazmen Sniffer Protocol */
203 #define LINKTYPE_ARCNET_LINUX 129 /* Linux-style headers */
206 * Juniper-private data link types, as per request from
207 * Hannes Gredler <hannes@juniper.net>. The corresponding
208 * DLT_s are used for passing on chassis-internal
209 * metainformation such as QOS profiles, etc..
211 #define LINKTYPE_JUNIPER_MLPPP 130
212 #define LINKTYPE_JUNIPER_MLFR 131
213 #define LINKTYPE_JUNIPER_ES 132
214 #define LINKTYPE_JUNIPER_GGSN 133
215 #define LINKTYPE_JUNIPER_MFR 134
216 #define LINKTYPE_JUNIPER_ATM2 135
217 #define LINKTYPE_JUNIPER_SERVICES 136
218 #define LINKTYPE_JUNIPER_ATM1 137
220 #define LINKTYPE_APPLE_IP_OVER_IEEE1394 138 /* Apple IP-over-IEEE 1394 cooked header */
222 #define LINKTYPE_MTP2_WITH_PHDR 139
223 #define LINKTYPE_MTP2 140
224 #define LINKTYPE_MTP3 141
225 #define LINKTYPE_SCCP 142
227 #define LINKTYPE_DOCSIS 143 /* DOCSIS MAC frames */
229 #define LINKTYPE_LINUX_IRDA 144 /* Linux-IrDA */
232 * Reserved for IBM SP switch and IBM Next Federation switch.
234 #define LINKTYPE_IBM_SP 145
235 #define LINKTYPE_IBM_SN 146
238 * Reserved for private use. If you have some link-layer header type
239 * that you want to use within your organization, with the capture files
240 * using that link-layer header type not ever be sent outside your
241 * organization, you can use these values.
243 * No libpcap release will use these for any purpose, nor will any
244 * tcpdump release use them, either.
246 * Do *NOT* use these in capture files that you expect anybody not using
247 * your private versions of capture-file-reading tools to read; in
248 * particular, do *NOT* use them in products, otherwise you may find that
249 * people won't be able to use tcpdump, or snort, or Ethereal, or... to
250 * read capture files from your firewall/intrusion detection/traffic
251 * monitoring/etc. appliance, or whatever product uses that LINKTYPE_ value,
252 * and you may also find that the developers of those applications will
253 * not accept patches to let them read those files.
255 * Also, do not use them if somebody might send you a capture using them
256 * for *their* private type and tools using them for *your* private type
257 * would have to read them.
259 * Instead, in those cases, ask "tcpdump-workers@lists.tcpdump.org" for a
260 * new DLT_ and LINKTYPE_ value, as per the comment in pcap/bpf.h, and use
261 * the type you're given.
263 #define LINKTYPE_USER0 147
264 #define LINKTYPE_USER1 148
265 #define LINKTYPE_USER2 149
266 #define LINKTYPE_USER3 150
267 #define LINKTYPE_USER4 151
268 #define LINKTYPE_USER5 152
269 #define LINKTYPE_USER6 153
270 #define LINKTYPE_USER7 154
271 #define LINKTYPE_USER8 155
272 #define LINKTYPE_USER9 156
273 #define LINKTYPE_USER10 157
274 #define LINKTYPE_USER11 158
275 #define LINKTYPE_USER12 159
276 #define LINKTYPE_USER13 160
277 #define LINKTYPE_USER14 161
278 #define LINKTYPE_USER15 162
281 * For future use with 802.11 captures - defined by AbsoluteValue
282 * Systems to store a number of bits of link-layer information
283 * including radio information:
285 * http://www.shaftnet.org/~pizza/software/capturefrm.txt
287 * but could and arguably should also be used by non-AVS Linux
288 * 802.11 drivers; that may happen in the future.
290 #define LINKTYPE_IEEE802_11_RADIO_AVS 163 /* 802.11 plus AVS radio header */
293 * Juniper-private data link type, as per request from
294 * Hannes Gredler <hannes@juniper.net>. The corresponding
295 * DLT_s are used for passing on chassis-internal
296 * metainformation such as QOS profiles, etc..
298 #define LINKTYPE_JUNIPER_MONITOR 164
301 * Reserved for BACnet MS/TP.
303 #define LINKTYPE_BACNET_MS_TP 165
306 * Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
308 * This is used in some OSes to allow a kernel socket filter to distinguish
309 * between incoming and outgoing packets, on a socket intended to
310 * supply pppd with outgoing packets so it can do dial-on-demand and
311 * hangup-on-lack-of-demand; incoming packets are filtered out so they
312 * don't cause pppd to hold the connection up (you don't want random
313 * input packets such as port scans, packets from old lost connections,
314 * etc. to force the connection to stay up).
316 * The first byte of the PPP header (0xff03) is modified to accomodate
317 * the direction - 0x00 = IN, 0x01 = OUT.
319 #define LINKTYPE_PPP_PPPD 166
322 * Juniper-private data link type, as per request from
323 * Hannes Gredler <hannes@juniper.net>. The DLT_s are used
324 * for passing on chassis-internal metainformation such as
325 * QOS profiles, cookies, etc..
327 #define LINKTYPE_JUNIPER_PPPOE 167
328 #define LINKTYPE_JUNIPER_PPPOE_ATM 168
330 #define LINKTYPE_GPRS_LLC 169 /* GPRS LLC */
331 #define LINKTYPE_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */
332 #define LINKTYPE_GPF_F 171 /* GPF-T (ITU-T G.7041/Y.1303) */
335 * Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
336 * monitoring equipment.
338 #define LINKTYPE_GCOM_T1E1 172
339 #define LINKTYPE_GCOM_SERIAL 173
342 * Juniper-private data link type, as per request from
343 * Hannes Gredler <hannes@juniper.net>. The DLT_ is used
344 * for internal communication to Physical Interface Cards (PIC)
346 #define LINKTYPE_JUNIPER_PIC_PEER 174
349 * Link types requested by Gregor Maier <gregor@endace.com> of Endace
350 * Measurement Systems. They add an ERF header (see
351 * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
352 * the link-layer header.
354 #define LINKTYPE_ERF_ETH 175 /* Ethernet */
355 #define LINKTYPE_ERF_POS 176 /* Packet-over-SONET */
358 * Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
359 * for vISDN (http://www.orlandi.com/visdn/). Its link-layer header
360 * includes additional information before the LAPD header, so it's
361 * not necessarily a generic LAPD header.
363 #define LINKTYPE_LINUX_LAPD 177
366 * Juniper-private data link type, as per request from
367 * Hannes Gredler <hannes@juniper.net>.
368 * The Link Types are used for prepending meta-information
369 * like interface index, interface name
370 * before standard Ethernet, PPP, Frelay & C-HDLC Frames
372 #define LINKTYPE_JUNIPER_ETHER 178
373 #define LINKTYPE_JUNIPER_PPP 179
374 #define LINKTYPE_JUNIPER_FRELAY 180
375 #define LINKTYPE_JUNIPER_CHDLC 181
378 * Multi Link Frame Relay (FRF.16)
380 #define LINKTYPE_MFR 182
383 * Juniper-private data link type, as per request from
384 * Hannes Gredler <hannes@juniper.net>.
385 * The DLT_ is used for internal communication with a
386 * voice Adapter Card (PIC)
388 #define LINKTYPE_JUNIPER_VP 183
392 * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
393 * Every frame contains a 32bit A429 label.
394 * More documentation on Arinc 429 can be found at
395 * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf
397 #define LINKTYPE_A429 184
400 * Arinc 653 Interpartition Communication messages.
401 * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
402 * Please refer to the A653-1 standard for more information.
404 #define LINKTYPE_A653_ICM 185
407 * USB packets, beginning with a USB setup header; requested by
408 * Paolo Abeni <paolo.abeni@email.it>.
410 #define LINKTYPE_USB 186
413 * Bluetooth HCI UART transport layer (part H:4); requested by
416 #define LINKTYPE_BLUETOOTH_HCI_H4 187
419 * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz
420 * <cruz_petagay@bah.com>.
422 #define LINKTYPE_IEEE802_16_MAC_CPS 188
425 * USB packets, beginning with a Linux USB header; requested by
426 * Paolo Abeni <paolo.abeni@email.it>.
428 #define LINKTYPE_USB_LINUX 189
431 * Controller Area Network (CAN) v. 2.0B packets.
432 * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
433 * Used to dump CAN packets coming from a CAN Vector board.
434 * More documentation on the CAN v2.0B frames can be found at
435 * http://www.can-cia.org/downloads/?269
437 #define LINKTYPE_CAN20B 190
440 * IEEE 802.15.4, with address fields padded, as is done by Linux
441 * drivers; requested by Juergen Schimmer.
443 #define LINKTYPE_IEEE802_15_4_LINUX 191
446 * Per Packet Information encapsulated packets.
447 * LINKTYPE_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
449 #define LINKTYPE_PPI 192
452 * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header;
453 * requested by Charles Clancy.
455 #define LINKTYPE_IEEE802_16_MAC_CPS_RADIO 193
458 * Juniper-private data link type, as per request from
459 * Hannes Gredler <hannes@juniper.net>.
460 * The DLT_ is used for internal communication with a
461 * integrated service module (ISM).
463 #define LINKTYPE_JUNIPER_ISM 194
466 * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
467 * nothing); requested by Mikko Saarnivala <mikko.saarnivala@sensinode.com>.
469 #define LINKTYPE_IEEE802_15_4 195
472 * Various link-layer types, with a pseudo-header, for SITA
473 * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com).
475 #define LINKTYPE_SITA 196
478 * Various link-layer types, with a pseudo-header, for Endace DAG cards;
479 * encapsulates Endace ERF records. Requested by Stephen Donnelly
480 * <stephen@endace.com>.
482 #define LINKTYPE_ERF 197
485 * Special header prepended to Ethernet packets when capturing from a
486 * u10 Networks board. Requested by Phil Mulholland
487 * <phil@u10networks.com>.
489 #define LINKTYPE_RAIF1 198
492 * IPMB packet for IPMI, beginning with the I2C slave address, followed
493 * by the netFn and LUN, etc.. Requested by Chanthy Toeung
494 * <chanthy.toeung@ca.kontron.com>.
496 #define LINKTYPE_IPMB 199
499 * Juniper-private data link type, as per request from
500 * Hannes Gredler <hannes@juniper.net>.
501 * The DLT_ is used for capturing data on a secure tunnel interface.
503 #define LINKTYPE_JUNIPER_ST 200
506 * Bluetooth HCI UART transport layer (part H:4), with pseudo-header
507 * that includes direction information; requested by Paolo Abeni.
509 #define LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR 201
512 * AX.25 packet with a 1-byte KISS header; see
514 * http://www.ax25.net/kiss.htm
516 * as per Richard Stearn <richard@rns-stearn.demon.co.uk>.
518 #define LINKTYPE_AX25_KISS 202
521 * LAPD packets from an ISDN channel, starting with the address field,
522 * with no pseudo-header.
523 * Requested by Varuna De Silva <varunax@gmail.com>.
525 #define LINKTYPE_LAPD 203
528 * Variants of various link-layer headers, with a one-byte direction
529 * pseudo-header prepended - zero means "received by this host",
530 * non-zero (any non-zero value) means "sent by this host" - as per
531 * Will Barker <w.barker@zen.co.uk>.
533 #define LINKTYPE_PPP_WITH_DIR 204 /* PPP */
534 #define LINKTYPE_C_HDLC_WITH_DIR 205 /* Cisco HDLC */
535 #define LINKTYPE_FRELAY_WITH_DIR 206 /* Frame Relay */
536 #define LINKTYPE_LAPB_WITH_DIR 207 /* LAPB */
539 * 208 is reserved for an as-yet-unspecified proprietary link-layer
540 * type, as requested by Will Barker.
544 * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman
545 * <avn@pigeonpoint.com>.
547 #define LINKTYPE_IPMB_LINUX 209
550 * FlexRay automotive bus - http://www.flexray.com/ - as requested
551 * by Hannes Kaelber <hannes.kaelber@x2e.de>.
553 #define LINKTYPE_FLEXRAY 210
556 * Media Oriented Systems Transport (MOST) bus for multimedia
557 * transport - http://www.mostcooperation.com/ - as requested
558 * by Hannes Kaelber <hannes.kaelber@x2e.de>.
560 #define LINKTYPE_MOST 211
563 * Local Interconnect Network (LIN) bus for vehicle networks -
564 * http://www.lin-subbus.org/ - as requested by Hannes Kaelber
565 * <hannes.kaelber@x2e.de>.
567 #define LINKTYPE_LIN 212
570 * X2E-private data link type used for serial line capture,
571 * as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
573 #define LINKTYPE_X2E_SERIAL 213
576 * X2E-private data link type used for the Xoraya data logger
577 * family, as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
579 #define LINKTYPE_X2E_XORAYA 214
582 * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
583 * nothing), but with the PHY-level data for non-ASK PHYs (4 octets
584 * of 0 as preamble, one octet of SFD, one octet of frame length+
585 * reserved bit, and then the MAC-layer data, starting with the
586 * frame control field).
588 * Requested by Max Filippov <jcmvbkbc@gmail.com>.
590 #define LINKTYPE_IEEE802_15_4_NONASK_PHY 215
593 * David Gibson <david@gibson.dropbear.id.au> requested this for
594 * captures from the Linux kernel /dev/input/eventN devices. This
595 * is used to communicate keystrokes and mouse movements from the
596 * Linux kernel to display systems, such as Xorg.
598 #define LINKTYPE_LINUX_EVDEV 216
601 * GSM Um and Abis interfaces, preceded by a "gsmtap" header.
603 * Requested by Harald Welte <laforge@gnumonks.org>.
605 #define LINKTYPE_GSMTAP_UM 217
606 #define LINKTYPE_GSMTAP_ABIS 218
609 * MPLS, with an MPLS label as the link-layer header.
610 * Requested by Michele Marchetto <michele@openbsd.org> on behalf
613 #define LINKTYPE_MPLS 219
616 * USB packets, beginning with a Linux USB header, with the USB header
617 * padded to 64 bytes; required for memory-mapped access.
619 #define LINKTYPE_USB_LINUX_MMAPPED 220
622 * DECT packets, with a pseudo-header; requested by
623 * Matthias Wenzel <tcpdump@mazzoo.de>.
625 #define LINKTYPE_DECT 221
628 * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" <eric.lidwa-1@nasa.gov>
629 * Date: Mon, 11 May 2009 11:18:30 -0500
631 * DLT_AOS. We need it for AOS Space Data Link Protocol.
632 * I have already written dissectors for but need an OK from
633 * legal before I can submit a patch.
636 #define LINKTYPE_AOS 222
639 * Wireless HART (Highway Addressable Remote Transducer)
640 * From the HART Communication Foundation
643 * Requested by Sam Roberts <vieuxtech@gmail.com>.
645 #define LINKTYPE_WIHART 223
648 * Fibre Channel FC-2 frames, beginning with a Frame_Header.
649 * Requested by Kahou Lei <kahou82@gmail.com>.
651 #define LINKTYPE_FC_2 224
654 * Fibre Channel FC-2 frames, beginning with an encoding of the
655 * SOF, and ending with an encoding of the EOF.
657 * The encodings represent the frame delimiters as 4-byte sequences
658 * representing the corresponding ordered sets, with K28.5
659 * represented as 0xBC, and the D symbols as the corresponding
660 * byte values; for example, SOFi2, which is K28.5 - D21.5 - D1.2 - D21.2,
661 * is represented as 0xBC 0xB5 0x55 0x55.
663 * Requested by Kahou Lei <kahou82@gmail.com>.
665 #define LINKTYPE_FC_2_WITH_FRAME_DELIMS 225
668 * Solaris ipnet pseudo-header; requested by Darren Reed <Darren.Reed@Sun.COM>.
670 * The pseudo-header starts with a one-byte version number; for version 2,
671 * the pseudo-header is:
673 * struct dl_ipnetinfo {
674 * u_int8_t dli_version;
675 * u_int8_t dli_family;
676 * u_int16_t dli_htype;
677 * u_int32_t dli_pktlen;
678 * u_int32_t dli_ifindex;
679 * u_int32_t dli_grifindex;
680 * u_int32_t dli_zsrc;
681 * u_int32_t dli_zdst;
684 * dli_version is 2 for the current version of the pseudo-header.
686 * dli_family is a Solaris address family value, so it's 2 for IPv4
689 * dli_htype is a "hook type" - 0 for incoming packets, 1 for outgoing
690 * packets, and 2 for packets arriving from another zone on the same
693 * dli_pktlen is the length of the packet data following the pseudo-header
694 * (so the captured length minus dli_pktlen is the length of the
695 * pseudo-header, assuming the entire pseudo-header was captured).
697 * dli_ifindex is the interface index of the interface on which the
700 * dli_grifindex is the group interface index number (for IPMP interfaces).
702 * dli_zsrc is the zone identifier for the source of the packet.
704 * dli_zdst is the zone identifier for the destination of the packet.
706 * A zone number of 0 is the global zone; a zone number of 0xffffffff
707 * means that the packet arrived from another host on the network, not
708 * from another zone on the same machine.
710 * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates
711 * which of those it is.
713 #define LINKTYPE_IPNET 226
716 * CAN (Controller Area Network) frames, with a pseudo-header as supplied
717 * by Linux SocketCAN. See Documentation/networking/can.txt in the Linux
720 * Requested by Felix Obenhuber <felix@obenhuber.de>.
722 #define LINKTYPE_CAN_SOCKETCAN 227
725 * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies
726 * whether it's v4 or v6. Requested by Darren Reed <Darren.Reed@Sun.COM>.
728 #define LINKTYPE_IPV4 228
729 #define LINKTYPE_IPV6 229
732 static struct linktype_map
{
737 * These DLT_* codes have LINKTYPE_* codes with values identical
738 * to the values of the corresponding DLT_* code.
740 { DLT_NULL
, LINKTYPE_NULL
},
741 { DLT_EN10MB
, LINKTYPE_ETHERNET
},
742 { DLT_EN3MB
, LINKTYPE_EXP_ETHERNET
},
743 { DLT_AX25
, LINKTYPE_AX25
},
744 { DLT_PRONET
, LINKTYPE_PRONET
},
745 { DLT_CHAOS
, LINKTYPE_CHAOS
},
746 { DLT_IEEE802
, LINKTYPE_TOKEN_RING
},
747 { DLT_ARCNET
, LINKTYPE_ARCNET
},
748 { DLT_SLIP
, LINKTYPE_SLIP
},
749 { DLT_PPP
, LINKTYPE_PPP
},
750 { DLT_FDDI
, LINKTYPE_FDDI
},
753 * These DLT_* codes have different values on different
754 * platforms; we map them to LINKTYPE_* codes that
755 * have values that should never be equal to any DLT_*
759 /* BSD/OS Frame Relay */
760 { DLT_FR
, LINKTYPE_FRELAY
},
763 { DLT_SYMANTEC_FIREWALL
, LINKTYPE_SYMANTEC_FIREWALL
},
764 { DLT_ATM_RFC1483
, LINKTYPE_ATM_RFC1483
},
765 { DLT_RAW
, LINKTYPE_RAW
},
766 { DLT_SLIP_BSDOS
, LINKTYPE_SLIP_BSDOS
},
767 { DLT_PPP_BSDOS
, LINKTYPE_PPP_BSDOS
},
769 /* BSD/OS Cisco HDLC */
770 { DLT_C_HDLC
, LINKTYPE_C_HDLC
},
773 * These DLT_* codes are not on all platforms, but, so far,
774 * there don't appear to be any platforms that define
775 * other codes with those values; we map them to
776 * different LINKTYPE_* values anyway, just in case.
779 /* Linux ATM Classical IP */
780 { DLT_ATM_CLIP
, LINKTYPE_ATM_CLIP
},
782 /* NetBSD sync/async serial PPP (or Cisco HDLC) */
783 { DLT_PPP_SERIAL
, LINKTYPE_PPP_HDLC
},
785 /* NetBSD PPP over Ethernet */
786 { DLT_PPP_ETHER
, LINKTYPE_PPP_ETHER
},
788 /* IEEE 802.11 wireless */
789 { DLT_IEEE802_11
, LINKTYPE_IEEE802_11
},
792 { DLT_FRELAY
, LINKTYPE_FRELAY
},
794 /* OpenBSD loopback */
795 { DLT_LOOP
, LINKTYPE_LOOP
},
797 /* OpenBSD IPSEC enc */
798 { DLT_ENC
, LINKTYPE_ENC
},
800 /* Linux cooked socket capture */
801 { DLT_LINUX_SLL
, LINKTYPE_LINUX_SLL
},
803 /* Apple LocalTalk hardware */
804 { DLT_LTALK
, LINKTYPE_LTALK
},
807 { DLT_ECONET
, LINKTYPE_ECONET
},
809 /* OpenBSD DLT_PFLOG */
810 { DLT_PFLOG
, LINKTYPE_PFLOG
},
812 /* For Cisco-internal use */
813 { DLT_CISCO_IOS
, LINKTYPE_CISCO_IOS
},
815 /* Prism II monitor-mode header plus 802.11 header */
816 { DLT_PRISM_HEADER
, LINKTYPE_PRISM_HEADER
},
818 /* FreeBSD Aironet driver stuff */
819 { DLT_AIRONET_HEADER
, LINKTYPE_AIRONET_HEADER
},
821 /* Siemens HiPath HDLC */
822 { DLT_HHDLC
, LINKTYPE_HHDLC
},
824 /* RFC 2625 IP-over-Fibre Channel */
825 { DLT_IP_OVER_FC
, LINKTYPE_IP_OVER_FC
},
828 { DLT_SUNATM
, LINKTYPE_SUNATM
},
831 { DLT_RIO
, LINKTYPE_RIO
},
834 { DLT_PCI_EXP
, LINKTYPE_PCI_EXP
},
836 /* Xilinx Aurora link layer */
837 { DLT_AURORA
, LINKTYPE_AURORA
},
839 /* 802.11 plus BSD radio header */
840 { DLT_IEEE802_11_RADIO
, LINKTYPE_IEEE802_11_RADIO
},
842 /* Tazmen Sniffer Protocol */
843 { DLT_TZSP
, LINKTYPE_TZSP
},
845 /* Arcnet with Linux-style link-layer headers */
846 { DLT_ARCNET_LINUX
, LINKTYPE_ARCNET_LINUX
},
848 /* Juniper-internal chassis encapsulation */
849 { DLT_JUNIPER_MLPPP
, LINKTYPE_JUNIPER_MLPPP
},
850 { DLT_JUNIPER_MLFR
, LINKTYPE_JUNIPER_MLFR
},
851 { DLT_JUNIPER_ES
, LINKTYPE_JUNIPER_ES
},
852 { DLT_JUNIPER_GGSN
, LINKTYPE_JUNIPER_GGSN
},
853 { DLT_JUNIPER_MFR
, LINKTYPE_JUNIPER_MFR
},
854 { DLT_JUNIPER_ATM2
, LINKTYPE_JUNIPER_ATM2
},
855 { DLT_JUNIPER_SERVICES
, LINKTYPE_JUNIPER_SERVICES
},
856 { DLT_JUNIPER_ATM1
, LINKTYPE_JUNIPER_ATM1
},
858 /* Apple IP-over-IEEE 1394 cooked header */
859 { DLT_APPLE_IP_OVER_IEEE1394
, LINKTYPE_APPLE_IP_OVER_IEEE1394
},
862 { DLT_MTP2_WITH_PHDR
, LINKTYPE_MTP2_WITH_PHDR
},
863 { DLT_MTP2
, LINKTYPE_MTP2
},
864 { DLT_MTP3
, LINKTYPE_MTP3
},
865 { DLT_SCCP
, LINKTYPE_SCCP
},
867 /* DOCSIS MAC frames */
868 { DLT_DOCSIS
, LINKTYPE_DOCSIS
},
870 /* IrDA IrLAP packets + Linux-cooked header */
871 { DLT_LINUX_IRDA
, LINKTYPE_LINUX_IRDA
},
873 /* IBM SP and Next Federation switches */
874 { DLT_IBM_SP
, LINKTYPE_IBM_SP
},
875 { DLT_IBM_SN
, LINKTYPE_IBM_SN
},
877 /* 802.11 plus AVS radio header */
878 { DLT_IEEE802_11_RADIO_AVS
, LINKTYPE_IEEE802_11_RADIO_AVS
},
881 * Any platform that defines additional DLT_* codes should:
883 * request a LINKTYPE_* code and value from tcpdump.org,
886 * add, in their version of libpcap, an entry to map
887 * those DLT_* codes to the corresponding LINKTYPE_*
890 * redefine, in their "net/bpf.h", any DLT_* values
891 * that collide with the values used by their additional
892 * DLT_* codes, to remove those collisions (but without
893 * making them collide with any of the LINKTYPE_*
894 * values equal to 50 or above; they should also avoid
895 * defining DLT_* values that collide with those
896 * LINKTYPE_* values, either).
899 /* Juniper-internal chassis encapsulation */
900 { DLT_JUNIPER_MONITOR
, LINKTYPE_JUNIPER_MONITOR
},
903 { DLT_BACNET_MS_TP
, LINKTYPE_BACNET_MS_TP
},
905 /* PPP for pppd, with direction flag in the PPP header */
906 { DLT_PPP_PPPD
, LINKTYPE_PPP_PPPD
},
908 /* Juniper-internal chassis encapsulation */
909 { DLT_JUNIPER_PPPOE
, LINKTYPE_JUNIPER_PPPOE
},
910 { DLT_JUNIPER_PPPOE_ATM
,LINKTYPE_JUNIPER_PPPOE_ATM
},
913 { DLT_GPRS_LLC
, LINKTYPE_GPRS_LLC
},
915 /* Transparent Generic Framing Procedure (ITU-T G.7041/Y.1303) */
916 { DLT_GPF_T
, LINKTYPE_GPF_T
},
918 /* Framed Generic Framing Procedure (ITU-T G.7041/Y.1303) */
919 { DLT_GPF_F
, LINKTYPE_GPF_F
},
921 { DLT_GCOM_T1E1
, LINKTYPE_GCOM_T1E1
},
922 { DLT_GCOM_SERIAL
, LINKTYPE_GCOM_SERIAL
},
924 /* Juniper-internal chassis encapsulation */
925 { DLT_JUNIPER_PIC_PEER
, LINKTYPE_JUNIPER_PIC_PEER
},
928 { DLT_ERF_ETH
, LINKTYPE_ERF_ETH
},
929 { DLT_ERF_POS
, LINKTYPE_ERF_POS
},
932 { DLT_LINUX_LAPD
, LINKTYPE_LINUX_LAPD
},
934 /* Juniper meta-information before Ether, PPP, Frame Relay, C-HDLC Frames */
935 { DLT_JUNIPER_ETHER
, LINKTYPE_JUNIPER_ETHER
},
936 { DLT_JUNIPER_PPP
, LINKTYPE_JUNIPER_PPP
},
937 { DLT_JUNIPER_FRELAY
, LINKTYPE_JUNIPER_FRELAY
},
938 { DLT_JUNIPER_CHDLC
, LINKTYPE_JUNIPER_CHDLC
},
940 /* Multi Link Frame Relay (FRF.16) */
941 { DLT_MFR
, LINKTYPE_MFR
},
943 /* Juniper Voice PIC */
944 { DLT_JUNIPER_VP
, LINKTYPE_JUNIPER_VP
},
946 /* Controller Area Network (CAN) v2.0B */
947 { DLT_A429
, LINKTYPE_A429
},
949 /* Arinc 653 Interpartition Communication messages */
950 { DLT_A653_ICM
, LINKTYPE_A653_ICM
},
953 { DLT_USB
, LINKTYPE_USB
},
955 /* Bluetooth HCI UART transport layer */
956 { DLT_BLUETOOTH_HCI_H4
, LINKTYPE_BLUETOOTH_HCI_H4
},
958 /* IEEE 802.16 MAC Common Part Sublayer */
959 { DLT_IEEE802_16_MAC_CPS
, LINKTYPE_IEEE802_16_MAC_CPS
},
961 /* USB with Linux header */
962 { DLT_USB_LINUX
, LINKTYPE_USB_LINUX
},
964 /* Controller Area Network (CAN) v2.0B */
965 { DLT_CAN20B
, LINKTYPE_CAN20B
},
967 /* IEEE 802.15.4 with address fields padded */
968 { DLT_IEEE802_15_4_LINUX
, LINKTYPE_IEEE802_15_4_LINUX
},
970 /* Per Packet Information encapsulated packets */
971 { DLT_PPI
, LINKTYPE_PPI
},
973 /* IEEE 802.16 MAC Common Part Sublayer plus radiotap header */
974 { DLT_IEEE802_16_MAC_CPS_RADIO
, LINKTYPE_IEEE802_16_MAC_CPS_RADIO
},
976 /* Juniper Voice ISM */
977 { DLT_JUNIPER_ISM
, LINKTYPE_JUNIPER_ISM
},
979 /* IEEE 802.15.4 exactly as it appears in the spec */
980 { DLT_IEEE802_15_4
, LINKTYPE_IEEE802_15_4
},
982 /* Various link-layer types for SITA */
983 { DLT_SITA
, LINKTYPE_SITA
},
985 /* Various link-layer types for Endace */
986 { DLT_ERF
, LINKTYPE_ERF
},
988 /* Special header for u10 Networks boards */
989 { DLT_RAIF1
, LINKTYPE_RAIF1
},
992 { DLT_IPMB
, LINKTYPE_IPMB
},
994 /* Juniper Secure Tunnel */
995 { DLT_JUNIPER_ST
, LINKTYPE_JUNIPER_ST
},
997 /* Bluetooth HCI UART transport layer, with pseudo-header */
998 { DLT_BLUETOOTH_HCI_H4_WITH_PHDR
, LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR
},
1000 /* AX.25 with KISS header */
1001 { DLT_AX25_KISS
, LINKTYPE_AX25_KISS
},
1003 /* Raw LAPD, with no pseudo-header */
1004 { DLT_LAPD
, LINKTYPE_LAPD
},
1006 /* PPP with one-byte pseudo-header giving direction */
1007 { DLT_PPP_WITH_DIR
, LINKTYPE_PPP_WITH_DIR
},
1009 /* Cisco HDLC with one-byte pseudo-header giving direction */
1010 { DLT_C_HDLC_WITH_DIR
, LINKTYPE_C_HDLC_WITH_DIR
},
1012 /* Frame Relay with one-byte pseudo-header giving direction */
1013 { DLT_FRELAY_WITH_DIR
, LINKTYPE_FRELAY_WITH_DIR
},
1015 /* LAPB with one-byte pseudo-header giving direction */
1016 { DLT_LAPB_WITH_DIR
, LINKTYPE_LAPB_WITH_DIR
},
1018 /* IPMB with Linux pseudo-header */
1019 { DLT_IPMB_LINUX
, LINKTYPE_IPMB_LINUX
},
1022 { DLT_FLEXRAY
, LINKTYPE_FLEXRAY
},
1025 { DLT_MOST
, LINKTYPE_MOST
},
1028 { DLT_LIN
, LINKTYPE_LIN
},
1030 /* X2E-private serial line capture */
1031 { DLT_X2E_SERIAL
, LINKTYPE_X2E_SERIAL
},
1033 /* X2E-private for Xoraya data logger family */
1034 { DLT_X2E_XORAYA
, LINKTYPE_X2E_XORAYA
},
1036 /* IEEE 802.15.4 with PHY data for non-ASK PHYs */
1037 { DLT_IEEE802_15_4_NONASK_PHY
, LINKTYPE_IEEE802_15_4_NONASK_PHY
},
1039 /* Input device events from Linux /dev/input/eventN devices */
1040 { DLT_LINUX_EVDEV
, LINKTYPE_LINUX_EVDEV
},
1043 { DLT_GSMTAP_UM
, LINKTYPE_GSMTAP_UM
},
1044 { DLT_GSMTAP_ABIS
, LINKTYPE_GSMTAP_ABIS
},
1046 /* MPLS, with an MPLS label as the link-layer header */
1047 { DLT_MPLS
, LINKTYPE_MPLS
},
1049 /* USB with padded Linux header */
1050 { DLT_USB_LINUX_MMAPPED
, LINKTYPE_USB_LINUX_MMAPPED
},
1052 /* DECT packets with a pseudo-header */
1053 { DLT_DECT
, LINKTYPE_DECT
},
1055 /* AOS Space Data Link Protocol */
1056 { DLT_AOS
, LINKTYPE_AOS
},
1059 { DLT_WIHART
, LINKTYPE_WIHART
},
1061 /* Fibre Channel FC-2 frames without SOF or EOF */
1062 { DLT_FC_2
, LINKTYPE_FC_2
},
1064 /* Fibre Channel FC-2 frames with SOF and EOF */
1065 { DLT_FC_2_WITH_FRAME_DELIMS
, LINKTYPE_FC_2_WITH_FRAME_DELIMS
},
1068 { DLT_IPNET
, LINKTYPE_IPNET
},
1070 /* CAN frames with SocketCAN headers */
1071 { DLT_CAN_SOCKETCAN
, LINKTYPE_CAN_SOCKETCAN
},
1074 { DLT_IPV4
, LINKTYPE_IPV4
},
1075 { DLT_IPV6
, LINKTYPE_IPV6
},
1081 dlt_to_linktype(int dlt
)
1085 for (i
= 0; map
[i
].dlt
!= -1; i
++) {
1086 if (map
[i
].dlt
== dlt
)
1087 return (map
[i
].linktype
);
1091 * If we don't have a mapping for this DLT_ code, return an
1092 * error; that means that the table above needs to have an
1099 linktype_to_dlt(int linktype
)
1103 for (i
= 0; map
[i
].linktype
!= -1; i
++) {
1104 if (map
[i
].linktype
== linktype
)
1105 return (map
[i
].dlt
);
1109 * If we don't have an entry for this link type, return
1110 * the link type value; it may be a DLT_ value from an
1111 * older version of libpcap.
1117 * The DLT_USB_LINUX and DLT_USB_LINUX_MMAPPED headers are in host
1118 * byte order when capturing (it's supplied directly from a
1119 * memory-mapped buffer shared by the kernel).
1121 * When reading a DLT_USB_LINUX or DLT_USB_LINUX_MMAPPED capture file,
1122 * we need to convert it from the capturing host's byte order to
1123 * the reading host's byte order.
1126 swap_linux_usb_header(const struct pcap_pkthdr
*hdr
, u_char
*buf
)
1128 pcap_usb_header
*uhdr
= (pcap_usb_header
*)buf
;
1131 * The URB id is a totally opaque value; do we really need to
1132 * convert it to the reading host's byte order???
1134 if (hdr
->caplen
< 8)
1136 uhdr
->id
= SWAPLL(uhdr
->id
);
1137 if (hdr
->caplen
< 14)
1139 uhdr
->bus_id
= SWAPSHORT(uhdr
->bus_id
);
1140 if (hdr
->caplen
< 24)
1142 uhdr
->ts_sec
= SWAPLL(uhdr
->ts_sec
);
1143 if (hdr
->caplen
< 28)
1145 uhdr
->ts_usec
= SWAPLONG(uhdr
->ts_usec
);
1146 if (hdr
->caplen
< 32)
1148 uhdr
->status
= SWAPLONG(uhdr
->status
);
1149 if (hdr
->caplen
< 36)
1151 uhdr
->urb_len
= SWAPLONG(uhdr
->urb_len
);
1152 if (hdr
->caplen
< 40)
1154 uhdr
->data_len
= SWAPLONG(uhdr
->data_len
);