2 * Code common to libpcap and pcap-NG file formats
5 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
7 * File format support for pcap-ng file format
8 * Copyright (c) 2007 by Ulf Lamping <ulf.lamping@web.de>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include "file_wrappers.h"
34 #include "pcap-encap.h"
35 #include "pcap-common.h"
38 * Map link-layer header types (LINKTYPE_ values) to Wiretap encapsulations.
40 * Either LBL NRG wasn't an adequate central registry (e.g., because of
41 * the slow rate of releases from them), or nobody bothered using them
42 * as a central registry, as many different groups have patched libpcap
43 * (and BPF, on the BSDs) to add new encapsulation types, and have ended
44 * up using the same DLT_ values for different encapsulation types.
46 * The Tcpdump Group now maintains the list of link-layer header types;
47 * they introduced a separate namespace of LINKTYPE_ values for the
48 * values to be used in capture files, and have libpcap map between
49 * those values in capture file headers and the DLT_ values that the
50 * pcap_datalink() and pcap_open_dead() APIs use. See
51 * http://www.tcpdump.org/linktypes.html for a list of LINKTYPE_ values.
53 * In most cases, the corresponding LINKTYPE_ and DLT_ values are the
54 * same. In the cases where the same link-layer header type was given
55 * different values in different OSes, a new LINKTYPE_ value was defined,
56 * different from all of the existing DLT_ values.
58 * This table maps LINKTYPE_ values to the corresponding Wiretap
59 * encapsulation. For cases where multiple DLT_ values were in use,
60 * it also checks what <pcap.h> defineds to determine how to interpret
61 * them, so that if a file was written by a version of libpcap prior
62 * to the introduction of the LINKTYPE_ values, and has a DLT_ value
63 * from the OS on which it was written rather than a LINKTYPE_ value
64 * as its linktype value in the file header, we map the numerical
65 * DLT_ value, as interpreted by the libpcap with which we're building
66 * Wireshark/Wiretap interprets them (which, if it doesn't support
67 * them at all, means we don't support them either - any capture files
68 * using them are foreign, and we don't hazard a guess as to which
69 * platform they came from; we could, I guess, choose the most likely
70 * platform), to the corresponding Wiretap encapsulation.
72 * Note: if you need a new encapsulation type for libpcap files, do
73 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
74 * add a new encapsulation type by changing an existing entry;
75 * leave the existing entries alone.
77 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking for
78 * a new LINKTYPE_/DLT_ value, and specifying the purpose of the new
79 * value. When you get the new LINKTYPE_/DLT_ value, use that numerical
80 * value in the "linktype_value" field of "pcap_to_wtap_map[]".
86 } pcap_to_wtap_map[] = {
88 * These are the values that are almost certainly the same
89 * in all libpcaps (I've yet to find one where the values
90 * in question are used for some purpose other than the
91 * one below, but...), and thus assigned as LINKTYPE_ values,
92 * and that Wiretap and Wireshark currently support.
94 { 0, WTAP_ENCAP_NULL }, /* null encapsulation */
95 { 1, WTAP_ENCAP_ETHERNET },
96 { 3, WTAP_ENCAP_AX25 },
97 { 6, WTAP_ENCAP_TOKEN_RING }, /* IEEE 802 Networks - assume token ring */
98 { 7, WTAP_ENCAP_ARCNET },
99 { 8, WTAP_ENCAP_SLIP },
100 { 9, WTAP_ENCAP_PPP },
101 #ifdef BIT_SWAPPED_MAC_ADDRS
102 { 10, WTAP_ENCAP_FDDI_BITSWAPPED },
104 { 10, WTAP_ENCAP_FDDI },
107 { 32, WTAP_ENCAP_REDBACK },
110 * 50 is DLT_PPP_SERIAL in NetBSD; it appears that DLT_PPP
111 * on BSD (at least according to standard tcpdump) has, as
112 * the first octet, an indication of whether the packet was
113 * transmitted or received (rather than having the standard
114 * PPP address value of 0xff), but that DLT_PPP_SERIAL puts
115 * a real live PPP header there, or perhaps a Cisco PPP header
116 * as per section 4.3.1 of RFC 1547 (implementations of this
117 * exist in various BSDs in "sys/net/if_spppsubr.c", and
118 * I think also exist either in standard Linux or in
119 * various Linux patches; the implementations show how to handle
120 * Cisco keepalive packets).
122 * However, I don't see any obvious place in FreeBSD "if_ppp.c"
123 * where anything other than the standard PPP header would be
124 * passed up. I see some stuff that sets the first octet
125 * to 0 for incoming and 1 for outgoing packets before applying
126 * a BPF filter to see whether to drop packets whose protocol
127 * field has the 0x8000 bit set, i.e. network control protocols -
128 * those are handed up to userland - but that code puts the
129 * address field back before passing the packet up.
131 * I also don't see anything immediately obvious that munges
132 * the address field for sync PPP, either.
134 * Wireshark currently assumes that if the first octet of a
135 * PPP frame is 0xFF, it's the address field and is followed
136 * by a control field and a 2-byte protocol, otherwise the
137 * address and control fields are absent and the frame begins
138 * with a protocol field. If we ever see a BSD/OS PPP
139 * capture, we'll have to handle it differently, and we may
140 * have to handle standard BSD captures differently if, in fact,
141 * they don't have 0xff 0x03 as the first two bytes - but, as per
142 * the two paragraphs preceding this, it's not clear that
143 * the address field *is* munged into an incoming/outgoing
144 * field when the packet is handed to the BPF device.
146 * For now, we just map DLT_PPP_SERIAL to WTAP_ENCAP_PPP, as
147 * we treat WTAP_ENCAP_PPP packets as if those beginning with
148 * 0xff have the standard RFC 1662 "PPP in HDLC-like Framing"
149 * 0xff 0x03 address/control header, and DLT_PPP_SERIAL frames
150 * appear to contain that unless they're Cisco frames (if we
151 * ever see a capture with them, we'd need to implement the
152 * RFC 1547 stuff, and the keepalive protocol stuff).
154 * We may have to distinguish between "PPP where if it doesn't
155 * begin with 0xff there's no HDLC encapsulation and the frame
156 * begins with the protocol field" (which is how we handle
157 * WTAP_ENCAP_PPP now) and "PPP where there's either HDLC
158 * encapsulation or Cisco PPP" (which is what DLT_PPP_SERIAL
161 * XXX - NetBSD has DLT_HDLC, which appears to be used for
162 * Cisco HDLC. Ideally, they should use DLT_PPP_SERIAL
163 * only for real live HDLC-encapsulated PPP, not for Cisco
166 { 50, WTAP_ENCAP_PPP },
169 * Used by NetBSD and OpenBSD pppoe(4).
171 { 51, WTAP_ENCAP_PPP_ETHER },
174 * Apparently used by the Axent Raptor firewall (now Symantec
175 * Enterprise Firewall).
176 * Thanks, Axent, for not reserving that type with tcpdump.org
177 * and not telling anybody about it.
179 { 99, WTAP_ENCAP_SYMANTEC },
182 * These are the values that libpcap 0.5 and later use in
183 * capture file headers, in an attempt to work around the
184 * confusion decried above, and that Wiretap and Wireshark
185 * currently support. I.e., they're the LINKTYPE_ values
186 * for RFC 1483 ATM and "raw IP", respectively, not the
187 * DLT_ values for them on all platforms.
189 { 100, WTAP_ENCAP_ATM_RFC1483 },
190 { 101, WTAP_ENCAP_RAW_IP },
193 * More values used by libpcap 0.5 as DLT_ values and used by the
194 * current CVS version of libpcap in capture file headers.
195 * They are not yet handled in Wireshark.
196 * If we get a capture that contains them, we'll implement them.
198 { 102, WTAP_ENCAP_SLIP_BSDOS },
199 { 103, WTAP_ENCAP_PPP_BSDOS },
203 * These ones are handled in Wireshark, though.
205 { 104, WTAP_ENCAP_CHDLC }, /* Cisco HDLC */
206 { 105, WTAP_ENCAP_IEEE_802_11 }, /* IEEE 802.11 */
207 { 106, WTAP_ENCAP_LINUX_ATM_CLIP },
208 { 107, WTAP_ENCAP_FRELAY }, /* Frame Relay */
209 { 108, WTAP_ENCAP_NULL }, /* OpenBSD loopback */
210 { 109, WTAP_ENCAP_ENC }, /* OpenBSD IPSEC enc */
212 { 110, WTAP_ENCAP_LANE_802_3 },/* ATM LANE 802.3 */
213 { 111, WTAP_ENCAP_HIPPI }, /* NetBSD HIPPI */
215 { 112, WTAP_ENCAP_CHDLC }, /* NetBSD HDLC framing */
218 * Linux "cooked mode" captures, used by the current CVS version
221 * it could be a packet in Cisco's ERSPAN encapsulation which uses
222 * this number as well (why can't people stick to protocols when it
223 * comes to allocating/using DLT types).
225 { 113, WTAP_ENCAP_SLL }, /* Linux cooked capture */
227 { 114, WTAP_ENCAP_LOCALTALK }, /* Localtalk */
230 * The tcpdump.org version of libpcap uses 117, rather than 17,
231 * for OpenBSD packet filter logging, so as to avoid conflicting
232 * with DLT_LANE8023 in SuSE 6.3 libpcap.
234 { 117, WTAP_ENCAP_PFLOG },
236 { 118, WTAP_ENCAP_CISCO_IOS },
237 { 119, WTAP_ENCAP_IEEE_802_11_PRISM }, /* 802.11 plus Prism monitor mode radio header */
238 { 121, WTAP_ENCAP_HHDLC }, /* HiPath HDLC */
239 { 122, WTAP_ENCAP_IP_OVER_FC }, /* RFC 2625 IP-over-FC */
240 { 123, WTAP_ENCAP_ATM_PDUS }, /* SunATM */
241 { 127, WTAP_ENCAP_IEEE_802_11_RADIOTAP }, /* 802.11 plus radiotap radio header */
242 { 128, WTAP_ENCAP_TZSP }, /* Tazmen Sniffer Protocol */
243 { 129, WTAP_ENCAP_ARCNET_LINUX },
244 { 130, WTAP_ENCAP_JUNIPER_MLPPP }, /* Juniper MLPPP on ML-, LS-, AS- PICs */
245 { 131, WTAP_ENCAP_JUNIPER_MLFR }, /* Juniper MLFR (FRF.15) on ML-, LS-, AS- PICs */
246 { 133, WTAP_ENCAP_JUNIPER_GGSN},
248 * Values 132 and 134 not listed here are reserved for use
249 * in Juniper hardware.
251 { 135, WTAP_ENCAP_JUNIPER_ATM2 }, /* various encapsulations captured on the ATM2 PIC */
252 { 136, WTAP_ENCAP_JUNIPER_SVCS }, /* various encapsulations captured on the services PIC */
253 { 137, WTAP_ENCAP_JUNIPER_ATM1 }, /* various encapsulations captured on the ATM1 PIC */
255 { 138, WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 },
256 /* Apple IP-over-IEEE 1394 */
258 { 139, WTAP_ENCAP_MTP2_WITH_PHDR },
259 { 140, WTAP_ENCAP_MTP2 },
260 { 141, WTAP_ENCAP_MTP3 },
261 { 142, WTAP_ENCAP_SCCP },
262 { 143, WTAP_ENCAP_DOCSIS },
263 { 144, WTAP_ENCAP_IRDA }, /* IrDA capture */
265 /* Reserved for private use. */
266 { 147, WTAP_ENCAP_USER0 },
267 { 148, WTAP_ENCAP_USER1 },
268 { 149, WTAP_ENCAP_USER2 },
269 { 150, WTAP_ENCAP_USER3 },
270 { 151, WTAP_ENCAP_USER4 },
271 { 152, WTAP_ENCAP_USER5 },
272 { 153, WTAP_ENCAP_USER6 },
273 { 154, WTAP_ENCAP_USER7 },
274 { 155, WTAP_ENCAP_USER8 },
275 { 156, WTAP_ENCAP_USER9 },
276 { 157, WTAP_ENCAP_USER10 },
277 { 158, WTAP_ENCAP_USER11 },
278 { 159, WTAP_ENCAP_USER12 },
279 { 160, WTAP_ENCAP_USER13 },
280 { 161, WTAP_ENCAP_USER14 },
281 { 162, WTAP_ENCAP_USER15 },
283 { 163, WTAP_ENCAP_IEEE_802_11_AVS }, /* 802.11 plus AVS radio header */
286 * 164 is reserved for Juniper-private chassis-internal
287 * meta-information such as QoS profiles, etc..
290 { 165, WTAP_ENCAP_BACNET_MS_TP },
293 * 166 is reserved for a PPP variant in which the first byte
294 * of the 0xff03 header, the 0xff, is replaced by a direction
295 * byte. I don't know whether any captures look like that,
296 * but it is used for some Linux IP filtering (ipfilter?).
299 /* Ethernet PPPoE frames captured on a service PIC */
300 { 167, WTAP_ENCAP_JUNIPER_PPPOE },
303 * 168 is reserved for more Juniper private-chassis-
304 * internal meta-information.
307 { 169, WTAP_ENCAP_GPRS_LLC },
310 * 170 and 171 are reserved for ITU-T G.7041/Y.1303 Generic
314 /* Registered by Gcom, Inc. */
315 { 172, WTAP_ENCAP_GCOM_TIE1 },
316 { 173, WTAP_ENCAP_GCOM_SERIAL },
318 { 177, WTAP_ENCAP_LINUX_LAPD },
320 /* Ethernet frames prepended with meta-information */
321 { 178, WTAP_ENCAP_JUNIPER_ETHER },
322 /* PPP frames prepended with meta-information */
323 { 179, WTAP_ENCAP_JUNIPER_PPP },
324 /* Frame-Relay frames prepended with meta-information */
325 { 180, WTAP_ENCAP_JUNIPER_FRELAY },
326 /* C-HDLC frames prepended with meta-information */
327 { 181, WTAP_ENCAP_JUNIPER_CHDLC },
328 /* VOIP Frames prepended with meta-information */
329 { 183, WTAP_ENCAP_JUNIPER_VP },
330 /* raw USB packets */
331 { 186, WTAP_ENCAP_USB },
332 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
333 { 187, WTAP_ENCAP_BLUETOOTH_H4 },
334 /* IEEE 802.16 MAC Common Part Sublayer */
335 { 188, WTAP_ENCAP_IEEE802_16_MAC_CPS },
336 /* USB packets with Linux-specified header */
337 { 189, WTAP_ENCAP_USB_LINUX },
339 { 190, WTAP_ENCAP_CAN20B },
340 /* Per-Packet Information header */
341 { 192, WTAP_ENCAP_PPI },
342 /* IEEE 802.15.4 Wireless PAN */
343 { 195, WTAP_ENCAP_IEEE802_15_4 },
344 /* SITA File Encapsulation */
345 { 196, WTAP_ENCAP_SITA },
346 /* Endace Record File Encapsulation */
347 { 197, WTAP_ENCAP_ERF },
349 { 199, WTAP_ENCAP_IPMB },
350 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
351 { 201, WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR },
352 /* AX.25 packet with a 1-byte KISS header */
353 { 202, WTAP_ENCAP_AX25_KISS },
355 { 203, WTAP_ENCAP_LAPD },
356 /* PPP with pseudoheader */
357 { 204, WTAP_ENCAP_PPP_WITH_PHDR },
359 { 209, WTAP_ENCAP_I2C },
361 { 210, WTAP_ENCAP_FLEXRAY },
363 { 211, WTAP_ENCAP_MOST },
365 { 212, WTAP_ENCAP_LIN },
366 /* X2E Xoraya serial frame */
367 { 213, WTAP_ENCAP_X2E_SERIAL },
368 /* X2E Xoraya frame */
369 { 214, WTAP_ENCAP_X2E_XORAYA },
370 /* IEEE 802.15.4 Wireless PAN non-ASK PHY */
371 { 215, WTAP_ENCAP_IEEE802_15_4_NONASK_PHY },
372 /* USB packets with padded Linux-specified header */
373 { 220, WTAP_ENCAP_USB_LINUX_MMAPPED },
374 /* Fibre Channel FC-2 frame */
375 { 224, WTAP_ENCAP_FIBRE_CHANNEL_FC2 },
376 /* Fibre Channel FC-2 frame with Delimiter */
377 { 225, WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS },
379 { 226, WTAP_ENCAP_IPNET },
380 /* SocketCAN frame */
381 { 227, WTAP_ENCAP_SOCKETCAN },
383 { 228, WTAP_ENCAP_RAW_IP4 },
385 { 229, WTAP_ENCAP_RAW_IP6 },
386 /* IEEE 802.15.4 Wireless PAN no fcs */
387 { 230, WTAP_ENCAP_IEEE802_15_4_NOFCS },
389 { 231, WTAP_ENCAP_DBUS },
390 /* DVB-CI (Common Interface) */
391 { 235, WTAP_ENCAP_DVBCI },
393 { 236, WTAP_ENCAP_MUX27010 },
394 /* STANAG 5066 - DTS(Data Transfer Sublayer) PDU */
395 { 237, WTAP_ENCAP_STANAG_5066_D_PDU },
397 { 239, WTAP_ENCAP_NFLOG },
398 /* netANALYZER pseudo-header followed by Ethernet with CRC */
399 { 240, WTAP_ENCAP_NETANALYZER },
400 /* netANALYZER pseudo-header in transparent mode */
401 { 241, WTAP_ENCAP_NETANALYZER_TRANSPARENT },
402 /* IP-over-Infiniband, as specified by RFC 4391 section 6 */
403 { 242, WTAP_ENCAP_IP_OVER_IB },
404 /* ISO/IEC 13818-1 MPEG2-TS packets */
405 { 243, WTAP_ENCAP_MPEG_2_TS },
407 { 245, WTAP_ENCAP_NFC_LLCP },
409 { 248, WTAP_ENCAP_SCTP},
411 { 249, WTAP_ENCAP_USBPCAP},
413 { 250, WTAP_ENCAP_RTAC_SERIAL},
414 /* Bluetooth Low Energy Link Layer */
415 { 251, WTAP_ENCAP_BLUETOOTH_LE_LL},
416 /* Wireshark Upper PDU export */
417 { 252, WTAP_ENCAP_WIRESHARK_UPPER_PDU},
418 /* Netlink Protocol (nlmon devices) */
419 { 253, WTAP_ENCAP_NETLINK },
420 /* Bluetooth Linux Monitor */
421 { 254, WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR },
422 /* Bluetooth BR/EDR Baseband RF captures */
423 { 255, WTAP_ENCAP_BLUETOOTH_BREDR_BB },
424 /* Bluetooth Low Energy Link Layer RF captures */
425 { 256, WTAP_ENCAP_BLUETOOTH_LE_LL_WITH_PHDR },
428 { 258, WTAP_ENCAP_PKTAP },
430 /* Ethernet Passive Optical Network */
431 { 259, WTAP_ENCAP_EPON },
433 /* IPMI Trace Data Collection */
434 { 260, WTAP_ENCAP_IPMI_TRACE },
439 * If you need a new encapsulation type for libpcap files, do
440 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
441 * add a new encapsulation type by changing an existing entry;
442 * leave the existing entries alone.
444 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
445 * for a new DLT_ value, and specifying the purpose of the new value.
446 * When you get the new DLT_ value, use that numerical value in
447 * the "linktype_value" field of "pcap_to_wtap_map[]".
451 * The following are entries for libpcap type values that have
452 * different meanings on different OSes. I.e., these are DLT_
453 * values that are different on different OSes, and that have
454 * a separate LINKTYPE_ value assigned to them.
456 * We put these *after* the entries for the LINKTYPE_ values for
457 * those Wiretap encapsulation types, so that, when writing a
458 * pcap or pcap-ng file, Wireshark writes the LINKTYPE_ value,
459 * not the OS's DLT_ value, as the file's link-layer header type
460 * for pcap or the interface's link-layer header type.
464 * 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
465 * seen that define anything other than DLT_ATM_RFC1483 as 11 are
466 * the BSD/OS one, which defines DLT_FR as 11, and libpcap 0.5,
467 * which define it as 100, mapping the kernel's value to 100, in
468 * an attempt to hide the different values used on different
471 * If this is a platform where DLT_FR is defined as 11, we
472 * don't handle 11 at all; otherwise, we handle it as
473 * DLT_ATM_RFC1483 (this means we'd misinterpret Frame Relay
474 * captures from BSD/OS if running on platforms other than BSD/OS,
477 * 1) we don't yet support DLT_FR
481 * 2) nothing short of a heuristic would let us interpret
484 #if defined(DLT_FR) && (DLT_FR == 11)
485 { 11, WTAP_ENCAP_FRELAY },
487 { 11, WTAP_ENCAP_ATM_RFC1483 },
491 * 12 is DLT_RAW on most platforms, but it's DLT_C_HDLC on
492 * BSD/OS, and DLT_LOOP on OpenBSD.
494 * We don't yet handle DLT_C_HDLC, but we can handle DLT_LOOP
495 * (it's just like DLT_NULL, only with the AF_ value in network
496 * rather than host byte order - Wireshark figures out the
497 * byte order from the data, so we don't care what byte order
498 * it's in), so if DLT_LOOP is defined as 12, interpret 12
499 * as WTAP_ENCAP_NULL, otherwise, unless DLT_C_HDLC is defined
500 * as 12, interpret it as WTAP_ENCAP_RAW_IP.
502 #if defined(DLT_LOOP) && (DLT_LOOP == 12)
503 { 12, WTAP_ENCAP_NULL },
504 #elif defined(DLT_C_HDLC) && (DLT_C_HDLC == 12)
506 * Put entry for Cisco HDLC here.
507 * XXX - is this just WTAP_ENCAP_CHDLC, i.e. does the frame
508 * start with a 4-byte Cisco HDLC header?
511 { 12, WTAP_ENCAP_RAW_IP },
515 * 13 is DLT_SLIP_BSDOS on FreeBSD and NetBSD, but those OSes
516 * don't actually generate it. I infer that BSD/OS translates
517 * DLT_SLIP from the kernel BPF code to DLT_SLIP_BSDOS in
518 * libpcap, as the BSD/OS link-layer header is different;
519 * however, in BSD/OS, DLT_SLIP_BSDOS is 15.
521 * From this, I infer that there's no point in handling 13
524 * 13 is DLT_ATM_RFC1483 on BSD/OS.
526 * 13 is DLT_ENC in OpenBSD, which is, I suspect, some kind
527 * of decrypted IPsec traffic.
529 * We treat 13 as WTAP_ENCAP_ENC on all systems except those
530 * that define DLT_ATM_RFC1483 as 13 - presumably only
531 * BSD/OS does so - so that, on BSD/OS systems, we still
532 * treate 13 as WTAP_ENCAP_ATM_RFC1483, but, on all other
533 * systems, we can read OpenBSD DLT_ENC captures.
535 #if defined(DLT_ATM_RFC1483) && (DLT_ATM_RFC1483 == 13)
536 { 13, WTAP_ENCAP_ATM_RFC1483 },
538 { 13, WTAP_ENCAP_ENC },
542 * 14 is DLT_PPP_BSDOS on FreeBSD and NetBSD, but those OSes
543 * don't actually generate it. I infer that BSD/OS translates
544 * DLT_PPP from the kernel BPF code to DLT_PPP_BSDOS in
545 * libpcap, as the BSD/OS link-layer header is different;
546 * however, in BSD/OS, DLT_PPP_BSDOS is 16.
548 * From this, I infer that there's no point in handling 14
551 * 14 is DLT_RAW on BSD/OS and OpenBSD.
553 { 14, WTAP_ENCAP_RAW_IP },
558 * DLT_SLIP_BSDOS on BSD/OS;
560 * DLT_HIPPI on NetBSD;
562 * DLT_LANE8023 with Alexey Kuznetzov's patches for
565 * DLT_I4L_RAWIP with the ISDN4Linux patches for libpcap
568 * but we don't currently handle any of those.
574 * DLT_PPP_BSDOS on BSD/OS;
576 * DLT_HDLC on NetBSD (Cisco HDLC);
578 * DLT_CIP with Alexey Kuznetzov's patches for
579 * Linux libpcap - this is WTAP_ENCAP_LINUX_ATM_CLIP;
581 * DLT_I4L_IP with the ISDN4Linux patches for libpcap
584 #if defined(DLT_CIP) && (DLT_CIP == 16)
585 { 16, WTAP_ENCAP_LINUX_ATM_CLIP },
587 #if defined(DLT_HDLC) && (DLT_HDLC == 16)
588 { 16, WTAP_ENCAP_CHDLC },
592 * 17 is DLT_LANE8023 in SuSE 6.3 libpcap; we don't currently
594 * It is also used as the PF (Packet Filter) logging format beginning
595 * with OpenBSD 3.0; we use 17 for PF logs unless DLT_LANE8023 is
596 * defined with the value 17.
598 #if !defined(DLT_LANE8023) || (DLT_LANE8023 != 17)
599 { 17, WTAP_ENCAP_OLD_PFLOG },
603 * 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
604 * DLT_CIP of 16 that the Alexey Kuznetzov patches for
605 * libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
606 * I've not found any libpcap that uses it for any other purpose -
607 * hopefully nobody will do so in the future.
609 { 18, WTAP_ENCAP_LINUX_ATM_CLIP },
612 * 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
613 * recent versions I've seen of the Linux ATM distribution;
614 * I've not yet found any libpcap that uses it for any other
615 * purpose - hopefully nobody will do so in the future.
617 { 19, WTAP_ENCAP_LINUX_ATM_CLIP },
622 * If you need a new encapsulation type for libpcap files, do
623 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
624 * add a new encapsulation type by changing an existing entry;
625 * leave the existing entries alone.
627 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
628 * for a new DLT_ value, and specifying the purpose of the new value.
629 * When you get the new DLT_ value, use that numerical value in
630 * the "linktype_value" field of "pcap_to_wtap_map[]".
633 #define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0])
636 wtap_pcap_encap_to_wtap_encap(int encap)
640 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
641 if (pcap_to_wtap_map[i].linktype_value == encap)
642 return pcap_to_wtap_map[i].wtap_encap_value;
644 return WTAP_ENCAP_UNKNOWN;
648 wtap_wtap_encap_to_pcap_encap(int encap)
654 case WTAP_ENCAP_FDDI:
655 case WTAP_ENCAP_FDDI_BITSWAPPED:
657 * Special-case WTAP_ENCAP_FDDI and
658 * WTAP_ENCAP_FDDI_BITSWAPPED; both of them get mapped
659 * to DLT_FDDI (even though that may mean that the bit
660 * order in the FDDI MAC addresses is wrong; so it goes
661 * - libpcap format doesn't record the byte order,
662 * so that's not fixable).
664 * The pcap_to_wtap_map[] table will only have an
665 * entry for one of the above, which is why we have
666 * to special-case them.
668 return 10; /* that's DLT_FDDI */
670 case WTAP_ENCAP_NETTL_FDDI:
672 * This will discard the nettl information, as that's
673 * in the pseudo-header.
675 * XXX - what about Ethernet and Token Ring?
677 return 10; /* that's DLT_FDDI */
679 case WTAP_ENCAP_FRELAY_WITH_PHDR:
681 * This will discard the pseudo-header information.
685 case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
687 * Map this to DLT_IEEE802_11, for now, even though
688 * that means the radio information will be lost.
689 * We should try to map those values to radiotap
690 * values and write this out as a radiotap file,
696 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
697 if (pcap_to_wtap_map[i].wtap_encap_value == encap)
698 return pcap_to_wtap_map[i].linktype_value;
704 wtap_encap_requires_phdr(int encap) {
706 (encap == WTAP_ENCAP_ATM_PDUS) ||
707 (encap == WTAP_ENCAP_IRDA) ||
708 (encap == WTAP_ENCAP_MTP2_WITH_PHDR) ||
709 (encap == WTAP_ENCAP_LINUX_LAPD) ||
710 (encap == WTAP_ENCAP_SITA) ||
711 (encap == WTAP_ENCAP_ERF) ||
712 (encap == WTAP_ENCAP_I2C) ||
713 (encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) ||
714 (encap == WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR) ||
715 (encap == WTAP_ENCAP_PPP_WITH_PHDR)
724 * Various pseudo-headers that appear at the beginning of packet data.
726 * We represent them as sets of offsets, as they might not be aligned on
727 * an appropriate structure boundary in the buffer, and as that makes them
728 * independent of the way the compiler might align fields.
732 * The link-layer header on SunATM packets.
734 #define SUNATM_FLAGS 0 /* destination and traffic type - 1 byte */
735 #define SUNATM_VPI 1 /* VPI - 1 byte */
736 #define SUNATM_VCI 2 /* VCI - 2 bytes */
737 #define SUNATM_LEN 4 /* length of the header */
740 * The link-layer header on Nokia IPSO ATM packets.
742 #define NOKIAATM_FLAGS 0 /* destination - 1 byte */
743 #define NOKIAATM_VPI 1 /* VPI - 1 byte */
744 #define NOKIAATM_VCI 2 /* VCI - 2 bytes */
745 #define NOKIAATM_LEN 4 /* length of the header */
748 * The link-layer header on Nokia IPSO packets.
750 #define NOKIA_LEN 4 /* length of the header */
753 * The fake link-layer header of IrDA packets as introduced by Jean Tourrilhes
756 #define IRDA_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
757 /* 12 unused bytes */
758 #define IRDA_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
759 #define IRDA_SLL_LEN 16 /* length of the header */
762 * A header containing additional MTP information.
764 #define MTP2_SENT_OFFSET 0 /* 1 byte */
765 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
766 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
767 #define MTP2_HDR_LEN 4 /* length of the header */
770 * A header containing additional SITA WAN information.
772 #define SITA_FLAGS_OFFSET 0 /* 1 byte */
773 #define SITA_SIGNALS_OFFSET 1 /* 1 byte */
774 #define SITA_ERRORS1_OFFSET 2 /* 1 byte */
775 #define SITA_ERRORS2_OFFSET 3 /* 1 byte */
776 #define SITA_PROTO_OFFSET 4 /* 1 byte */
777 #define SITA_HDR_LEN 5 /* length of the header */
780 * The fake link-layer header of LAPD packets.
783 #define ETH_P_LAPD 0x0030
786 #define LAPD_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
787 #define LAPD_SLL_HATYPE_OFFSET 2 /* hardware address type - 2 bytes */
788 #define LAPD_SLL_HALEN_OFFSET 4 /* hardware address length - 2 bytes */
789 #define LAPD_SLL_ADDR_OFFSET 6 /* address - 8 bytes */
790 #define LAPD_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
791 #define LAPD_SLL_LEN 16 /* length of the header */
794 * The NFC LLCP per-packet header.
796 #define LLCP_ADAPTER_OFFSET 0
797 #define LLCP_FLAGS_OFFSET 1
798 #define LLCP_HEADER_LEN 2
801 * I2C link-layer on-disk format
803 struct i2c_file_hdr {
809 pcap_read_sunatm_pseudoheader(FILE_T fh,
810 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
812 guint8 atm_phdr[SUNATM_LEN];
816 errno = WTAP_ERR_CANT_READ;
817 if (!wtap_read_bytes(fh, atm_phdr, SUNATM_LEN, err, err_info))
820 vpi = atm_phdr[SUNATM_VPI];
821 vci = pntoh16(&atm_phdr[SUNATM_VCI]);
823 switch (atm_phdr[SUNATM_FLAGS] & 0x0F) {
825 case 0x01: /* LANE */
826 pseudo_header->atm.aal = AAL_5;
827 pseudo_header->atm.type = TRAF_LANE;
830 case 0x02: /* RFC 1483 LLC multiplexed traffic */
831 pseudo_header->atm.aal = AAL_5;
832 pseudo_header->atm.type = TRAF_LLCMX;
835 case 0x05: /* ILMI */
836 pseudo_header->atm.aal = AAL_5;
837 pseudo_header->atm.type = TRAF_ILMI;
840 case 0x06: /* Q.2931 */
841 pseudo_header->atm.aal = AAL_SIGNALLING;
842 pseudo_header->atm.type = TRAF_UNKNOWN;
845 case 0x03: /* MARS (RFC 2022) */
846 pseudo_header->atm.aal = AAL_5;
847 pseudo_header->atm.type = TRAF_UNKNOWN;
850 case 0x04: /* IFMP (Ipsilon Flow Management Protocol; see RFC 1954) */
851 pseudo_header->atm.aal = AAL_5;
852 pseudo_header->atm.type = TRAF_UNKNOWN; /* XXX - TRAF_IPSILON? */
857 * Assume it's AAL5, unless it's VPI 0 and VCI 5, in which
858 * case assume it's AAL_SIGNALLING; we know nothing more
861 * XXX - is this necessary? Or are we guaranteed that
862 * all signalling traffic has a type of 0x06?
864 * XXX - is this guaranteed to be AAL5? Or, if the type is
865 * 0x00 ("raw"), might it be non-AAL5 traffic?
867 if (vpi == 0 && vci == 5)
868 pseudo_header->atm.aal = AAL_SIGNALLING;
870 pseudo_header->atm.aal = AAL_5;
871 pseudo_header->atm.type = TRAF_UNKNOWN;
874 pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
876 pseudo_header->atm.vpi = vpi;
877 pseudo_header->atm.vci = vci;
878 pseudo_header->atm.channel = (atm_phdr[SUNATM_FLAGS] & 0x80) ? 0 : 1;
880 /* We don't have this information */
881 pseudo_header->atm.flags = 0;
882 pseudo_header->atm.cells = 0;
883 pseudo_header->atm.aal5t_u2u = 0;
884 pseudo_header->atm.aal5t_len = 0;
885 pseudo_header->atm.aal5t_chksum = 0;
891 pcap_read_nokiaatm_pseudoheader(FILE_T fh,
892 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
894 guint8 atm_phdr[NOKIAATM_LEN];
898 errno = WTAP_ERR_CANT_READ;
899 if (!wtap_read_bytes(fh, atm_phdr, NOKIAATM_LEN, err, err_info))
902 vpi = atm_phdr[NOKIAATM_VPI];
903 vci = pntoh16(&atm_phdr[NOKIAATM_VCI]);
905 pseudo_header->atm.vpi = vpi;
906 pseudo_header->atm.vci = vci;
907 pseudo_header->atm.channel = (atm_phdr[NOKIAATM_FLAGS] & 0x80) ? 0 : 1;
909 /* We don't have this information */
910 pseudo_header->atm.flags = 0;
911 pseudo_header->atm.cells = 0;
912 pseudo_header->atm.aal5t_u2u = 0;
913 pseudo_header->atm.aal5t_len = 0;
914 pseudo_header->atm.aal5t_chksum = 0;
920 pcap_read_nokia_pseudoheader(FILE_T fh,
921 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
923 guint8 phdr[NOKIA_LEN];
925 errno = WTAP_ERR_CANT_READ;
927 /* backtrack to read the 4 mysterious bytes that aren't considered
928 * part of the packet size
930 if (file_seek(fh, -NOKIA_LEN, SEEK_CUR, err) == -1)
932 *err = file_error(fh, err_info);
934 *err = WTAP_ERR_SHORT_READ;
938 if (!wtap_read_bytes(fh, phdr, NOKIA_LEN, err, err_info))
941 memcpy(pseudo_header->nokia.stuff, phdr, NOKIA_LEN);
947 pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
948 int *err, gchar **err_info)
950 guint8 irda_phdr[IRDA_SLL_LEN];
952 errno = WTAP_ERR_CANT_READ;
953 if (!wtap_read_bytes(fh, irda_phdr, IRDA_SLL_LEN, err, err_info))
956 if (pntoh16(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
957 *err = WTAP_ERR_BAD_FILE;
958 if (err_info != NULL)
959 *err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
963 pseudo_header->irda.pkttype = pntoh16(&irda_phdr[IRDA_SLL_PKTTYPE_OFFSET]);
969 pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
971 guint8 mtp2_hdr[MTP2_HDR_LEN];
973 errno = WTAP_ERR_CANT_READ;
974 if (!wtap_read_bytes(fh, mtp2_hdr, MTP2_HDR_LEN, err, err_info))
977 pseudo_header->mtp2.sent = mtp2_hdr[MTP2_SENT_OFFSET];
978 pseudo_header->mtp2.annex_a_used = mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET];
979 pseudo_header->mtp2.link_number = pntoh16(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET]);
985 pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
986 int *err, gchar **err_info)
988 guint8 lapd_phdr[LAPD_SLL_LEN];
990 errno = WTAP_ERR_CANT_READ;
991 if (!wtap_read_bytes(fh, lapd_phdr, LAPD_SLL_LEN, err, err_info))
994 if (pntoh16(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
995 *err = WTAP_ERR_BAD_FILE;
996 if (err_info != NULL)
997 *err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
1001 pseudo_header->lapd.pkttype = pntoh16(&lapd_phdr[LAPD_SLL_PKTTYPE_OFFSET]);
1002 pseudo_header->lapd.we_network = !!lapd_phdr[LAPD_SLL_ADDR_OFFSET+0];
1008 pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1010 guint8 sita_phdr[SITA_HDR_LEN];
1012 errno = WTAP_ERR_CANT_READ;
1013 if (!wtap_read_bytes(fh, sita_phdr, SITA_HDR_LEN, err, err_info))
1016 pseudo_header->sita.sita_flags = sita_phdr[SITA_FLAGS_OFFSET];
1017 pseudo_header->sita.sita_signals = sita_phdr[SITA_SIGNALS_OFFSET];
1018 pseudo_header->sita.sita_errors1 = sita_phdr[SITA_ERRORS1_OFFSET];
1019 pseudo_header->sita.sita_errors2 = sita_phdr[SITA_ERRORS2_OFFSET];
1020 pseudo_header->sita.sita_proto = sita_phdr[SITA_PROTO_OFFSET];
1026 * When not using the memory-mapped interface to capture USB events,
1027 * code that reads those events can use the MON_IOCX_GET ioctl to
1028 * read a 48-byte header consisting of a "struct linux_usb_phdr", as
1029 * defined below, followed immediately by one of:
1031 * 8 bytes of a "struct usb_device_setup_hdr", if "setup_flag"
1032 * in the preceding "struct linux_usb_phdr" is 0;
1034 * in Linux 2.6.30 or later, 8 bytes of a "struct iso_rec", if
1035 * this is an isochronous transfer;
1037 * 8 bytes of junk, otherwise.
1039 * In Linux 2.6.31 and later, it can also use the MON_IOCX_GETX ioctl
1040 * to read a 64-byte header; that header consists of the 48 bytes
1041 * above, followed immediately by 16 bytes of a "struct linux_usb_phdr_ext",
1044 * In Linux 2.6.21 and later, there's a memory-mapped interface to
1045 * capture USB events. In that interface, the events in the memory-mapped
1046 * buffer have a 64-byte header, followed immediately by the data.
1047 * In Linux 2.6.21 through 2.6.30.x, the 64-byte header is the 48-byte
1048 * header described above, followed by 16 bytes of zeroes; in Linux
1049 * 2.6.31 and later, the 64-byte header is the 64-byte header described
1052 * See linux/Documentation/usb/usbmon.txt and libpcap/pcap/usb.h for details.
1054 * With WTAP_ENCAP_USB_LINUX, packets have the 48-byte header; with
1055 * WTAP_ENCAP_USB_LINUX_MMAPPED, they have the 64-byte header. There
1056 * is no indication of whether the header has the "struct iso_rec", or
1057 * whether the last 16 bytes of a 64-byte header are all zeros or are
1058 * a "struct linux_usb_phdr_ext".
1062 * URB transfer_type values
1064 #define URB_ISOCHRONOUS 0x0
1065 #define URB_INTERRUPT 0x1
1066 #define URB_CONTROL 0x2
1067 #define URB_BULK 0x3
1070 * Information from the URB for Isochronous transfers.
1072 * This structure is 8 bytes long.
1080 * Header prepended by Linux kernel to each USB event.
1082 * (Setup flag is '-', 'D', 'Z', or 0. Data flag is '<', '>', 'Z', or 0.)
1084 * The values are in *host* byte order.
1086 struct linux_usb_phdr {
1087 guint64 id; /* urb id, to link submission and completion events */
1088 guint8 event_type; /* Submit ('S'), Completed ('C'), Error ('E') */
1089 guint8 transfer_type; /* ISO (0), Intr, Control, Bulk (3) */
1090 guint8 endpoint_number; /* Endpoint number (0-15) and transfer direction */
1091 guint8 device_address; /* 0-127 */
1093 gint8 setup_flag; /* 0, if the urb setup header is meaningful */
1094 gint8 data_flag; /* 0, if urb data is present */
1098 guint32 urb_len; /* whole len of urb this event refers to */
1099 guint32 data_len; /* amount of urb data really present in this event */
1102 * Packet-type-dependent data.
1103 * USB setup information of setup_flag is true.
1104 * Otherwise, some isochronous transfer information.
1112 * This data is provided by Linux 2.6.31 and later kernels.
1114 * For WTAP_ENCAP_USB_LINUX, it's not in the pseudo-header, so
1115 * the pseudo-header is always 48 bytes long, including the
1116 * packet-type-dependent data.
1118 * For WTAP_ENCAP_USB_LINUX_MMAPPED, the pseudo-header is always
1119 * 64 bytes long, with the packet-type-dependent data preceding
1120 * these last 16 bytes. In pre-2.6.31 kernels, it's zero padding;
1121 * in 2.6.31 and later, it's the following data.
1123 gint32 interval; /* only for Interrupt and Isochronous events */
1124 gint32 start_frame; /* for Isochronous */
1125 guint32 xfer_flags; /* copy of URB's transfer_flags */
1126 guint32 ndesc; /* actual number of isochronous descriptors */
1129 struct linux_usb_isodesc {
1137 * USB setup header as defined in USB specification
1138 * See usb_20.pdf, Chapter 9.3 'USB Device Requests' for details.
1139 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
1141 * This structure is 8 bytes long.
1143 struct usb_device_setup_hdr {
1144 gint8 bmRequestType;
1153 * Offset of the *end* of a field within a particular structure.
1155 #define END_OFFSETOF(basep, fieldp) \
1156 (((char *)(void *)(fieldp)) - ((char *)(void *)(basep)) + \
1160 * Is that offset within the bounds of the packet?
1162 #define WITHIN_PACKET(basep, fieldp) \
1163 (packet_size >= END_OFFSETOF((basep), (fieldp)))
1165 #define CHECK_AND_SWAP16(fieldp) \
1167 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1169 PBSWAP16((guint8 *)fieldp); \
1172 #define CHECK_AND_SWAP32(fieldp) \
1174 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1176 PBSWAP32((guint8 *)fieldp); \
1179 #define CHECK_AND_SWAP64(fieldp) \
1181 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1183 PBSWAP64((guint8 *)fieldp); \
1187 pcap_byteswap_linux_usb_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd,
1188 gboolean header_len_64_bytes)
1191 struct linux_usb_phdr *usb_phdr;
1192 struct linux_usb_isodesc *pisodesc;
1193 gint32 iso_numdesc, i;
1196 * Minimum of captured and actual length (just in case the
1197 * actual length < the captured length, which Should Never
1200 packet_size = phdr->caplen;
1201 if (packet_size > phdr->len)
1202 packet_size = phdr->len;
1205 * Greasy hack, but we never directly dereference any of
1206 * the fields in *usb_phdr, we just get offsets of and
1207 * addresses of its members and byte-swap it with a
1208 * byte-at-a-time macro, so it's alignment-safe.
1210 usb_phdr = (struct linux_usb_phdr *)(void *)pd;
1212 CHECK_AND_SWAP64(&usb_phdr->id);
1213 CHECK_AND_SWAP16(&usb_phdr->bus_id);
1214 CHECK_AND_SWAP64(&usb_phdr->ts_sec);
1215 CHECK_AND_SWAP32(&usb_phdr->ts_usec);
1216 CHECK_AND_SWAP32(&usb_phdr->status);
1217 CHECK_AND_SWAP32(&usb_phdr->urb_len);
1218 CHECK_AND_SWAP32(&usb_phdr->data_len);
1220 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1221 CHECK_AND_SWAP32(&usb_phdr->s.iso.error_count);
1222 CHECK_AND_SWAP32(&usb_phdr->s.iso.numdesc);
1225 if (header_len_64_bytes) {
1227 * This is either the "version 1" header, with
1228 * 16 bytes of additional fields at the end, or
1229 * a "version 0" header from a memory-mapped
1230 * capture, with 16 bytes of zeroed-out padding
1231 * at the end. Byte swap them as if this were
1232 * a "version 1" header.
1234 * Yes, the first argument to END_OFFSETOF() should
1235 * be usb_phdr, not usb_phdr_ext; we want the offset of
1236 * the additional fields from the beginning of
1239 CHECK_AND_SWAP32(&usb_phdr->interval);
1240 CHECK_AND_SWAP32(&usb_phdr->start_frame);
1241 CHECK_AND_SWAP32(&usb_phdr->xfer_flags);
1242 CHECK_AND_SWAP32(&usb_phdr->ndesc);
1245 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1246 /* swap the values in struct linux_usb_isodesc */
1249 * See previous "Greasy hack" comment.
1251 if (header_len_64_bytes) {
1252 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 64);
1254 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 48);
1256 iso_numdesc = usb_phdr->s.iso.numdesc;
1257 for (i = 0; i < iso_numdesc; i++) {
1258 CHECK_AND_SWAP32(&pisodesc->iso_status);
1259 CHECK_AND_SWAP32(&pisodesc->iso_off);
1260 CHECK_AND_SWAP32(&pisodesc->iso_len);
1261 CHECK_AND_SWAP32(&pisodesc->_pad);
1269 guint8 nflog_family; /* address family */
1270 guint8 nflog_version; /* version */
1271 guint16 nflog_rid; /* resource ID */
1275 guint16 tlv_length; /* tlv length */
1276 guint16 tlv_type; /* tlv type */
1277 /* value follows this */
1281 pcap_byteswap_nflog_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd)
1285 struct nflog_hdr *nfhdr;
1286 struct nflog_tlv *tlv;
1290 * Minimum of captured and actual length (just in case the
1291 * actual length < the captured length, which Should Never
1294 packet_size = phdr->caplen;
1295 if (packet_size > phdr->len)
1296 packet_size = phdr->len;
1298 if (packet_size < sizeof(struct nflog_hdr)) {
1299 /* Not enough data to have any TLVs. */
1304 nfhdr = (struct nflog_hdr *)pd;
1305 if (!(nfhdr->nflog_version) == 0) {
1306 /* Unknown NFLOG version */
1310 packet_size -= (guint)sizeof(struct nflog_hdr);
1311 p += sizeof(struct nflog_hdr);
1313 while (packet_size >= sizeof(struct nflog_tlv)) {
1314 tlv = (struct nflog_tlv *) p;
1316 /* Swap the type and length. */
1317 PBSWAP16((guint8 *)&tlv->tlv_type);
1318 PBSWAP16((guint8 *)&tlv->tlv_length);
1320 /* Get the length of the TLV. */
1321 size = tlv->tlv_length;
1323 size += 4 - size % 4;
1325 /* Is the TLV's length less than the minimum? */
1326 if (size < sizeof(struct nflog_tlv)) {
1327 /* Yes. Give up now. */
1331 /* Do we have enough data for the full TLV? */
1332 if (packet_size < size) {
1337 /* Skip over the TLV. */
1338 packet_size -= size;
1344 pcap_read_bt_pseudoheader(FILE_T fh,
1345 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1347 struct libpcap_bt_phdr phdr;
1349 errno = WTAP_ERR_CANT_READ;
1350 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_phdr),
1353 pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
1358 pcap_read_bt_monitor_pseudoheader(FILE_T fh,
1359 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1361 struct libpcap_bt_monitor_phdr phdr;
1363 errno = WTAP_ERR_CANT_READ;
1364 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_monitor_phdr),
1368 pseudo_header->btmon.adapter_id = g_ntohs(phdr.adapter_id);
1369 pseudo_header->btmon.opcode = g_ntohs(phdr.opcode);
1374 pcap_read_llcp_pseudoheader(FILE_T fh,
1375 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1377 guint8 phdr[LLCP_HEADER_LEN];
1379 errno = WTAP_ERR_CANT_READ;
1380 if (!wtap_read_bytes(fh, phdr, LLCP_HEADER_LEN, err, err_info))
1382 pseudo_header->llcp.adapter = phdr[LLCP_ADAPTER_OFFSET];
1383 pseudo_header->llcp.flags = phdr[LLCP_FLAGS_OFFSET];
1388 pcap_read_ppp_pseudoheader(FILE_T fh,
1389 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1391 struct libpcap_ppp_phdr phdr;
1393 errno = WTAP_ERR_CANT_READ;
1394 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_ppp_phdr),
1397 pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
1402 pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr,
1403 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1405 guint8 erf_hdr[sizeof(struct erf_phdr)];
1407 errno = WTAP_ERR_CANT_READ;
1408 if (!wtap_read_bytes(fh, erf_hdr, sizeof(struct erf_phdr), err, err_info))
1410 pseudo_header->erf.phdr.ts = pletoh64(&erf_hdr[0]); /* timestamp */
1411 pseudo_header->erf.phdr.type = erf_hdr[8];
1412 pseudo_header->erf.phdr.flags = erf_hdr[9];
1413 pseudo_header->erf.phdr.rlen = pntoh16(&erf_hdr[10]);
1414 pseudo_header->erf.phdr.lctr = pntoh16(&erf_hdr[12]);
1415 pseudo_header->erf.phdr.wlen = pntoh16(&erf_hdr[14]);
1417 /* The high 32 bits of the timestamp contain the integer number of seconds
1418 * while the lower 32 bits contain the binary fraction of the second.
1419 * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */
1421 guint64 ts = pseudo_header->erf.phdr.ts;
1422 whdr->ts.secs = (guint32) (ts >> 32);
1423 ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000);
1424 ts += (ts & 0x80000000) << 1; /* rounding */
1425 whdr->ts.nsecs = ((guint32) (ts >> 32));
1426 if ( whdr->ts.nsecs >= 1000000000) {
1427 whdr->ts.nsecs -= 1000000000;
1435 * If the type of record given in the pseudo header indicate the presence of an extension
1436 * header then, read all the extension headers
1439 pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1440 int *err, gchar **err_info, guint * psize)
1442 guint8 erf_exhdr[8];
1443 guint64 erf_exhdr_sw;
1444 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1447 if (pseudo_header->erf.phdr.type & 0x80){
1449 errno = WTAP_ERR_CANT_READ;
1450 if (!wtap_read_bytes(fh, erf_exhdr, 8, err, err_info))
1452 type = erf_exhdr[0];
1453 erf_exhdr_sw = pntoh64(erf_exhdr);
1455 memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw));
1458 } while (type & 0x80);
1464 * If the type of record given in the pseudo header indicate the precense of a subheader
1465 * then, read this optional subheader
1468 pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1469 int *err, gchar **err_info, guint * psize)
1471 guint8 erf_subhdr[sizeof(union erf_subhdr)];
1474 switch(pseudo_header->erf.phdr.type & 0x7F) {
1475 case ERF_TYPE_MC_HDLC:
1476 case ERF_TYPE_MC_RAW:
1477 case ERF_TYPE_MC_ATM:
1478 case ERF_TYPE_MC_RAW_CHANNEL:
1479 case ERF_TYPE_MC_AAL5:
1480 case ERF_TYPE_MC_AAL2:
1481 case ERF_TYPE_COLOR_MC_HDLC_POS:
1482 /* Extract the Multi Channel header to include it in the pseudo header part */
1483 errno = WTAP_ERR_CANT_READ;
1484 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_mc_header_t), err, err_info))
1486 pseudo_header->erf.subhdr.mc_hdr = pntoh32(&erf_subhdr[0]);
1487 *psize = sizeof(erf_mc_header_t);
1490 case ERF_TYPE_COLOR_ETH:
1491 case ERF_TYPE_DSM_COLOR_ETH:
1492 /* Extract the Ethernet additional header to include it in the pseudo header part */
1493 errno = WTAP_ERR_CANT_READ;
1494 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_eth_header_t), err, err_info))
1496 pseudo_header->erf.subhdr.eth_hdr = pntoh16(&erf_subhdr[0]);
1497 *psize = sizeof(erf_eth_header_t);
1500 /* No optional pseudo header for this ERF type */
1507 pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1509 struct i2c_file_hdr i2c_hdr;
1511 errno = WTAP_ERR_CANT_READ;
1512 if (!wtap_read_bytes(fh, &i2c_hdr, sizeof (i2c_hdr), err, err_info))
1515 pseudo_header->i2c.is_event = i2c_hdr.bus & 0x80 ? 1 : 0;
1516 pseudo_header->i2c.bus = i2c_hdr.bus & 0x7f;
1517 pseudo_header->i2c.flags = pntoh32(&i2c_hdr.flags);
1523 pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
1524 guint packet_size, gboolean check_packet_size,
1525 struct wtap_pkthdr *phdr, int *err, gchar **err_info)
1530 switch (wtap_encap) {
1532 case WTAP_ENCAP_ATM_PDUS:
1533 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1537 if (check_packet_size && packet_size < NOKIAATM_LEN) {
1539 * Uh-oh, the packet isn't big enough to even
1540 * have a pseudo-header.
1542 *err = WTAP_ERR_BAD_FILE;
1543 *err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1547 if (!pcap_read_nokiaatm_pseudoheader(fh,
1548 &phdr->pseudo_header, err, err_info))
1549 return -1; /* Read error */
1551 phdr_len = NOKIAATM_LEN;
1556 if (check_packet_size && packet_size < SUNATM_LEN) {
1558 * Uh-oh, the packet isn't big enough to even
1559 * have a pseudo-header.
1561 *err = WTAP_ERR_BAD_FILE;
1562 *err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1566 if (!pcap_read_sunatm_pseudoheader(fh,
1567 &phdr->pseudo_header, err, err_info))
1568 return -1; /* Read error */
1570 phdr_len = SUNATM_LEN;
1574 case WTAP_ENCAP_ETHERNET:
1575 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1577 * Nokia IPSO. Psuedo header has already been read, but it's not considered
1578 * part of the packet size, so reread it to store the data for later (when saving)
1580 if (!pcap_read_nokia_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1581 return -1; /* Read error */
1585 * We don't know whether there's an FCS in this frame or not.
1587 phdr->pseudo_header.eth.fcs_len = -1;
1590 case WTAP_ENCAP_IEEE_802_11:
1591 case WTAP_ENCAP_IEEE_802_11_PRISM:
1592 case WTAP_ENCAP_IEEE_802_11_RADIOTAP:
1593 case WTAP_ENCAP_IEEE_802_11_AVS:
1595 * We don't know whether there's an FCS in this frame or not.
1596 * XXX - are there any OSes where the capture mechanism
1599 phdr->pseudo_header.ieee_802_11.fcs_len = -1;
1600 phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
1601 phdr->pseudo_header.ieee_802_11.channel = 0;
1602 phdr->pseudo_header.ieee_802_11.data_rate = 0;
1603 phdr->pseudo_header.ieee_802_11.signal_level = 0;
1606 case WTAP_ENCAP_IRDA:
1607 if (check_packet_size && packet_size < IRDA_SLL_LEN) {
1609 * Uh-oh, the packet isn't big enough to even
1610 * have a pseudo-header.
1612 *err = WTAP_ERR_BAD_FILE;
1613 *err_info = g_strdup_printf("pcap: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
1617 if (!pcap_read_irda_pseudoheader(fh, &phdr->pseudo_header,
1619 return -1; /* Read error */
1621 phdr_len = IRDA_SLL_LEN;
1624 case WTAP_ENCAP_MTP2_WITH_PHDR:
1625 if (check_packet_size && packet_size < MTP2_HDR_LEN) {
1627 * Uh-oh, the packet isn't big enough to even
1628 * have a pseudo-header.
1630 *err = WTAP_ERR_BAD_FILE;
1631 *err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
1635 if (!pcap_read_mtp2_pseudoheader(fh, &phdr->pseudo_header,
1637 return -1; /* Read error */
1639 phdr_len = MTP2_HDR_LEN;
1642 case WTAP_ENCAP_LINUX_LAPD:
1643 if (check_packet_size && packet_size < LAPD_SLL_LEN) {
1645 * Uh-oh, the packet isn't big enough to even
1646 * have a pseudo-header.
1648 *err = WTAP_ERR_BAD_FILE;
1649 *err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
1653 if (!pcap_read_lapd_pseudoheader(fh, &phdr->pseudo_header,
1655 return -1; /* Read error */
1657 phdr_len = LAPD_SLL_LEN;
1660 case WTAP_ENCAP_SITA:
1661 if (check_packet_size && packet_size < SITA_HDR_LEN) {
1663 * Uh-oh, the packet isn't big enough to even
1664 * have a pseudo-header.
1666 *err = WTAP_ERR_BAD_FILE;
1667 *err_info = g_strdup_printf("pcap: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
1671 if (!pcap_read_sita_pseudoheader(fh, &phdr->pseudo_header,
1673 return -1; /* Read error */
1675 phdr_len = SITA_HDR_LEN;
1678 case WTAP_ENCAP_BLUETOOTH_H4:
1679 /* We don't have pseudoheader, so just pretend we received everything. */
1680 phdr->pseudo_header.p2p.sent = FALSE;
1683 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1684 if (check_packet_size &&
1685 packet_size < sizeof (struct libpcap_bt_phdr)) {
1687 * Uh-oh, the packet isn't big enough to even
1688 * have a pseudo-header.
1690 *err = WTAP_ERR_BAD_FILE;
1691 *err_info = g_strdup_printf("pcap: libpcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
1695 if (!pcap_read_bt_pseudoheader(fh,
1696 &phdr->pseudo_header, err, err_info))
1697 return -1; /* Read error */
1699 phdr_len = (int)sizeof (struct libpcap_bt_phdr);
1702 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
1703 if (check_packet_size &&
1704 packet_size < sizeof (struct libpcap_bt_monitor_phdr)) {
1706 * Uh-oh, the packet isn't big enough to even
1707 * have a pseudo-header.
1709 *err = WTAP_ERR_BAD_FILE;
1710 *err_info = g_strdup_printf("pcap: libpcap bluetooth monitor file has a %u-byte packet, too small to have even a pseudo-header",
1714 if (!pcap_read_bt_monitor_pseudoheader(fh,
1715 &phdr->pseudo_header, err, err_info))
1716 return -1; /* Read error */
1718 phdr_len = (int)sizeof (struct libpcap_bt_monitor_phdr);
1721 case WTAP_ENCAP_NFC_LLCP:
1722 if (check_packet_size && packet_size < LLCP_HEADER_LEN) {
1723 *err = WTAP_ERR_BAD_FILE;
1724 *err_info = g_strdup_printf("pcap: libpcap llcp file too short");
1727 if (!pcap_read_llcp_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1728 return -1; /* Read error */
1729 phdr_len = LLCP_HEADER_LEN;
1732 case WTAP_ENCAP_PPP_WITH_PHDR:
1733 if (check_packet_size &&
1734 packet_size < sizeof (struct libpcap_ppp_phdr)) {
1736 * Uh-oh, the packet isn't big enough to even
1737 * have a pseudo-header.
1739 *err = WTAP_ERR_BAD_FILE;
1740 *err_info = g_strdup_printf("pcap: libpcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
1744 if (!pcap_read_ppp_pseudoheader(fh,
1745 &phdr->pseudo_header, err, err_info))
1746 return -1; /* Read error */
1748 phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
1751 case WTAP_ENCAP_ERF:
1752 if (check_packet_size &&
1753 packet_size < sizeof(struct erf_phdr) ) {
1755 * Uh-oh, the packet isn't big enough to even
1756 * have a pseudo-header.
1758 *err = WTAP_ERR_BAD_FILE;
1759 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
1764 if (!pcap_read_erf_pseudoheader(fh, phdr, &phdr->pseudo_header,
1766 return -1; /* Read error */
1768 phdr_len = (int)sizeof(struct erf_phdr);
1770 /* check the optional Extension header */
1771 if (!pcap_read_erf_exheader(fh, &phdr->pseudo_header, err, err_info,
1773 return -1; /* Read error */
1777 /* check the optional Multi Channel header */
1778 if (!pcap_read_erf_subheader(fh, &phdr->pseudo_header, err, err_info,
1780 return -1; /* Read error */
1784 if (check_packet_size &&
1785 packet_size < (guint)phdr_len) {
1787 * Uh-oh, the packet isn't big enough for the pseudo-
1790 *err = WTAP_ERR_BAD_FILE;
1791 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small for a pseudo-header with ex- and sub-headers (%d)",
1792 packet_size, phdr_len);
1797 case WTAP_ENCAP_I2C:
1798 if (check_packet_size &&
1799 packet_size < sizeof (struct i2c_file_hdr)) {
1801 * Uh-oh, the packet isn't big enough to even
1802 * have a pseudo-header.
1804 *err = WTAP_ERR_BAD_FILE;
1805 *err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
1809 if (!pcap_read_i2c_pseudoheader(fh, &phdr->pseudo_header,
1811 return -1; /* Read error */
1814 * Don't count the pseudo-header as part of the packet.
1816 phdr_len = (int)sizeof (struct i2c_file_hdr);
1824 pcap_read_post_process(int file_type, int wtap_encap,
1825 struct wtap_pkthdr *phdr, guint8 *pd, gboolean bytes_swapped, int fcs_len)
1827 switch (wtap_encap) {
1829 case WTAP_ENCAP_ATM_PDUS:
1830 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1834 * Guess the traffic type based on the packet
1837 atm_guess_traffic_type(phdr, pd);
1842 * If this is ATM LANE traffic, try to guess what
1843 * type of LANE traffic it is based on the packet
1846 if (phdr->pseudo_header.atm.type == TRAF_LANE)
1847 atm_guess_lane_type(phdr, pd);
1851 case WTAP_ENCAP_ETHERNET:
1852 phdr->pseudo_header.eth.fcs_len = fcs_len;
1855 case WTAP_ENCAP_USB_LINUX:
1857 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, FALSE);
1860 case WTAP_ENCAP_USB_LINUX_MMAPPED:
1862 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, TRUE);
1865 case WTAP_ENCAP_NETANALYZER:
1867 * Not strictly necessary, as the netANALYZER
1868 * dissector calls the "Ethernet with FCS"
1869 * dissector, but we might as well set it.
1871 phdr->pseudo_header.eth.fcs_len = 4;
1874 case WTAP_ENCAP_NFLOG:
1876 pcap_byteswap_nflog_pseudoheader(phdr, pd);
1885 pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
1891 case WTAP_ENCAP_ATM_PDUS:
1892 hdrsize = SUNATM_LEN;
1895 case WTAP_ENCAP_IRDA:
1896 hdrsize = IRDA_SLL_LEN;
1899 case WTAP_ENCAP_MTP2_WITH_PHDR:
1900 hdrsize = MTP2_HDR_LEN;
1903 case WTAP_ENCAP_LINUX_LAPD:
1904 hdrsize = LAPD_SLL_LEN;
1907 case WTAP_ENCAP_SITA:
1908 hdrsize = SITA_HDR_LEN;
1911 case WTAP_ENCAP_ERF:
1912 hdrsize = (int)sizeof (struct erf_phdr);
1913 switch (pseudo_header->erf.phdr.type & 0x7F) {
1915 case ERF_TYPE_MC_HDLC:
1916 case ERF_TYPE_MC_RAW:
1917 case ERF_TYPE_MC_ATM:
1918 case ERF_TYPE_MC_RAW_CHANNEL:
1919 case ERF_TYPE_MC_AAL5:
1920 case ERF_TYPE_MC_AAL2:
1921 case ERF_TYPE_COLOR_MC_HDLC_POS:
1922 hdrsize += (int)sizeof(struct erf_mc_hdr);
1926 case ERF_TYPE_COLOR_ETH:
1927 case ERF_TYPE_DSM_COLOR_ETH:
1928 hdrsize += (int)sizeof(struct erf_eth_hdr);
1936 * Add in the lengths of the extension headers.
1938 if (pseudo_header->erf.phdr.type & 0x80) {
1939 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1940 guint8 erf_exhdr[8];
1944 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
1945 type = erf_exhdr[0];
1948 } while (type & 0x80 && i < max);
1952 case WTAP_ENCAP_I2C:
1953 hdrsize = (int)sizeof (struct i2c_file_hdr);
1956 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1957 hdrsize = (int)sizeof (struct libpcap_bt_phdr);
1960 case WTAP_ENCAP_PPP_WITH_PHDR:
1961 hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
1964 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
1965 hdrsize = (int)sizeof (struct libpcap_bt_monitor_phdr);
1977 pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header,
1980 guint8 atm_hdr[SUNATM_LEN];
1981 guint8 irda_hdr[IRDA_SLL_LEN];
1982 guint8 lapd_hdr[LAPD_SLL_LEN];
1983 guint8 mtp2_hdr[MTP2_HDR_LEN];
1984 guint8 sita_hdr[SITA_HDR_LEN];
1985 guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
1986 struct i2c_file_hdr i2c_hdr;
1987 struct libpcap_bt_phdr bt_hdr;
1988 struct libpcap_bt_monitor_phdr bt_monitor_hdr;
1989 struct libpcap_ppp_phdr ppp_hdr;
1994 case WTAP_ENCAP_ATM_PDUS:
1996 * Write the ATM header.
1998 atm_hdr[SUNATM_FLAGS] =
1999 (pseudo_header->atm.channel == 0) ? 0x80 : 0x00;
2000 switch (pseudo_header->atm.aal) {
2002 case AAL_SIGNALLING:
2004 atm_hdr[SUNATM_FLAGS] |= 0x06;
2008 switch (pseudo_header->atm.type) {
2012 atm_hdr[SUNATM_FLAGS] |= 0x01;
2016 /* RFC 1483 LLC multiplexed traffic */
2017 atm_hdr[SUNATM_FLAGS] |= 0x02;
2022 atm_hdr[SUNATM_FLAGS] |= 0x05;
2027 atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi;
2028 phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci);
2029 if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err))
2031 wdh->bytes_dumped += sizeof(atm_hdr);
2034 case WTAP_ENCAP_IRDA:
2036 * Write the IrDA header.
2038 memset(irda_hdr, 0, sizeof(irda_hdr));
2039 phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET],
2040 pseudo_header->irda.pkttype);
2041 phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017);
2042 if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err))
2044 wdh->bytes_dumped += sizeof(irda_hdr);
2047 case WTAP_ENCAP_MTP2_WITH_PHDR:
2049 * Write the MTP2 header.
2051 memset(&mtp2_hdr, 0, sizeof(mtp2_hdr));
2052 mtp2_hdr[MTP2_SENT_OFFSET] = pseudo_header->mtp2.sent;
2053 mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET] = pseudo_header->mtp2.annex_a_used;
2054 phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET],
2055 pseudo_header->mtp2.link_number);
2056 if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err))
2058 wdh->bytes_dumped += sizeof(mtp2_hdr);
2061 case WTAP_ENCAP_LINUX_LAPD:
2063 * Write the LAPD header.
2065 memset(&lapd_hdr, 0, sizeof(lapd_hdr));
2066 phtons(&lapd_hdr[LAPD_SLL_PKTTYPE_OFFSET],
2067 pseudo_header->lapd.pkttype);
2068 phtons(&lapd_hdr[LAPD_SLL_PROTOCOL_OFFSET], ETH_P_LAPD);
2069 lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] =
2070 pseudo_header->lapd.we_network?0x01:0x00;
2071 if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err))
2073 wdh->bytes_dumped += sizeof(lapd_hdr);
2076 case WTAP_ENCAP_SITA:
2078 * Write the SITA header.
2080 memset(&sita_hdr, 0, sizeof(sita_hdr));
2081 sita_hdr[SITA_FLAGS_OFFSET] = pseudo_header->sita.sita_flags;
2082 sita_hdr[SITA_SIGNALS_OFFSET] = pseudo_header->sita.sita_signals;
2083 sita_hdr[SITA_ERRORS1_OFFSET] = pseudo_header->sita.sita_errors1;
2084 sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.sita_errors2;
2085 sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.sita_proto;
2086 if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err))
2088 wdh->bytes_dumped += sizeof(sita_hdr);
2091 case WTAP_ENCAP_ERF:
2093 * Write the ERF header.
2095 memset(&erf_hdr, 0, sizeof(erf_hdr));
2096 phtolell(&erf_hdr[0], pseudo_header->erf.phdr.ts);
2097 erf_hdr[8] = pseudo_header->erf.phdr.type;
2098 erf_hdr[9] = pseudo_header->erf.phdr.flags;
2099 phtons(&erf_hdr[10], pseudo_header->erf.phdr.rlen);
2100 phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr);
2101 phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen);
2102 size = sizeof(struct erf_phdr);
2104 switch(pseudo_header->erf.phdr.type & 0x7F) {
2105 case ERF_TYPE_MC_HDLC:
2106 case ERF_TYPE_MC_RAW:
2107 case ERF_TYPE_MC_ATM:
2108 case ERF_TYPE_MC_RAW_CHANNEL:
2109 case ERF_TYPE_MC_AAL5:
2110 case ERF_TYPE_MC_AAL2:
2111 case ERF_TYPE_COLOR_MC_HDLC_POS:
2112 phtonl(&erf_hdr[16], pseudo_header->erf.subhdr.mc_hdr);
2113 size += (int)sizeof(struct erf_mc_hdr);
2116 case ERF_TYPE_COLOR_ETH:
2117 case ERF_TYPE_DSM_COLOR_ETH:
2118 phtons(&erf_hdr[16], pseudo_header->erf.subhdr.eth_hdr);
2119 size += (int)sizeof(struct erf_eth_hdr);
2124 if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
2126 wdh->bytes_dumped += size;
2129 * Now write out the extension headers.
2131 if (pseudo_header->erf.phdr.type & 0x80) {
2132 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
2133 guint8 erf_exhdr[8];
2137 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
2138 type = erf_exhdr[0];
2139 if (!wtap_dump_file_write(wdh, erf_exhdr, 8, err))
2141 wdh->bytes_dumped += 8;
2143 } while (type & 0x80 && i < max);
2147 case WTAP_ENCAP_I2C:
2149 * Write the I2C header.
2151 memset(&i2c_hdr, 0, sizeof(i2c_hdr));
2152 i2c_hdr.bus = pseudo_header->i2c.bus |
2153 (pseudo_header->i2c.is_event ? 0x80 : 0x00);
2154 phtonl((guint8 *)&i2c_hdr.flags, pseudo_header->i2c.flags);
2155 if (!wtap_dump_file_write(wdh, &i2c_hdr, sizeof(i2c_hdr), err))
2157 wdh->bytes_dumped += sizeof(i2c_hdr);
2160 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
2161 bt_hdr.direction = GUINT32_TO_BE(pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV);
2162 if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err))
2164 wdh->bytes_dumped += sizeof bt_hdr;
2167 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
2168 bt_monitor_hdr.adapter_id = GUINT16_TO_BE(pseudo_header->btmon.adapter_id);
2169 bt_monitor_hdr.opcode = GUINT16_TO_BE(pseudo_header->btmon.opcode);
2171 if (!wtap_dump_file_write(wdh, &bt_monitor_hdr, sizeof bt_monitor_hdr, err))
2173 wdh->bytes_dumped += sizeof bt_monitor_hdr;
2176 case WTAP_ENCAP_PPP_WITH_PHDR:
2177 ppp_hdr.direction = (pseudo_header->p2p.sent ? LIBPCAP_PPP_PHDR_SENT : LIBPCAP_PPP_PHDR_RECV);
2178 if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err))
2180 wdh->bytes_dumped += sizeof ppp_hdr;