fm/ipmitopo: fix 64-bit compilation
[unleashed.git] / contrib / libpcap / pcap-common.c
blob84368f6cefa6867329871f6949a3ba778c87f530
1 /*
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
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.
21 * pcap-common.c - common code for pcap and pcap-ng files
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #ifdef _WIN32
29 #include <pcap-stdinc.h>
30 #else /* _WIN32 */
31 #if HAVE_INTTYPES_H
32 #include <inttypes.h>
33 #elif HAVE_STDINT_H
34 #include <stdint.h>
35 #endif
36 #ifdef HAVE_SYS_BITYPES_H
37 #include <sys/bitypes.h>
38 #endif
39 #include <sys/types.h>
40 #endif /* _WIN32 */
42 #include "pcap-int.h"
43 #include "extract.h"
44 #include "pcap/sll.h"
45 #include "pcap/usb.h"
46 #include "pcap/nflog.h"
47 #include "pcap/can_socketcan.h"
49 #include "pcap-common.h"
52 * We don't write DLT_* values to capture files, because they're not the
53 * same on all platforms.
55 * Unfortunately, the various flavors of BSD have not always used the same
56 * numerical values for the same data types, and various patches to
57 * libpcap for non-BSD OSes have added their own DLT_* codes for link
58 * layer encapsulation types seen on those OSes, and those codes have had,
59 * in some cases, values that were also used, on other platforms, for other
60 * link layer encapsulation types.
62 * This means that capture files of a type whose numerical DLT_* code
63 * means different things on different BSDs, or with different versions
64 * of libpcap, can't always be read on systems other than those like
65 * the one running on the machine on which the capture was made.
67 * Instead, we define here a set of LINKTYPE_* codes, and map DLT_* codes
68 * to LINKTYPE_* codes when writing a savefile header, and map LINKTYPE_*
69 * codes to DLT_* codes when reading a savefile header.
71 * For those DLT_* codes that have, as far as we know, the same values on
72 * all platforms (DLT_NULL through DLT_FDDI), we define LINKTYPE_xxx as
73 * DLT_xxx; that way, captures of those types can still be read by
74 * versions of libpcap that map LINKTYPE_* values to DLT_* values, and
75 * captures of those types written by versions of libpcap that map DLT_
76 * values to LINKTYPE_ values can still be read by older versions
77 * of libpcap.
79 * The other LINKTYPE_* codes are given values starting at 100, in the
80 * hopes that no DLT_* code will be given one of those values.
82 * In order to ensure that a given LINKTYPE_* code's value will refer to
83 * the same encapsulation type on all platforms, you should not allocate
84 * a new LINKTYPE_* value without consulting
85 * "tcpdump-workers@lists.tcpdump.org". The tcpdump developers will
86 * allocate a value for you, and will not subsequently allocate it to
87 * anybody else; that value will be added to the "pcap.h" in the
88 * tcpdump.org Git repository, so that a future libpcap release will
89 * include it.
91 * You should, if possible, also contribute patches to libpcap and tcpdump
92 * to handle the new encapsulation type, so that they can also be checked
93 * into the tcpdump.org Git repository and so that they will appear in
94 * future libpcap and tcpdump releases.
96 * Do *NOT* assume that any values after the largest value in this file
97 * are available; you might not have the most up-to-date version of this
98 * file, and new values after that one might have been assigned. Also,
99 * do *NOT* use any values below 100 - those might already have been
100 * taken by one (or more!) organizations.
102 * Any platform that defines additional DLT_* codes should:
104 * request a LINKTYPE_* code and value from tcpdump.org,
105 * as per the above;
107 * add, in their version of libpcap, an entry to map
108 * those DLT_* codes to the corresponding LINKTYPE_*
109 * code;
111 * redefine, in their "net/bpf.h", any DLT_* values
112 * that collide with the values used by their additional
113 * DLT_* codes, to remove those collisions (but without
114 * making them collide with any of the LINKTYPE_*
115 * values equal to 50 or above; they should also avoid
116 * defining DLT_* values that collide with those
117 * LINKTYPE_* values, either).
119 #define LINKTYPE_NULL DLT_NULL
120 #define LINKTYPE_ETHERNET DLT_EN10MB /* also for 100Mb and up */
121 #define LINKTYPE_EXP_ETHERNET DLT_EN3MB /* 3Mb experimental Ethernet */
122 #define LINKTYPE_AX25 DLT_AX25
123 #define LINKTYPE_PRONET DLT_PRONET
124 #define LINKTYPE_CHAOS DLT_CHAOS
125 #define LINKTYPE_IEEE802_5 DLT_IEEE802 /* DLT_IEEE802 is used for 802.5 Token Ring */
126 #define LINKTYPE_ARCNET_BSD DLT_ARCNET /* BSD-style headers */
127 #define LINKTYPE_SLIP DLT_SLIP
128 #define LINKTYPE_PPP DLT_PPP
129 #define LINKTYPE_FDDI DLT_FDDI
132 * LINKTYPE_PPP is for use when there might, or might not, be an RFC 1662
133 * PPP in HDLC-like framing header (with 0xff 0x03 before the PPP protocol
134 * field) at the beginning of the packet.
136 * This is for use when there is always such a header; the address field
137 * might be 0xff, for regular PPP, or it might be an address field for Cisco
138 * point-to-point with HDLC framing as per section 4.3.1 of RFC 1547 ("Cisco
139 * HDLC"). This is, for example, what you get with NetBSD's DLT_PPP_SERIAL.
141 * We give it the same value as NetBSD's DLT_PPP_SERIAL, in the hopes that
142 * nobody else will choose a DLT_ value of 50, and so that DLT_PPP_SERIAL
143 * captures will be written out with a link type that NetBSD's tcpdump
144 * can read.
146 #define LINKTYPE_PPP_HDLC 50 /* PPP in HDLC-like framing */
148 #define LINKTYPE_PPP_ETHER 51 /* NetBSD PPP-over-Ethernet */
150 #define LINKTYPE_SYMANTEC_FIREWALL 99 /* Symantec Enterprise Firewall */
153 * These correspond to DLT_s that have different values on different
154 * platforms; we map between these values in capture files and
155 * the DLT_ values as returned by pcap_datalink() and passed to
156 * pcap_open_dead().
158 #define LINKTYPE_ATM_RFC1483 100 /* LLC/SNAP-encapsulated ATM */
159 #define LINKTYPE_RAW 101 /* raw IP */
160 #define LINKTYPE_SLIP_BSDOS 102 /* BSD/OS SLIP BPF header */
161 #define LINKTYPE_PPP_BSDOS 103 /* BSD/OS PPP BPF header */
164 * Values starting with 104 are used for newly-assigned link-layer
165 * header type values; for those link-layer header types, the DLT_
166 * value returned by pcap_datalink() and passed to pcap_open_dead(),
167 * and the LINKTYPE_ value that appears in capture files, are the
168 * same.
170 * LINKTYPE_MATCHING_MIN is the lowest such value; LINKTYPE_MATCHING_MAX
171 * is the highest such value.
173 #define LINKTYPE_MATCHING_MIN 104 /* lowest value in the "matching" range */
175 #define LINKTYPE_C_HDLC 104 /* Cisco HDLC */
176 #define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 (wireless) */
177 #define LINKTYPE_ATM_CLIP 106 /* Linux Classical IP over ATM */
178 #define LINKTYPE_FRELAY 107 /* Frame Relay */
179 #define LINKTYPE_LOOP 108 /* OpenBSD loopback */
180 #define LINKTYPE_ENC 109 /* OpenBSD IPSEC enc */
183 * These three types are reserved for future use.
185 #define LINKTYPE_LANE8023 110 /* ATM LANE + 802.3 */
186 #define LINKTYPE_HIPPI 111 /* NetBSD HIPPI */
187 #define LINKTYPE_HDLC 112 /* NetBSD HDLC framing */
189 #define LINKTYPE_LINUX_SLL 113 /* Linux cooked socket capture */
190 #define LINKTYPE_LTALK 114 /* Apple LocalTalk hardware */
191 #define LINKTYPE_ECONET 115 /* Acorn Econet */
194 * Reserved for use with OpenBSD ipfilter.
196 #define LINKTYPE_IPFILTER 116
198 #define LINKTYPE_PFLOG 117 /* OpenBSD DLT_PFLOG */
199 #define LINKTYPE_CISCO_IOS 118 /* For Cisco-internal use */
200 #define LINKTYPE_IEEE802_11_PRISM 119 /* 802.11 plus Prism II monitor mode radio metadata header */
201 #define LINKTYPE_IEEE802_11_AIRONET 120 /* 802.11 plus FreeBSD Aironet driver radio metadata header */
204 * Reserved for Siemens HiPath HDLC.
206 #define LINKTYPE_HHDLC 121
208 #define LINKTYPE_IP_OVER_FC 122 /* RFC 2625 IP-over-Fibre Channel */
209 #define LINKTYPE_SUNATM 123 /* Solaris+SunATM */
212 * Reserved as per request from Kent Dahlgren <kent@praesum.com>
213 * for private use.
215 #define LINKTYPE_RIO 124 /* RapidIO */
216 #define LINKTYPE_PCI_EXP 125 /* PCI Express */
217 #define LINKTYPE_AURORA 126 /* Xilinx Aurora link layer */
219 #define LINKTYPE_IEEE802_11_RADIOTAP 127 /* 802.11 plus radiotap radio metadata header */
222 * Reserved for the TZSP encapsulation, as per request from
223 * Chris Waters <chris.waters@networkchemistry.com>
224 * TZSP is a generic encapsulation for any other link type,
225 * which includes a means to include meta-information
226 * with the packet, e.g. signal strength and channel
227 * for 802.11 packets.
229 #define LINKTYPE_TZSP 128 /* Tazmen Sniffer Protocol */
231 #define LINKTYPE_ARCNET_LINUX 129 /* Linux-style headers */
234 * Juniper-private data link types, as per request from
235 * Hannes Gredler <hannes@juniper.net>. The corresponding
236 * DLT_s are used for passing on chassis-internal
237 * metainformation such as QOS profiles, etc..
239 #define LINKTYPE_JUNIPER_MLPPP 130
240 #define LINKTYPE_JUNIPER_MLFR 131
241 #define LINKTYPE_JUNIPER_ES 132
242 #define LINKTYPE_JUNIPER_GGSN 133
243 #define LINKTYPE_JUNIPER_MFR 134
244 #define LINKTYPE_JUNIPER_ATM2 135
245 #define LINKTYPE_JUNIPER_SERVICES 136
246 #define LINKTYPE_JUNIPER_ATM1 137
248 #define LINKTYPE_APPLE_IP_OVER_IEEE1394 138 /* Apple IP-over-IEEE 1394 cooked header */
250 #define LINKTYPE_MTP2_WITH_PHDR 139
251 #define LINKTYPE_MTP2 140
252 #define LINKTYPE_MTP3 141
253 #define LINKTYPE_SCCP 142
255 #define LINKTYPE_DOCSIS 143 /* DOCSIS MAC frames */
257 #define LINKTYPE_LINUX_IRDA 144 /* Linux-IrDA */
260 * Reserved for IBM SP switch and IBM Next Federation switch.
262 #define LINKTYPE_IBM_SP 145
263 #define LINKTYPE_IBM_SN 146
266 * Reserved for private use. If you have some link-layer header type
267 * that you want to use within your organization, with the capture files
268 * using that link-layer header type not ever be sent outside your
269 * organization, you can use these values.
271 * No libpcap release will use these for any purpose, nor will any
272 * tcpdump release use them, either.
274 * Do *NOT* use these in capture files that you expect anybody not using
275 * your private versions of capture-file-reading tools to read; in
276 * particular, do *NOT* use them in products, otherwise you may find that
277 * people won't be able to use tcpdump, or snort, or Ethereal, or... to
278 * read capture files from your firewall/intrusion detection/traffic
279 * monitoring/etc. appliance, or whatever product uses that LINKTYPE_ value,
280 * and you may also find that the developers of those applications will
281 * not accept patches to let them read those files.
283 * Also, do not use them if somebody might send you a capture using them
284 * for *their* private type and tools using them for *your* private type
285 * would have to read them.
287 * Instead, in those cases, ask "tcpdump-workers@lists.tcpdump.org" for a
288 * new DLT_ and LINKTYPE_ value, as per the comment in pcap/bpf.h, and use
289 * the type you're given.
291 #define LINKTYPE_USER0 147
292 #define LINKTYPE_USER1 148
293 #define LINKTYPE_USER2 149
294 #define LINKTYPE_USER3 150
295 #define LINKTYPE_USER4 151
296 #define LINKTYPE_USER5 152
297 #define LINKTYPE_USER6 153
298 #define LINKTYPE_USER7 154
299 #define LINKTYPE_USER8 155
300 #define LINKTYPE_USER9 156
301 #define LINKTYPE_USER10 157
302 #define LINKTYPE_USER11 158
303 #define LINKTYPE_USER12 159
304 #define LINKTYPE_USER13 160
305 #define LINKTYPE_USER14 161
306 #define LINKTYPE_USER15 162
309 * For future use with 802.11 captures - defined by AbsoluteValue
310 * Systems to store a number of bits of link-layer information
311 * including radio information:
313 * http://www.shaftnet.org/~pizza/software/capturefrm.txt
315 #define LINKTYPE_IEEE802_11_AVS 163 /* 802.11 plus AVS radio metadata header */
318 * Juniper-private data link type, as per request from
319 * Hannes Gredler <hannes@juniper.net>. The corresponding
320 * DLT_s are used for passing on chassis-internal
321 * metainformation such as QOS profiles, etc..
323 #define LINKTYPE_JUNIPER_MONITOR 164
326 * BACnet MS/TP frames.
328 #define LINKTYPE_BACNET_MS_TP 165
331 * Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
333 * This is used in some OSes to allow a kernel socket filter to distinguish
334 * between incoming and outgoing packets, on a socket intended to
335 * supply pppd with outgoing packets so it can do dial-on-demand and
336 * hangup-on-lack-of-demand; incoming packets are filtered out so they
337 * don't cause pppd to hold the connection up (you don't want random
338 * input packets such as port scans, packets from old lost connections,
339 * etc. to force the connection to stay up).
341 * The first byte of the PPP header (0xff03) is modified to accomodate
342 * the direction - 0x00 = IN, 0x01 = OUT.
344 #define LINKTYPE_PPP_PPPD 166
347 * Juniper-private data link type, as per request from
348 * Hannes Gredler <hannes@juniper.net>. The DLT_s are used
349 * for passing on chassis-internal metainformation such as
350 * QOS profiles, cookies, etc..
352 #define LINKTYPE_JUNIPER_PPPOE 167
353 #define LINKTYPE_JUNIPER_PPPOE_ATM 168
355 #define LINKTYPE_GPRS_LLC 169 /* GPRS LLC */
356 #define LINKTYPE_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */
357 #define LINKTYPE_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */
360 * Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
361 * monitoring equipment.
363 #define LINKTYPE_GCOM_T1E1 172
364 #define LINKTYPE_GCOM_SERIAL 173
367 * Juniper-private data link type, as per request from
368 * Hannes Gredler <hannes@juniper.net>. The DLT_ is used
369 * for internal communication to Physical Interface Cards (PIC)
371 #define LINKTYPE_JUNIPER_PIC_PEER 174
374 * Link types requested by Gregor Maier <gregor@endace.com> of Endace
375 * Measurement Systems. They add an ERF header (see
376 * http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
377 * the link-layer header.
379 #define LINKTYPE_ERF_ETH 175 /* Ethernet */
380 #define LINKTYPE_ERF_POS 176 /* Packet-over-SONET */
383 * Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
384 * for vISDN (http://www.orlandi.com/visdn/). Its link-layer header
385 * includes additional information before the LAPD header, so it's
386 * not necessarily a generic LAPD header.
388 #define LINKTYPE_LINUX_LAPD 177
391 * Juniper-private data link type, as per request from
392 * Hannes Gredler <hannes@juniper.net>.
393 * The Link Types are used for prepending meta-information
394 * like interface index, interface name
395 * before standard Ethernet, PPP, Frelay & C-HDLC Frames
397 #define LINKTYPE_JUNIPER_ETHER 178
398 #define LINKTYPE_JUNIPER_PPP 179
399 #define LINKTYPE_JUNIPER_FRELAY 180
400 #define LINKTYPE_JUNIPER_CHDLC 181
403 * Multi Link Frame Relay (FRF.16)
405 #define LINKTYPE_MFR 182
408 * Juniper-private data link type, as per request from
409 * Hannes Gredler <hannes@juniper.net>.
410 * The DLT_ is used for internal communication with a
411 * voice Adapter Card (PIC)
413 #define LINKTYPE_JUNIPER_VP 183
416 * Arinc 429 frames.
417 * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
418 * Every frame contains a 32bit A429 label.
419 * More documentation on Arinc 429 can be found at
420 * http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf
422 #define LINKTYPE_A429 184
425 * Arinc 653 Interpartition Communication messages.
426 * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
427 * Please refer to the A653-1 standard for more information.
429 #define LINKTYPE_A653_ICM 185
432 * This used to be "USB packets, beginning with a USB setup header;
433 * requested by Paolo Abeni <paolo.abeni@email.it>."
435 * However, that header didn't work all that well - it left out some
436 * useful information - and was abandoned in favor of the DLT_USB_LINUX
437 * header.
439 * This is now used by FreeBSD for its BPF taps for USB; that has its
440 * own headers. So it is written, so it is done.
442 #define LINKTYPE_USB_FREEBSD 186
445 * Bluetooth HCI UART transport layer (part H:4); requested by
446 * Paolo Abeni.
448 #define LINKTYPE_BLUETOOTH_HCI_H4 187
451 * IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz
452 * <cruz_petagay@bah.com>.
454 #define LINKTYPE_IEEE802_16_MAC_CPS 188
457 * USB packets, beginning with a Linux USB header; requested by
458 * Paolo Abeni <paolo.abeni@email.it>.
460 #define LINKTYPE_USB_LINUX 189
463 * Controller Area Network (CAN) v. 2.0B packets.
464 * DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
465 * Used to dump CAN packets coming from a CAN Vector board.
466 * More documentation on the CAN v2.0B frames can be found at
467 * http://www.can-cia.org/downloads/?269
469 #define LINKTYPE_CAN20B 190
472 * IEEE 802.15.4, with address fields padded, as is done by Linux
473 * drivers; requested by Juergen Schimmer.
475 #define LINKTYPE_IEEE802_15_4_LINUX 191
478 * Per Packet Information encapsulated packets.
479 * LINKTYPE_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
481 #define LINKTYPE_PPI 192
484 * Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header;
485 * requested by Charles Clancy.
487 #define LINKTYPE_IEEE802_16_MAC_CPS_RADIO 193
490 * Juniper-private data link type, as per request from
491 * Hannes Gredler <hannes@juniper.net>.
492 * The DLT_ is used for internal communication with a
493 * integrated service module (ISM).
495 #define LINKTYPE_JUNIPER_ISM 194
498 * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
499 * nothing); requested by Mikko Saarnivala <mikko.saarnivala@sensinode.com>.
501 #define LINKTYPE_IEEE802_15_4 195
504 * Various link-layer types, with a pseudo-header, for SITA
505 * (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com).
507 #define LINKTYPE_SITA 196
510 * Various link-layer types, with a pseudo-header, for Endace DAG cards;
511 * encapsulates Endace ERF records. Requested by Stephen Donnelly
512 * <stephen@endace.com>.
514 #define LINKTYPE_ERF 197
517 * Special header prepended to Ethernet packets when capturing from a
518 * u10 Networks board. Requested by Phil Mulholland
519 * <phil@u10networks.com>.
521 #define LINKTYPE_RAIF1 198
524 * IPMB packet for IPMI, beginning with the I2C slave address, followed
525 * by the netFn and LUN, etc.. Requested by Chanthy Toeung
526 * <chanthy.toeung@ca.kontron.com>.
528 #define LINKTYPE_IPMB 199
531 * Juniper-private data link type, as per request from
532 * Hannes Gredler <hannes@juniper.net>.
533 * The DLT_ is used for capturing data on a secure tunnel interface.
535 #define LINKTYPE_JUNIPER_ST 200
538 * Bluetooth HCI UART transport layer (part H:4), with pseudo-header
539 * that includes direction information; requested by Paolo Abeni.
541 #define LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR 201
544 * AX.25 packet with a 1-byte KISS header; see
546 * http://www.ax25.net/kiss.htm
548 * as per Richard Stearn <richard@rns-stearn.demon.co.uk>.
550 #define LINKTYPE_AX25_KISS 202
553 * LAPD packets from an ISDN channel, starting with the address field,
554 * with no pseudo-header.
555 * Requested by Varuna De Silva <varunax@gmail.com>.
557 #define LINKTYPE_LAPD 203
560 * Variants of various link-layer headers, with a one-byte direction
561 * pseudo-header prepended - zero means "received by this host",
562 * non-zero (any non-zero value) means "sent by this host" - as per
563 * Will Barker <w.barker@zen.co.uk>.
565 #define LINKTYPE_PPP_WITH_DIR 204 /* PPP */
566 #define LINKTYPE_C_HDLC_WITH_DIR 205 /* Cisco HDLC */
567 #define LINKTYPE_FRELAY_WITH_DIR 206 /* Frame Relay */
568 #define LINKTYPE_LAPB_WITH_DIR 207 /* LAPB */
571 * 208 is reserved for an as-yet-unspecified proprietary link-layer
572 * type, as requested by Will Barker.
576 * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman
577 * <avn@pigeonpoint.com>.
579 #define LINKTYPE_IPMB_LINUX 209
582 * FlexRay automotive bus - http://www.flexray.com/ - as requested
583 * by Hannes Kaelber <hannes.kaelber@x2e.de>.
585 #define LINKTYPE_FLEXRAY 210
588 * Media Oriented Systems Transport (MOST) bus for multimedia
589 * transport - http://www.mostcooperation.com/ - as requested
590 * by Hannes Kaelber <hannes.kaelber@x2e.de>.
592 #define LINKTYPE_MOST 211
595 * Local Interconnect Network (LIN) bus for vehicle networks -
596 * http://www.lin-subbus.org/ - as requested by Hannes Kaelber
597 * <hannes.kaelber@x2e.de>.
599 #define LINKTYPE_LIN 212
602 * X2E-private data link type used for serial line capture,
603 * as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
605 #define LINKTYPE_X2E_SERIAL 213
608 * X2E-private data link type used for the Xoraya data logger
609 * family, as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
611 #define LINKTYPE_X2E_XORAYA 214
614 * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
615 * nothing), but with the PHY-level data for non-ASK PHYs (4 octets
616 * of 0 as preamble, one octet of SFD, one octet of frame length+
617 * reserved bit, and then the MAC-layer data, starting with the
618 * frame control field).
620 * Requested by Max Filippov <jcmvbkbc@gmail.com>.
622 #define LINKTYPE_IEEE802_15_4_NONASK_PHY 215
625 * David Gibson <david@gibson.dropbear.id.au> requested this for
626 * captures from the Linux kernel /dev/input/eventN devices. This
627 * is used to communicate keystrokes and mouse movements from the
628 * Linux kernel to display systems, such as Xorg.
630 #define LINKTYPE_LINUX_EVDEV 216
633 * GSM Um and Abis interfaces, preceded by a "gsmtap" header.
635 * Requested by Harald Welte <laforge@gnumonks.org>.
637 #define LINKTYPE_GSMTAP_UM 217
638 #define LINKTYPE_GSMTAP_ABIS 218
641 * MPLS, with an MPLS label as the link-layer header.
642 * Requested by Michele Marchetto <michele@openbsd.org> on behalf
643 * of OpenBSD.
645 #define LINKTYPE_MPLS 219
648 * USB packets, beginning with a Linux USB header, with the USB header
649 * padded to 64 bytes; required for memory-mapped access.
651 #define LINKTYPE_USB_LINUX_MMAPPED 220
654 * DECT packets, with a pseudo-header; requested by
655 * Matthias Wenzel <tcpdump@mazzoo.de>.
657 #define LINKTYPE_DECT 221
660 * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" <eric.lidwa-1@nasa.gov>
661 * Date: Mon, 11 May 2009 11:18:30 -0500
663 * DLT_AOS. We need it for AOS Space Data Link Protocol.
664 * I have already written dissectors for but need an OK from
665 * legal before I can submit a patch.
668 #define LINKTYPE_AOS 222
671 * Wireless HART (Highway Addressable Remote Transducer)
672 * From the HART Communication Foundation
673 * IES/PAS 62591
675 * Requested by Sam Roberts <vieuxtech@gmail.com>.
677 #define LINKTYPE_WIHART 223
680 * Fibre Channel FC-2 frames, beginning with a Frame_Header.
681 * Requested by Kahou Lei <kahou82@gmail.com>.
683 #define LINKTYPE_FC_2 224
686 * Fibre Channel FC-2 frames, beginning with an encoding of the
687 * SOF, and ending with an encoding of the EOF.
689 * The encodings represent the frame delimiters as 4-byte sequences
690 * representing the corresponding ordered sets, with K28.5
691 * represented as 0xBC, and the D symbols as the corresponding
692 * byte values; for example, SOFi2, which is K28.5 - D21.5 - D1.2 - D21.2,
693 * is represented as 0xBC 0xB5 0x55 0x55.
695 * Requested by Kahou Lei <kahou82@gmail.com>.
697 #define LINKTYPE_FC_2_WITH_FRAME_DELIMS 225
700 * Solaris ipnet pseudo-header; requested by Darren Reed <Darren.Reed@Sun.COM>.
702 * The pseudo-header starts with a one-byte version number; for version 2,
703 * the pseudo-header is:
705 * struct dl_ipnetinfo {
706 * u_int8_t dli_version;
707 * u_int8_t dli_family;
708 * u_int16_t dli_htype;
709 * u_int32_t dli_pktlen;
710 * u_int32_t dli_ifindex;
711 * u_int32_t dli_grifindex;
712 * u_int32_t dli_zsrc;
713 * u_int32_t dli_zdst;
714 * };
716 * dli_version is 2 for the current version of the pseudo-header.
718 * dli_family is a Solaris address family value, so it's 2 for IPv4
719 * and 26 for IPv6.
721 * dli_htype is a "hook type" - 0 for incoming packets, 1 for outgoing
722 * packets, and 2 for packets arriving from another zone on the same
723 * machine.
725 * dli_pktlen is the length of the packet data following the pseudo-header
726 * (so the captured length minus dli_pktlen is the length of the
727 * pseudo-header, assuming the entire pseudo-header was captured).
729 * dli_ifindex is the interface index of the interface on which the
730 * packet arrived.
732 * dli_grifindex is the group interface index number (for IPMP interfaces).
734 * dli_zsrc is the zone identifier for the source of the packet.
736 * dli_zdst is the zone identifier for the destination of the packet.
738 * A zone number of 0 is the global zone; a zone number of 0xffffffff
739 * means that the packet arrived from another host on the network, not
740 * from another zone on the same machine.
742 * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates
743 * which of those it is.
745 #define LINKTYPE_IPNET 226
748 * CAN (Controller Area Network) frames, with a pseudo-header as supplied
749 * by Linux SocketCAN, and with multi-byte numerical fields in that header
750 * in big-endian byte order.
752 * See Documentation/networking/can.txt in the Linux source.
754 * Requested by Felix Obenhuber <felix@obenhuber.de>.
756 #define LINKTYPE_CAN_SOCKETCAN 227
759 * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies
760 * whether it's v4 or v6. Requested by Darren Reed <Darren.Reed@Sun.COM>.
762 #define LINKTYPE_IPV4 228
763 #define LINKTYPE_IPV6 229
766 * IEEE 802.15.4, exactly as it appears in the spec (no padding, no
767 * nothing), and with no FCS at the end of the frame; requested by
768 * Jon Smirl <jonsmirl@gmail.com>.
770 #define LINKTYPE_IEEE802_15_4_NOFCS 230
773 * Raw D-Bus:
775 * http://www.freedesktop.org/wiki/Software/dbus
777 * messages:
779 * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages
781 * starting with the endianness flag, followed by the message type, etc.,
782 * but without the authentication handshake before the message sequence:
784 * http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
786 * Requested by Martin Vidner <martin@vidner.net>.
788 #define LINKTYPE_DBUS 231
791 * Juniper-private data link type, as per request from
792 * Hannes Gredler <hannes@juniper.net>.
794 #define LINKTYPE_JUNIPER_VS 232
795 #define LINKTYPE_JUNIPER_SRX_E2E 233
796 #define LINKTYPE_JUNIPER_FIBRECHANNEL 234
799 * DVB-CI (DVB Common Interface for communication between a PC Card
800 * module and a DVB receiver). See
802 * http://www.kaiser.cx/pcap-dvbci.html
804 * for the specification.
806 * Requested by Martin Kaiser <martin@kaiser.cx>.
808 #define LINKTYPE_DVB_CI 235
811 * Variant of 3GPP TS 27.010 multiplexing protocol. Requested
812 * by Hans-Christoph Schemmel <hans-christoph.schemmel@cinterion.com>.
814 #define LINKTYPE_MUX27010 236
817 * STANAG 5066 D_PDUs. Requested by M. Baris Demiray
818 * <barisdemiray@gmail.com>.
820 #define LINKTYPE_STANAG_5066_D_PDU 237
823 * Juniper-private data link type, as per request from
824 * Hannes Gredler <hannes@juniper.net>.
826 #define LINKTYPE_JUNIPER_ATM_CEMIC 238
829 * NetFilter LOG messages
830 * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets)
832 * Requested by Jakub Zawadzki <darkjames-ws@darkjames.pl>
834 #define LINKTYPE_NFLOG 239
837 * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type
838 * for Ethernet packets with a 4-byte pseudo-header and always
839 * with the payload including the FCS, as supplied by their
840 * netANALYZER hardware and software.
842 * Requested by Holger P. Frommer <HPfrommer@hilscher.com>
844 #define LINKTYPE_NETANALYZER 240
847 * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type
848 * for Ethernet packets with a 4-byte pseudo-header and FCS and
849 * 1 byte of SFD, as supplied by their netANALYZER hardware and
850 * software.
852 * Requested by Holger P. Frommer <HPfrommer@hilscher.com>
854 #define LINKTYPE_NETANALYZER_TRANSPARENT 241
857 * IP-over-InfiniBand, as specified by RFC 4391.
859 * Requested by Petr Sumbera <petr.sumbera@oracle.com>.
861 #define LINKTYPE_IPOIB 242
864 * MPEG-2 transport stream (ISO 13818-1/ITU-T H.222.0).
866 * Requested by Guy Martin <gmsoft@tuxicoman.be>.
868 #define LINKTYPE_MPEG_2_TS 243
871 * ng4T GmbH's UMTS Iub/Iur-over-ATM and Iub/Iur-over-IP format as
872 * used by their ng40 protocol tester.
874 * Requested by Jens Grimmer <jens.grimmer@ng4t.com>.
876 #define LINKTYPE_NG40 244
879 * Pseudo-header giving adapter number and flags, followed by an NFC
880 * (Near-Field Communications) Logical Link Control Protocol (LLCP) PDU,
881 * as specified by NFC Forum Logical Link Control Protocol Technical
882 * Specification LLCP 1.1.
884 * Requested by Mike Wakerly <mikey@google.com>.
886 #define LINKTYPE_NFC_LLCP 245
889 * pfsync output; DLT_PFSYNC is 18, which collides with DLT_CIP in
890 * SuSE 6.3, on OpenBSD, NetBSD, DragonFly BSD, and Mac OS X, and
891 * is 121, which collides with DLT_HHDLC, in FreeBSD. We pick a
892 * shiny new link-layer header type value that doesn't collide with
893 * anything, in the hopes that future pfsync savefiles, if any,
894 * won't require special hacks to distinguish from other savefiles.
897 #define LINKTYPE_PFSYNC 246
900 * Raw InfiniBand packets, starting with the Local Routing Header.
902 * Requested by Oren Kladnitsky <orenk@mellanox.com>.
904 #define LINKTYPE_INFINIBAND 247
907 * SCTP, with no lower-level protocols (i.e., no IPv4 or IPv6).
909 * Requested by Michael Tuexen <Michael.Tuexen@lurchi.franken.de>.
911 #define LINKTYPE_SCTP 248
914 * USB packets, beginning with a USBPcap header.
916 * Requested by Tomasz Mon <desowin@gmail.com>
918 #define LINKTYPE_USBPCAP 249
921 * Schweitzer Engineering Laboratories "RTAC" product serial-line
922 * packets.
924 * Requested by Chris Bontje <chris_bontje@selinc.com>.
926 #define DLT_RTAC_SERIAL 250
929 * Bluetooth Low Energy air interface link-layer packets.
931 * Requested by Mike Kershaw <dragorn@kismetwireless.net>.
933 #define LINKTYPE_BLUETOOTH_LE_LL 251
936 * Link-layer header type for upper-protocol layer PDU saves from wireshark.
938 * the actual contents are determined by two TAGs stored with each
939 * packet:
940 * EXP_PDU_TAG_LINKTYPE the link type (LINKTYPE_ value) of the
941 * original packet.
943 * EXP_PDU_TAG_PROTO_NAME the name of the wireshark dissector
944 * that can make sense of the data stored.
946 #define LINKTYPE_WIRESHARK_UPPER_PDU 252
949 * Link-layer header type for the netlink protocol (nlmon devices).
951 #define LINKTYPE_NETLINK 253
954 * Bluetooth Linux Monitor headers for the BlueZ stack.
956 #define LINKTYPE_BLUETOOTH_LINUX_MONITOR 254
959 * Bluetooth Basic Rate/Enhanced Data Rate baseband packets, as
960 * captured by Ubertooth.
962 #define LINKTYPE_BLUETOOTH_BREDR_BB 255
965 * Bluetooth Low Energy link layer packets, as captured by Ubertooth.
967 #define LINKTYPE_BLUETOOTH_LE_LL_WITH_PHDR 256
970 * PROFIBUS data link layer.
972 #define LINKTYPE_PROFIBUS_DL 257
975 * Apple's DLT_PKTAP headers.
977 * Sadly, the folks at Apple either had no clue that the DLT_USERn values
978 * are for internal use within an organization and partners only, and
979 * didn't know that the right way to get a link-layer header type is to
980 * ask tcpdump.org for one, or knew and didn't care, so they just
981 * used DLT_USER2, which causes problems for everything except for
982 * their version of tcpdump.
984 * So I'll just give them one; hopefully this will show up in a
985 * libpcap release in time for them to get this into 10.10 Big Sur
986 * or whatever Mavericks' successor is called. LINKTYPE_PKTAP
987 * will be 258 *even on OS X*; that is *intentional*, so that
988 * PKTAP files look the same on *all* OSes (different OSes can have
989 * different numerical values for a given DLT_, but *MUST NOT* have
990 * different values for what goes in a file, as files can be moved
991 * between OSes!).
993 #define LINKTYPE_PKTAP 258
996 * Ethernet packets preceded by a header giving the last 6 octets
997 * of the preamble specified by 802.3-2012 Clause 65, section
998 * 65.1.3.2 "Transmit".
1000 #define LINKTYPE_EPON 259
1003 * IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format"
1004 * in the PICMG HPM.2 specification.
1006 #define LINKTYPE_IPMI_HPM_2 260
1009 * per Joshua Wright <jwright@hasborg.com>, formats for Zwave captures.
1011 #define LINKTYPE_ZWAVE_R1_R2 261
1012 #define LINKTYPE_ZWAVE_R3 262
1015 * per Steve Karg <skarg@users.sourceforge.net>, formats for Wattstopper
1016 * Digital Lighting Management room bus serial protocol captures.
1018 #define LINKTYPE_WATTSTOPPER_DLM 263
1021 * ISO 14443 contactless smart card messages.
1023 #define LINKTYPE_ISO_14443 264
1026 * Radio data system (RDS) groups. IEC 62106.
1027 * Per Jonathan Brucker <jonathan.brucke@gmail.com>.
1029 #define LINKTYPE_RDS 265
1031 #define LINKTYPE_MATCHING_MAX 265 /* highest value in the "matching" range */
1033 static struct linktype_map {
1034 int dlt;
1035 int linktype;
1036 } map[] = {
1038 * These DLT_* codes have LINKTYPE_* codes with values identical
1039 * to the values of the corresponding DLT_* code.
1041 { DLT_NULL, LINKTYPE_NULL },
1042 { DLT_EN10MB, LINKTYPE_ETHERNET },
1043 { DLT_EN3MB, LINKTYPE_EXP_ETHERNET },
1044 { DLT_AX25, LINKTYPE_AX25 },
1045 { DLT_PRONET, LINKTYPE_PRONET },
1046 { DLT_CHAOS, LINKTYPE_CHAOS },
1047 { DLT_IEEE802, LINKTYPE_IEEE802_5 },
1048 { DLT_ARCNET, LINKTYPE_ARCNET_BSD },
1049 { DLT_SLIP, LINKTYPE_SLIP },
1050 { DLT_PPP, LINKTYPE_PPP },
1051 { DLT_FDDI, LINKTYPE_FDDI },
1052 { DLT_SYMANTEC_FIREWALL, LINKTYPE_SYMANTEC_FIREWALL },
1055 * These DLT_* codes have different values on different
1056 * platforms; we map them to LINKTYPE_* codes that
1057 * have values that should never be equal to any DLT_*
1058 * code.
1060 #ifdef DLT_FR
1061 /* BSD/OS Frame Relay */
1062 { DLT_FR, LINKTYPE_FRELAY },
1063 #endif
1065 { DLT_ATM_RFC1483, LINKTYPE_ATM_RFC1483 },
1066 { DLT_RAW, LINKTYPE_RAW },
1067 { DLT_SLIP_BSDOS, LINKTYPE_SLIP_BSDOS },
1068 { DLT_PPP_BSDOS, LINKTYPE_PPP_BSDOS },
1070 /* BSD/OS Cisco HDLC */
1071 { DLT_C_HDLC, LINKTYPE_C_HDLC },
1074 * These DLT_* codes are not on all platforms, but, so far,
1075 * there don't appear to be any platforms that define
1076 * other codes with those values; we map them to
1077 * different LINKTYPE_* values anyway, just in case.
1080 /* Linux ATM Classical IP */
1081 { DLT_ATM_CLIP, LINKTYPE_ATM_CLIP },
1083 /* NetBSD sync/async serial PPP (or Cisco HDLC) */
1084 { DLT_PPP_SERIAL, LINKTYPE_PPP_HDLC },
1086 /* NetBSD PPP over Ethernet */
1087 { DLT_PPP_ETHER, LINKTYPE_PPP_ETHER },
1090 * All LINKTYPE_ values between LINKTYPE_MATCHING_MIN
1091 * and LINKTYPE_MATCHING_MAX are mapped to identical
1092 * DLT_ values.
1095 { -1, -1 }
1099 dlt_to_linktype(int dlt)
1101 int i;
1104 * DLTs that, on some platforms, have values in the matching range
1105 * but that *don't* have the same value as the corresponding
1106 * LINKTYPE because, for some reason, not all OSes have the
1107 * same value for that DLT (note that the DLT's value might be
1108 * outside the matching range on some of those OSes).
1110 if (dlt == DLT_PFSYNC)
1111 return (LINKTYPE_PFSYNC);
1112 if (dlt == DLT_PKTAP)
1113 return (LINKTYPE_PKTAP);
1116 * For all other values in the matching range, the DLT
1117 * value is the same as the LINKTYPE value.
1119 if (dlt >= DLT_MATCHING_MIN && dlt <= DLT_MATCHING_MAX)
1120 return (dlt);
1123 * Map the values outside that range.
1125 for (i = 0; map[i].dlt != -1; i++) {
1126 if (map[i].dlt == dlt)
1127 return (map[i].linktype);
1131 * If we don't have a mapping for this DLT, return an
1132 * error; that means that this is a value with no corresponding
1133 * LINKTYPE, and we need to assign one.
1135 return (-1);
1139 linktype_to_dlt(int linktype)
1141 int i;
1144 * LINKTYPEs in the matching range that *don't*
1145 * have the same value as the corresponding DLTs
1146 * because, for some reason, not all OSes have the
1147 * same value for that DLT.
1149 if (linktype == LINKTYPE_PFSYNC)
1150 return (DLT_PFSYNC);
1151 if (linktype == LINKTYPE_PKTAP)
1152 return (DLT_PKTAP);
1155 * For all other values in the matching range, the LINKTYPE
1156 * value is the same as the DLT value.
1158 if (linktype >= LINKTYPE_MATCHING_MIN &&
1159 linktype <= LINKTYPE_MATCHING_MAX)
1160 return (linktype);
1163 * Map the values outside that range.
1165 for (i = 0; map[i].linktype != -1; i++) {
1166 if (map[i].linktype == linktype)
1167 return (map[i].dlt);
1171 * If we don't have an entry for this LINKTYPE, return
1172 * the link type value; it may be a DLT from an older
1173 * version of libpcap.
1175 return linktype;
1178 #define EXTRACT_
1181 * DLT_LINUX_SLL packets with a protocol type of LINUX_SLL_P_CAN or
1182 * LINUX_SLL_P_CANFD have SocketCAN headers in front of the payload,
1183 * with the CAN ID being in host byte order.
1185 * When reading a DLT_LINUX_SLL capture file, we need to check for those
1186 * packets and convert the CAN ID from the byte order of the host that
1187 * wrote the file to this host's byte order.
1189 static void
1190 swap_linux_sll_header(const struct pcap_pkthdr *hdr, u_char *buf)
1192 u_int caplen = hdr->caplen;
1193 u_int length = hdr->len;
1194 struct sll_header *shdr = (struct sll_header *)buf;
1195 u_int16_t protocol;
1196 pcap_can_socketcan_hdr *chdr;
1198 if (caplen < (u_int) sizeof(struct sll_header) ||
1199 length < (u_int) sizeof(struct sll_header)) {
1200 /* Not enough data to have the protocol field */
1201 return;
1204 protocol = EXTRACT_16BITS(&shdr->sll_protocol);
1205 if (protocol != LINUX_SLL_P_CAN && protocol != LINUX_SLL_P_CANFD)
1206 return;
1209 * SocketCAN packet; fix up the packet's header.
1211 chdr = (pcap_can_socketcan_hdr *)(buf + sizeof(struct sll_header));
1212 if (caplen < (u_int) sizeof(struct sll_header) + sizeof(chdr->can_id) ||
1213 length < (u_int) sizeof(struct sll_header) + sizeof(chdr->can_id)) {
1214 /* Not enough data to have the CAN ID */
1215 return;
1217 chdr->can_id = SWAPLONG(chdr->can_id);
1221 * The DLT_USB_LINUX and DLT_USB_LINUX_MMAPPED headers are in host
1222 * byte order when capturing (it's supplied directly from a
1223 * memory-mapped buffer shared by the kernel).
1225 * When reading a DLT_USB_LINUX or DLT_USB_LINUX_MMAPPED capture file,
1226 * we need to convert it from the byte order of the host that wrote
1227 * the file to this host's byte order.
1229 static void
1230 swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
1231 int header_len_64_bytes)
1233 pcap_usb_header_mmapped *uhdr = (pcap_usb_header_mmapped *)buf;
1234 bpf_u_int32 offset = 0;
1237 * "offset" is the offset *past* the field we're swapping;
1238 * we skip the field *before* checking to make sure
1239 * the captured data length includes the entire field.
1243 * The URB id is a totally opaque value; do we really need to
1244 * convert it to the reading host's byte order???
1246 offset += 8; /* skip past id */
1247 if (hdr->caplen < offset)
1248 return;
1249 uhdr->id = SWAPLL(uhdr->id);
1251 offset += 4; /* skip past various 1-byte fields */
1253 offset += 2; /* skip past bus_id */
1254 if (hdr->caplen < offset)
1255 return;
1256 uhdr->bus_id = SWAPSHORT(uhdr->bus_id);
1258 offset += 2; /* skip past various 1-byte fields */
1260 offset += 8; /* skip past ts_sec */
1261 if (hdr->caplen < offset)
1262 return;
1263 uhdr->ts_sec = SWAPLL(uhdr->ts_sec);
1265 offset += 4; /* skip past ts_usec */
1266 if (hdr->caplen < offset)
1267 return;
1268 uhdr->ts_usec = SWAPLONG(uhdr->ts_usec);
1270 offset += 4; /* skip past status */
1271 if (hdr->caplen < offset)
1272 return;
1273 uhdr->status = SWAPLONG(uhdr->status);
1275 offset += 4; /* skip past urb_len */
1276 if (hdr->caplen < offset)
1277 return;
1278 uhdr->urb_len = SWAPLONG(uhdr->urb_len);
1280 offset += 4; /* skip past data_len */
1281 if (hdr->caplen < offset)
1282 return;
1283 uhdr->data_len = SWAPLONG(uhdr->data_len);
1285 if (uhdr->transfer_type == URB_ISOCHRONOUS) {
1286 offset += 4; /* skip past s.iso.error_count */
1287 if (hdr->caplen < offset)
1288 return;
1289 uhdr->s.iso.error_count = SWAPLONG(uhdr->s.iso.error_count);
1291 offset += 4; /* skip past s.iso.numdesc */
1292 if (hdr->caplen < offset)
1293 return;
1294 uhdr->s.iso.numdesc = SWAPLONG(uhdr->s.iso.numdesc);
1295 } else
1296 offset += 8; /* skip USB setup header */
1299 * With the old header, there are no isochronous descriptors
1300 * after the header.
1302 * With the new header, the actual number of descriptors in
1303 * the header is not s.iso.numdesc, it's ndesc - only the
1304 * first N descriptors, for some value of N, are put into
1305 * the header, and ndesc is set to the actual number copied.
1306 * In addition, if s.iso.numdesc is negative, no descriptors
1307 * are captured, and ndesc is set to 0.
1309 if (header_len_64_bytes) {
1311 * This is either the "version 1" header, with
1312 * 16 bytes of additional fields at the end, or
1313 * a "version 0" header from a memory-mapped
1314 * capture, with 16 bytes of zeroed-out padding
1315 * at the end. Byte swap them as if this were
1316 * a "version 1" header.
1318 offset += 4; /* skip past interval */
1319 if (hdr->caplen < offset)
1320 return;
1321 uhdr->interval = SWAPLONG(uhdr->interval);
1323 offset += 4; /* skip past start_frame */
1324 if (hdr->caplen < offset)
1325 return;
1326 uhdr->start_frame = SWAPLONG(uhdr->start_frame);
1328 offset += 4; /* skip past xfer_flags */
1329 if (hdr->caplen < offset)
1330 return;
1331 uhdr->xfer_flags = SWAPLONG(uhdr->xfer_flags);
1333 offset += 4; /* skip past ndesc */
1334 if (hdr->caplen < offset)
1335 return;
1336 uhdr->ndesc = SWAPLONG(uhdr->ndesc);
1338 if (uhdr->transfer_type == URB_ISOCHRONOUS) {
1339 /* swap the values in struct linux_usb_isodesc */
1340 usb_isodesc *pisodesc;
1341 u_int32_t i;
1343 pisodesc = (usb_isodesc *)(void *)(buf+offset);
1344 for (i = 0; i < uhdr->ndesc; i++) {
1345 offset += 4; /* skip past status */
1346 if (hdr->caplen < offset)
1347 return;
1348 pisodesc->status = SWAPLONG(pisodesc->status);
1350 offset += 4; /* skip past offset */
1351 if (hdr->caplen < offset)
1352 return;
1353 pisodesc->offset = SWAPLONG(pisodesc->offset);
1355 offset += 4; /* skip past len */
1356 if (hdr->caplen < offset)
1357 return;
1358 pisodesc->len = SWAPLONG(pisodesc->len);
1360 offset += 4; /* skip past padding */
1362 pisodesc++;
1369 * The DLT_NFLOG "packets" have a mixture of big-endian and host-byte-order
1370 * data. They begin with a fixed-length header with big-endian fields,
1371 * followed by a set of TLVs, where the type and length are in host
1372 * byte order but the values are either big-endian or are a raw byte
1373 * sequence that's the same regardless of the host's byte order.
1375 * When reading a DLT_NFLOG capture file, we need to convert the type
1376 * and length values from the byte order of the host that wrote the
1377 * file to the byte order of this host.
1379 static void
1380 swap_nflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
1382 u_char *p = buf;
1383 nflog_hdr_t *nfhdr = (nflog_hdr_t *)buf;
1384 nflog_tlv_t *tlv;
1385 u_int caplen = hdr->caplen;
1386 u_int length = hdr->len;
1387 u_int16_t size;
1389 if (caplen < (u_int) sizeof(nflog_hdr_t) ||
1390 length < (u_int) sizeof(nflog_hdr_t)) {
1391 /* Not enough data to have any TLVs. */
1392 return;
1395 if (nfhdr->nflog_version != 0) {
1396 /* Unknown NFLOG version */
1397 return;
1400 length -= sizeof(nflog_hdr_t);
1401 caplen -= sizeof(nflog_hdr_t);
1402 p += sizeof(nflog_hdr_t);
1404 while (caplen >= sizeof(nflog_tlv_t)) {
1405 tlv = (nflog_tlv_t *) p;
1407 /* Swap the type and length. */
1408 tlv->tlv_type = SWAPSHORT(tlv->tlv_type);
1409 tlv->tlv_length = SWAPSHORT(tlv->tlv_length);
1411 /* Get the length of the TLV. */
1412 size = tlv->tlv_length;
1413 if (size % 4 != 0)
1414 size += 4 - size % 4;
1416 /* Is the TLV's length less than the minimum? */
1417 if (size < sizeof(nflog_tlv_t)) {
1418 /* Yes. Give up now. */
1419 return;
1422 /* Do we have enough data for the full TLV? */
1423 if (caplen < size || length < size) {
1424 /* No. */
1425 return;
1428 /* Skip over the TLV. */
1429 length -= size;
1430 caplen -= size;
1431 p += size;
1435 void
1436 swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data)
1439 * Convert pseudo-headers from the byte order of
1440 * the host on which the file was saved to our
1441 * byte order, as necessary.
1443 switch (linktype) {
1445 case DLT_LINUX_SLL:
1446 swap_linux_sll_header(hdr, data);
1447 break;
1449 case DLT_USB_LINUX:
1450 swap_linux_usb_header(hdr, data, 0);
1451 break;
1453 case DLT_USB_LINUX_MMAPPED:
1454 swap_linux_usb_header(hdr, data, 1);
1455 break;
1457 case DLT_NFLOG:
1458 swap_nflog_header(hdr, data);
1459 break;