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_LOOP }, /* 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 },
309 /* ITU-T G.7041/Y.1303 Generic Framing Procedure. */
310 { 170, WTAP_ENCAP_GFP_T },
311 { 171, WTAP_ENCAP_GFP_F },
313 /* Registered by Gcom, Inc. */
314 { 172, WTAP_ENCAP_GCOM_TIE1 },
315 { 173, WTAP_ENCAP_GCOM_SERIAL },
317 { 177, WTAP_ENCAP_LINUX_LAPD },
319 /* Ethernet frames prepended with meta-information */
320 { 178, WTAP_ENCAP_JUNIPER_ETHER },
321 /* PPP frames prepended with meta-information */
322 { 179, WTAP_ENCAP_JUNIPER_PPP },
323 /* Frame-Relay frames prepended with meta-information */
324 { 180, WTAP_ENCAP_JUNIPER_FRELAY },
325 /* C-HDLC frames prepended with meta-information */
326 { 181, WTAP_ENCAP_JUNIPER_CHDLC },
327 /* VOIP Frames prepended with meta-information */
328 { 183, WTAP_ENCAP_JUNIPER_VP },
329 /* Virtual Network Frames prepended with meta-information */
330 { 184, WTAP_ENCAP_JUNIPER_VN },
331 /* USB packets from FreeBSD's USB BPF tap */
332 { 186, WTAP_ENCAP_USB_FREEBSD },
333 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
334 { 187, WTAP_ENCAP_BLUETOOTH_H4 },
335 /* IEEE 802.16 MAC Common Part Sublayer */
336 { 188, WTAP_ENCAP_IEEE802_16_MAC_CPS },
337 /* USB packets with Linux-specified header */
338 { 189, WTAP_ENCAP_USB_LINUX },
340 { 190, WTAP_ENCAP_CAN20B },
341 /* Per-Packet Information header */
342 { 192, WTAP_ENCAP_PPI },
343 /* IEEE 802.15.4 Wireless PAN */
344 { 195, WTAP_ENCAP_IEEE802_15_4 },
345 /* SITA File Encapsulation */
346 { 196, WTAP_ENCAP_SITA },
347 /* Endace Record File Encapsulation */
348 { 197, WTAP_ENCAP_ERF },
350 { 199, WTAP_ENCAP_IPMB },
351 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
352 { 201, WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR },
353 /* AX.25 packet with a 1-byte KISS header */
354 { 202, WTAP_ENCAP_AX25_KISS },
356 { 203, WTAP_ENCAP_LAPD },
357 /* PPP with pseudoheader */
358 { 204, WTAP_ENCAP_PPP_WITH_PHDR },
360 { 209, WTAP_ENCAP_I2C },
362 { 210, WTAP_ENCAP_FLEXRAY },
364 { 211, WTAP_ENCAP_MOST },
366 { 212, WTAP_ENCAP_LIN },
367 /* X2E Xoraya serial frame */
368 { 213, WTAP_ENCAP_X2E_SERIAL },
369 /* X2E Xoraya frame */
370 { 214, WTAP_ENCAP_X2E_XORAYA },
371 /* IEEE 802.15.4 Wireless PAN non-ASK PHY */
372 { 215, WTAP_ENCAP_IEEE802_15_4_NONASK_PHY },
373 /* USB packets with padded Linux-specified header */
374 { 220, WTAP_ENCAP_USB_LINUX_MMAPPED },
375 /* Fibre Channel FC-2 frame */
376 { 224, WTAP_ENCAP_FIBRE_CHANNEL_FC2 },
377 /* Fibre Channel FC-2 frame with Delimiter */
378 { 225, WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS },
380 { 226, WTAP_ENCAP_IPNET },
381 /* SocketCAN frame */
382 { 227, WTAP_ENCAP_SOCKETCAN },
384 { 228, WTAP_ENCAP_RAW_IP4 },
386 { 229, WTAP_ENCAP_RAW_IP6 },
387 /* IEEE 802.15.4 Wireless PAN no fcs */
388 { 230, WTAP_ENCAP_IEEE802_15_4_NOFCS },
390 { 231, WTAP_ENCAP_DBUS },
391 /* DVB-CI (Common Interface) */
392 { 235, WTAP_ENCAP_DVBCI },
394 { 236, WTAP_ENCAP_MUX27010 },
395 /* STANAG 5066 - DTS(Data Transfer Sublayer) PDU */
396 { 237, WTAP_ENCAP_STANAG_5066_D_PDU },
398 { 239, WTAP_ENCAP_NFLOG },
399 /* netANALYZER pseudo-header followed by Ethernet with CRC */
400 { 240, WTAP_ENCAP_NETANALYZER },
401 /* netANALYZER pseudo-header in transparent mode */
402 { 241, WTAP_ENCAP_NETANALYZER_TRANSPARENT },
403 /* IP-over-Infiniband, as specified by RFC 4391 section 6 */
404 { 242, WTAP_ENCAP_IP_OVER_IB_PCAP },
405 /* ISO/IEC 13818-1 MPEG2-TS packets */
406 { 243, WTAP_ENCAP_MPEG_2_TS },
408 { 245, WTAP_ENCAP_NFC_LLCP },
410 { 248, WTAP_ENCAP_SCTP},
412 { 249, WTAP_ENCAP_USBPCAP},
414 { 250, WTAP_ENCAP_RTAC_SERIAL},
415 /* Bluetooth Low Energy Link Layer */
416 { 251, WTAP_ENCAP_BLUETOOTH_LE_LL},
417 /* Wireshark Upper PDU export */
418 { 252, WTAP_ENCAP_WIRESHARK_UPPER_PDU},
419 /* Netlink Protocol (nlmon devices) */
420 { 253, WTAP_ENCAP_NETLINK },
421 /* Bluetooth Linux Monitor */
422 { 254, WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR },
423 /* Bluetooth BR/EDR Baseband RF captures */
424 { 255, WTAP_ENCAP_BLUETOOTH_BREDR_BB },
425 /* Bluetooth Low Energy Link Layer RF captures */
426 { 256, WTAP_ENCAP_BLUETOOTH_LE_LL_WITH_PHDR },
429 { 258, WTAP_ENCAP_PKTAP },
431 /* Ethernet Passive Optical Network */
432 { 259, WTAP_ENCAP_EPON },
434 /* IPMI Trace Data Collection */
435 { 260, WTAP_ENCAP_IPMI_TRACE },
437 /* ISO14443 contactless smartcard standards */
438 { 264, WTAP_ENCAP_ISO14443 },
443 * If you need a new encapsulation type for libpcap files, do
444 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
445 * add a new encapsulation type by changing an existing entry;
446 * leave the existing entries alone.
448 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
449 * for a new DLT_ value, and specifying the purpose of the new value.
450 * When you get the new DLT_ value, use that numerical value in
451 * the "linktype_value" field of "pcap_to_wtap_map[]".
455 * The following are entries for libpcap type values that have
456 * different meanings on different OSes. I.e., these are DLT_
457 * values that are different on different OSes, and that have
458 * a separate LINKTYPE_ value assigned to them.
460 * We put these *after* the entries for the LINKTYPE_ values for
461 * those Wiretap encapsulation types, so that, when writing a
462 * pcap or pcap-ng file, Wireshark writes the LINKTYPE_ value,
463 * not the OS's DLT_ value, as the file's link-layer header type
464 * for pcap or the interface's link-layer header type.
468 * 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
469 * seen that define anything other than DLT_ATM_RFC1483 as 11 are
470 * the BSD/OS one, which defines DLT_FR as 11. We handle it as
471 * Frame Relay on BSD/OS and LLC-encapsulated ATM on all other
474 #if defined(__bsdi__) /* BSD/OS */
475 { 11, WTAP_ENCAP_FRELAY },
477 { 11, WTAP_ENCAP_ATM_RFC1483 },
481 * 12 is DLT_RAW on most platforms, but it's DLT_C_HDLC on
482 * BSD/OS, and DLT_LOOP on OpenBSD.
484 * We don't yet handle DLT_C_HDLC, but we can handle DLT_LOOP
485 * (it's just like DLT_NULL, only with the AF_ value in network
486 * rather than host byte order - Wireshark figures out the
487 * byte order from the data, so we don't care what byte order
488 * it's in), so, on OpenBSD, interpret 12 as WTAP_ENCAP_LOOP,
489 * otherwise, if we're not on BSD/OS, interpret it as
492 #if defined(__OpenBSD__)
493 { 12, WTAP_ENCAP_LOOP },
494 #elif defined(__bsdi__) /* BSD/OS */
496 * Put entry for Cisco HDLC here.
497 * XXX - is this just WTAP_ENCAP_CHDLC, i.e. does the frame
498 * start with a 4-byte Cisco HDLC header?
501 { 12, WTAP_ENCAP_RAW_IP },
505 * 13 is DLT_SLIP_BSDOS on FreeBSD and NetBSD, but those OSes
506 * don't actually generate it. I infer that BSD/OS translates
507 * DLT_SLIP from the kernel BPF code to DLT_SLIP_BSDOS in
508 * libpcap, as the BSD/OS link-layer header is different;
509 * however, in BSD/OS, DLT_SLIP_BSDOS is 15.
511 * From this, I infer that there's no point in handling 13
514 * 13 is DLT_ATM_RFC1483 on BSD/OS.
516 * 13 is DLT_ENC in OpenBSD, which is, I suspect, some kind
517 * of decrypted IPsec traffic.
519 * We treat 13 as WTAP_ENCAP_ENC on all systems except those
520 * that define DLT_ATM_RFC1483 as 13 - presumably only
521 * BSD/OS does so - so that, on BSD/OS systems, we still
522 * treate 13 as WTAP_ENCAP_ATM_RFC1483, but, on all other
523 * systems, we can read OpenBSD DLT_ENC captures.
525 #if defined(__bsdi__) /* BSD/OS */
526 { 13, WTAP_ENCAP_ATM_RFC1483 },
528 { 13, WTAP_ENCAP_ENC },
532 * 14 is DLT_PPP_BSDOS on FreeBSD and NetBSD, but those OSes
533 * don't actually generate it. I infer that BSD/OS translates
534 * DLT_PPP from the kernel BPF code to DLT_PPP_BSDOS in
535 * libpcap, as the BSD/OS link-layer header is different;
536 * however, in BSD/OS, DLT_PPP_BSDOS is 16.
538 * From this, I infer that there's no point in handling 14
541 * 14 is DLT_RAW on BSD/OS and OpenBSD.
543 { 14, WTAP_ENCAP_RAW_IP },
548 * DLT_SLIP_BSDOS on BSD/OS;
550 * DLT_HIPPI on NetBSD;
552 * DLT_LANE8023 with Alexey Kuznetzov's patches for
555 * DLT_I4L_RAWIP with the ISDN4Linux patches for libpcap
558 * but we don't currently handle any of those.
564 * DLT_PPP_BSDOS on BSD/OS;
566 * DLT_HDLC on NetBSD (Cisco HDLC);
568 * DLT_CIP with Alexey Kuznetzov's patches for
569 * Linux libpcap - this is WTAP_ENCAP_LINUX_ATM_CLIP;
571 * DLT_I4L_IP with the ISDN4Linux patches for libpcap
574 #if defined(__NetBSD__)
575 { 16, WTAP_ENCAP_CHDLC },
576 #elif !defined(__bsdi__)
578 * If you care about the two different Linux interpretations
579 * of 16, fix it yourself.
581 { 16, WTAP_ENCAP_LINUX_ATM_CLIP },
585 * 17 is DLT_LANE8023 in SuSE 6.3 libpcap; we don't currently
587 * It is also used as the PF (Packet Filter) logging format beginning
588 * with OpenBSD 3.0; we use 17 for PF logs on OpenBSD and don't
591 #if defined(__OpenBSD__)
592 { 17, WTAP_ENCAP_OLD_PFLOG },
596 * 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
597 * DLT_CIP of 16 that the Alexey Kuznetzov patches for
598 * libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
599 * I've not found any libpcap that uses it for any other purpose -
600 * hopefully nobody will do so in the future.
602 { 18, WTAP_ENCAP_LINUX_ATM_CLIP },
605 * 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
606 * recent versions I've seen of the Linux ATM distribution;
607 * I've not yet found any libpcap that uses it for any other
608 * purpose - hopefully nobody will do so in the future.
610 { 19, WTAP_ENCAP_LINUX_ATM_CLIP },
615 * If you need a new encapsulation type for libpcap files, do
616 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
617 * add a new encapsulation type by changing an existing entry;
618 * leave the existing entries alone.
620 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
621 * for a new DLT_ value, and specifying the purpose of the new value.
622 * When you get the new DLT_ value, use that numerical value in
623 * the "linktype_value" field of "pcap_to_wtap_map[]".
626 #define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0])
629 wtap_pcap_encap_to_wtap_encap(int encap)
633 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
634 if (pcap_to_wtap_map[i].linktype_value == encap)
635 return pcap_to_wtap_map[i].wtap_encap_value;
637 return WTAP_ENCAP_UNKNOWN;
641 wtap_wtap_encap_to_pcap_encap(int encap)
647 case WTAP_ENCAP_FDDI:
648 case WTAP_ENCAP_FDDI_BITSWAPPED:
650 * Special-case WTAP_ENCAP_FDDI and
651 * WTAP_ENCAP_FDDI_BITSWAPPED; both of them get mapped
652 * to DLT_FDDI (even though that may mean that the bit
653 * order in the FDDI MAC addresses is wrong; so it goes
654 * - libpcap format doesn't record the byte order,
655 * so that's not fixable).
657 * The pcap_to_wtap_map[] table will only have an
658 * entry for one of the above, which is why we have
659 * to special-case them.
661 return 10; /* that's DLT_FDDI */
663 case WTAP_ENCAP_NETTL_FDDI:
665 * This will discard the nettl information, as that's
666 * in the pseudo-header.
668 * XXX - what about Ethernet and Token Ring?
670 return 10; /* that's DLT_FDDI */
672 case WTAP_ENCAP_FRELAY_WITH_PHDR:
674 * This will discard the pseudo-header information.
678 case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
680 * Map this to DLT_IEEE802_11, for now, even though
681 * that means the radio information will be lost.
682 * We should try to map those values to radiotap
683 * values and write this out as a radiotap file,
689 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
690 if (pcap_to_wtap_map[i].wtap_encap_value == encap)
691 return pcap_to_wtap_map[i].linktype_value;
697 wtap_encap_requires_phdr(int wtap_encap)
699 switch (wtap_encap) {
701 case WTAP_ENCAP_ATM_PDUS:
702 case WTAP_ENCAP_IRDA:
703 case WTAP_ENCAP_MTP2_WITH_PHDR:
704 case WTAP_ENCAP_LINUX_LAPD:
705 case WTAP_ENCAP_SITA:
706 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
707 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
708 case WTAP_ENCAP_NFC_LLCP:
709 case WTAP_ENCAP_PPP_WITH_PHDR:
719 * Various pseudo-headers that appear at the beginning of packet data.
721 * We represent them as sets of offsets, as they might not be aligned on
722 * an appropriate structure boundary in the buffer, and as that makes them
723 * independent of the way the compiler might align fields.
727 * The link-layer header on SunATM packets.
729 #define SUNATM_FLAGS 0 /* destination and traffic type - 1 byte */
730 #define SUNATM_VPI 1 /* VPI - 1 byte */
731 #define SUNATM_VCI 2 /* VCI - 2 bytes */
732 #define SUNATM_LEN 4 /* length of the header */
735 * The link-layer header on Nokia IPSO ATM packets.
737 #define NOKIAATM_FLAGS 0 /* destination - 1 byte */
738 #define NOKIAATM_VPI 1 /* VPI - 1 byte */
739 #define NOKIAATM_VCI 2 /* VCI - 2 bytes */
740 #define NOKIAATM_LEN 4 /* length of the header */
743 * The link-layer header on Nokia IPSO packets.
745 #define NOKIA_LEN 4 /* length of the header */
748 * The fake link-layer header of Linux cooked packets.
750 #define LINUX_SLL_PROTOCOL_OFFSET 14 /* protocol */
751 #define LINUX_SLL_LEN 16 /* length of the header */
754 * The protocols we have to check for.
756 #define LINUX_SLL_P_CAN 0x000C /* Controller Area Network */
757 #define LINUX_SLL_P_CANFD 0x000D /* Controller Area Network flexible data rate */
760 * The fake link-layer header of IrDA packets as introduced by Jean Tourrilhes
763 #define IRDA_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
764 /* 12 unused bytes */
765 #define IRDA_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
766 #define IRDA_SLL_LEN 16 /* length of the header */
769 * A header containing additional MTP information.
771 #define MTP2_SENT_OFFSET 0 /* 1 byte */
772 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
773 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
774 #define MTP2_HDR_LEN 4 /* length of the header */
777 * A header containing additional SITA WAN information.
779 #define SITA_FLAGS_OFFSET 0 /* 1 byte */
780 #define SITA_SIGNALS_OFFSET 1 /* 1 byte */
781 #define SITA_ERRORS1_OFFSET 2 /* 1 byte */
782 #define SITA_ERRORS2_OFFSET 3 /* 1 byte */
783 #define SITA_PROTO_OFFSET 4 /* 1 byte */
784 #define SITA_HDR_LEN 5 /* length of the header */
787 * The fake link-layer header of LAPD packets.
790 #define ETH_P_LAPD 0x0030
793 #define LAPD_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
794 #define LAPD_SLL_HATYPE_OFFSET 2 /* hardware address type - 2 bytes */
795 #define LAPD_SLL_HALEN_OFFSET 4 /* hardware address length - 2 bytes */
796 #define LAPD_SLL_ADDR_OFFSET 6 /* address - 8 bytes */
797 #define LAPD_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
798 #define LAPD_SLL_LEN 16 /* length of the header */
801 * The NFC LLCP per-packet header.
803 #define LLCP_ADAPTER_OFFSET 0
804 #define LLCP_FLAGS_OFFSET 1
805 #define LLCP_HEADER_LEN 2
808 * I2C link-layer on-disk format
810 struct i2c_file_hdr {
816 pcap_read_sunatm_pseudoheader(FILE_T fh,
817 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
819 guint8 atm_phdr[SUNATM_LEN];
823 if (!wtap_read_bytes(fh, atm_phdr, SUNATM_LEN, err, err_info))
826 vpi = atm_phdr[SUNATM_VPI];
827 vci = pntoh16(&atm_phdr[SUNATM_VCI]);
829 switch (atm_phdr[SUNATM_FLAGS] & 0x0F) {
831 case 0x01: /* LANE */
832 pseudo_header->atm.aal = AAL_5;
833 pseudo_header->atm.type = TRAF_LANE;
836 case 0x02: /* RFC 1483 LLC multiplexed traffic */
837 pseudo_header->atm.aal = AAL_5;
838 pseudo_header->atm.type = TRAF_LLCMX;
841 case 0x05: /* ILMI */
842 pseudo_header->atm.aal = AAL_5;
843 pseudo_header->atm.type = TRAF_ILMI;
846 case 0x06: /* Q.2931 */
847 pseudo_header->atm.aal = AAL_SIGNALLING;
848 pseudo_header->atm.type = TRAF_UNKNOWN;
851 case 0x03: /* MARS (RFC 2022) */
852 pseudo_header->atm.aal = AAL_5;
853 pseudo_header->atm.type = TRAF_UNKNOWN;
856 case 0x04: /* IFMP (Ipsilon Flow Management Protocol; see RFC 1954) */
857 pseudo_header->atm.aal = AAL_5;
858 pseudo_header->atm.type = TRAF_UNKNOWN; /* XXX - TRAF_IPSILON? */
863 * Assume it's AAL5, unless it's VPI 0 and VCI 5, in which
864 * case assume it's AAL_SIGNALLING; we know nothing more
867 * XXX - is this necessary? Or are we guaranteed that
868 * all signalling traffic has a type of 0x06?
870 * XXX - is this guaranteed to be AAL5? Or, if the type is
871 * 0x00 ("raw"), might it be non-AAL5 traffic?
873 if (vpi == 0 && vci == 5)
874 pseudo_header->atm.aal = AAL_SIGNALLING;
876 pseudo_header->atm.aal = AAL_5;
877 pseudo_header->atm.type = TRAF_UNKNOWN;
880 pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
882 pseudo_header->atm.vpi = vpi;
883 pseudo_header->atm.vci = vci;
884 pseudo_header->atm.channel = (atm_phdr[SUNATM_FLAGS] & 0x80) ? 0 : 1;
886 /* We don't have this information */
887 pseudo_header->atm.flags = 0;
888 pseudo_header->atm.cells = 0;
889 pseudo_header->atm.aal5t_u2u = 0;
890 pseudo_header->atm.aal5t_len = 0;
891 pseudo_header->atm.aal5t_chksum = 0;
897 pcap_read_nokiaatm_pseudoheader(FILE_T fh,
898 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
900 guint8 atm_phdr[NOKIAATM_LEN];
904 if (!wtap_read_bytes(fh, atm_phdr, NOKIAATM_LEN, err, err_info))
907 vpi = atm_phdr[NOKIAATM_VPI];
908 vci = pntoh16(&atm_phdr[NOKIAATM_VCI]);
910 pseudo_header->atm.vpi = vpi;
911 pseudo_header->atm.vci = vci;
912 pseudo_header->atm.channel = (atm_phdr[NOKIAATM_FLAGS] & 0x80) ? 0 : 1;
914 /* We don't have this information */
915 pseudo_header->atm.flags = 0;
916 pseudo_header->atm.cells = 0;
917 pseudo_header->atm.aal5t_u2u = 0;
918 pseudo_header->atm.aal5t_len = 0;
919 pseudo_header->atm.aal5t_chksum = 0;
925 pcap_read_nokia_pseudoheader(FILE_T fh,
926 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
928 guint8 phdr[NOKIA_LEN];
931 /* backtrack to read the 4 mysterious bytes that aren't considered
932 * part of the packet size
934 if (file_seek(fh, -NOKIA_LEN, SEEK_CUR, err) == -1)
936 *err = file_error(fh, err_info);
938 *err = WTAP_ERR_SHORT_READ;
942 if (!wtap_read_bytes(fh, phdr, NOKIA_LEN, err, err_info))
945 memcpy(pseudo_header->nokia.stuff, phdr, NOKIA_LEN);
951 pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
952 int *err, gchar **err_info)
954 guint8 irda_phdr[IRDA_SLL_LEN];
956 if (!wtap_read_bytes(fh, irda_phdr, IRDA_SLL_LEN, err, err_info))
959 if (pntoh16(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
960 *err = WTAP_ERR_BAD_FILE;
961 if (err_info != NULL)
962 *err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
966 pseudo_header->irda.pkttype = pntoh16(&irda_phdr[IRDA_SLL_PKTTYPE_OFFSET]);
972 pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
974 guint8 mtp2_hdr[MTP2_HDR_LEN];
976 if (!wtap_read_bytes(fh, mtp2_hdr, MTP2_HDR_LEN, err, err_info))
979 pseudo_header->mtp2.sent = mtp2_hdr[MTP2_SENT_OFFSET];
980 pseudo_header->mtp2.annex_a_used = mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET];
981 pseudo_header->mtp2.link_number = pntoh16(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET]);
987 pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
988 int *err, gchar **err_info)
990 guint8 lapd_phdr[LAPD_SLL_LEN];
992 if (!wtap_read_bytes(fh, lapd_phdr, LAPD_SLL_LEN, err, err_info))
995 if (pntoh16(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
996 *err = WTAP_ERR_BAD_FILE;
997 if (err_info != NULL)
998 *err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
1002 pseudo_header->lapd.pkttype = pntoh16(&lapd_phdr[LAPD_SLL_PKTTYPE_OFFSET]);
1003 pseudo_header->lapd.we_network = !!lapd_phdr[LAPD_SLL_ADDR_OFFSET+0];
1009 pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1011 guint8 sita_phdr[SITA_HDR_LEN];
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;
1152 * Offset of the *end* of a field within a particular structure.
1154 #define END_OFFSETOF(basep, fieldp) \
1155 (((char *)(void *)(fieldp)) - ((char *)(void *)(basep)) + \
1159 * Is that offset within the bounds of the packet?
1161 #define WITHIN_PACKET(basep, fieldp) \
1162 (packet_size >= END_OFFSETOF((basep), (fieldp)))
1164 #define CHECK_AND_SWAP16(fieldp) \
1166 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1168 PBSWAP16((guint8 *)fieldp); \
1171 #define CHECK_AND_SWAP32(fieldp) \
1173 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1175 PBSWAP32((guint8 *)fieldp); \
1178 #define CHECK_AND_SWAP64(fieldp) \
1180 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1182 PBSWAP64((guint8 *)fieldp); \
1185 struct can_socketcan_hdr {
1186 guint32 can_id; /* CAN ID and flags */
1187 guint8 payload_length; /* Frame payload length */
1194 pcap_byteswap_linux_sll_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd)
1198 struct can_socketcan_hdr *can_socketcan_phdr;
1201 * Minimum of captured and actual length (just in case the
1202 * actual length < the captured length, which Should Never
1205 packet_size = phdr->caplen;
1206 if (packet_size > phdr->len)
1207 packet_size = phdr->len;
1209 if (packet_size < LINUX_SLL_LEN) {
1210 /* Not enough data to have the protocol */
1214 protocol = pntoh16(&pd[LINUX_SLL_PROTOCOL_OFFSET]);
1215 if (protocol != LINUX_SLL_P_CAN && protocol != LINUX_SLL_P_CANFD) {
1216 /* Not a CAN packet; nothing to fix */
1221 * Greasy hack, but we never directly dereference any of
1222 * the fields in *can_socketcan_phdr, we just get offsets
1223 * of and addresses of its members and byte-swap it with a
1224 * byte-at-a-time macro, so it's alignment-safe.
1226 can_socketcan_phdr = (struct can_socketcan_hdr *)(void *)(pd + LINUX_SLL_LEN);
1228 if (packet_size < LINUX_SLL_LEN + sizeof(can_socketcan_phdr->can_id)) {
1229 /* Not enough data to have the full CAN ID */
1233 PBSWAP32((guint8 *)&can_socketcan_phdr->can_id);
1237 pcap_byteswap_linux_usb_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd,
1238 gboolean header_len_64_bytes)
1241 struct linux_usb_phdr *usb_phdr;
1242 struct linux_usb_isodesc *pisodesc;
1243 gint32 iso_numdesc, i;
1246 * Minimum of captured and actual length (just in case the
1247 * actual length < the captured length, which Should Never
1250 packet_size = phdr->caplen;
1251 if (packet_size > phdr->len)
1252 packet_size = phdr->len;
1255 * Greasy hack, but we never directly dereference any of
1256 * the fields in *usb_phdr, we just get offsets of and
1257 * addresses of its members and byte-swap it with a
1258 * byte-at-a-time macro, so it's alignment-safe.
1260 usb_phdr = (struct linux_usb_phdr *)(void *)pd;
1262 CHECK_AND_SWAP64(&usb_phdr->id);
1263 CHECK_AND_SWAP16(&usb_phdr->bus_id);
1264 CHECK_AND_SWAP64(&usb_phdr->ts_sec);
1265 CHECK_AND_SWAP32(&usb_phdr->ts_usec);
1266 CHECK_AND_SWAP32(&usb_phdr->status);
1267 CHECK_AND_SWAP32(&usb_phdr->urb_len);
1268 CHECK_AND_SWAP32(&usb_phdr->data_len);
1270 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1271 CHECK_AND_SWAP32(&usb_phdr->s.iso.error_count);
1272 CHECK_AND_SWAP32(&usb_phdr->s.iso.numdesc);
1275 if (header_len_64_bytes) {
1277 * This is either the "version 1" header, with
1278 * 16 bytes of additional fields at the end, or
1279 * a "version 0" header from a memory-mapped
1280 * capture, with 16 bytes of zeroed-out padding
1281 * at the end. Byte swap them as if this were
1282 * a "version 1" header.
1284 * Yes, the first argument to END_OFFSETOF() should
1285 * be usb_phdr, not usb_phdr_ext; we want the offset of
1286 * the additional fields from the beginning of
1289 CHECK_AND_SWAP32(&usb_phdr->interval);
1290 CHECK_AND_SWAP32(&usb_phdr->start_frame);
1291 CHECK_AND_SWAP32(&usb_phdr->xfer_flags);
1292 CHECK_AND_SWAP32(&usb_phdr->ndesc);
1295 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1296 /* swap the values in struct linux_usb_isodesc */
1299 * See previous "Greasy hack" comment.
1301 if (header_len_64_bytes) {
1302 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 64);
1304 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 48);
1306 iso_numdesc = usb_phdr->s.iso.numdesc;
1307 for (i = 0; i < iso_numdesc; i++) {
1308 CHECK_AND_SWAP32(&pisodesc->iso_status);
1309 CHECK_AND_SWAP32(&pisodesc->iso_off);
1310 CHECK_AND_SWAP32(&pisodesc->iso_len);
1311 CHECK_AND_SWAP32(&pisodesc->_pad);
1319 guint8 nflog_family; /* address family */
1320 guint8 nflog_version; /* version */
1321 guint16 nflog_rid; /* resource ID */
1325 guint16 tlv_length; /* tlv length */
1326 guint16 tlv_type; /* tlv type */
1327 /* value follows this */
1331 pcap_byteswap_nflog_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd)
1335 struct nflog_hdr *nfhdr;
1336 struct nflog_tlv *tlv;
1340 * Minimum of captured and actual length (just in case the
1341 * actual length < the captured length, which Should Never
1344 packet_size = phdr->caplen;
1345 if (packet_size > phdr->len)
1346 packet_size = phdr->len;
1348 if (packet_size < sizeof(struct nflog_hdr)) {
1349 /* Not enough data to have any TLVs. */
1354 nfhdr = (struct nflog_hdr *)pd;
1355 if (nfhdr->nflog_version != 0) {
1356 /* Unknown NFLOG version */
1360 packet_size -= (guint)sizeof(struct nflog_hdr);
1361 p += sizeof(struct nflog_hdr);
1363 while (packet_size >= sizeof(struct nflog_tlv)) {
1364 tlv = (struct nflog_tlv *) p;
1366 /* Swap the type and length. */
1367 PBSWAP16((guint8 *)&tlv->tlv_type);
1368 PBSWAP16((guint8 *)&tlv->tlv_length);
1370 /* Get the length of the TLV. */
1371 size = tlv->tlv_length;
1373 size += 4 - size % 4;
1375 /* Is the TLV's length less than the minimum? */
1376 if (size < sizeof(struct nflog_tlv)) {
1377 /* Yes. Give up now. */
1381 /* Do we have enough data for the full TLV? */
1382 if (packet_size < size) {
1387 /* Skip over the TLV. */
1388 packet_size -= size;
1394 * Pseudo-header at the beginning of DLT_BLUETOOTH_HCI_H4_WITH_PHDR frames.
1395 * Values in network byte order.
1397 struct libpcap_bt_phdr {
1398 guint32 direction; /* Bit 0 hold the frame direction. */
1401 #define LIBPCAP_BT_PHDR_SENT 0
1402 #define LIBPCAP_BT_PHDR_RECV 1
1405 pcap_read_bt_pseudoheader(FILE_T fh,
1406 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1408 struct libpcap_bt_phdr phdr;
1410 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_phdr),
1413 pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
1418 * Pseudo-header at the beginning of DLT_BLUETOOTH_LINUX_MONITOR frames.
1419 * Values in network byte order.
1421 struct libpcap_bt_monitor_phdr {
1427 pcap_read_bt_monitor_pseudoheader(FILE_T fh,
1428 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1430 struct libpcap_bt_monitor_phdr phdr;
1432 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_monitor_phdr),
1436 pseudo_header->btmon.adapter_id = g_ntohs(phdr.adapter_id);
1437 pseudo_header->btmon.opcode = g_ntohs(phdr.opcode);
1442 pcap_read_llcp_pseudoheader(FILE_T fh,
1443 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1445 guint8 phdr[LLCP_HEADER_LEN];
1447 if (!wtap_read_bytes(fh, phdr, LLCP_HEADER_LEN, err, err_info))
1449 pseudo_header->llcp.adapter = phdr[LLCP_ADAPTER_OFFSET];
1450 pseudo_header->llcp.flags = phdr[LLCP_FLAGS_OFFSET];
1455 * Pseudo-header at the beginning of DLT_PPP_WITH_DIR frames.
1457 struct libpcap_ppp_phdr {
1461 #define LIBPCAP_PPP_PHDR_RECV 0
1462 #define LIBPCAP_PPP_PHDR_SENT 1
1465 pcap_read_ppp_pseudoheader(FILE_T fh,
1466 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1468 struct libpcap_ppp_phdr phdr;
1470 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_ppp_phdr),
1473 pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
1478 pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr,
1479 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1481 guint8 erf_hdr[sizeof(struct erf_phdr)];
1483 if (!wtap_read_bytes(fh, erf_hdr, sizeof(struct erf_phdr), err, err_info))
1485 pseudo_header->erf.phdr.ts = pletoh64(&erf_hdr[0]); /* timestamp */
1486 pseudo_header->erf.phdr.type = erf_hdr[8];
1487 pseudo_header->erf.phdr.flags = erf_hdr[9];
1488 pseudo_header->erf.phdr.rlen = pntoh16(&erf_hdr[10]);
1489 pseudo_header->erf.phdr.lctr = pntoh16(&erf_hdr[12]);
1490 pseudo_header->erf.phdr.wlen = pntoh16(&erf_hdr[14]);
1492 /* The high 32 bits of the timestamp contain the integer number of seconds
1493 * while the lower 32 bits contain the binary fraction of the second.
1494 * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */
1496 guint64 ts = pseudo_header->erf.phdr.ts;
1497 whdr->ts.secs = (guint32) (ts >> 32);
1498 ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000);
1499 ts += (ts & 0x80000000) << 1; /* rounding */
1500 whdr->ts.nsecs = ((guint32) (ts >> 32));
1501 if ( whdr->ts.nsecs >= 1000000000) {
1502 whdr->ts.nsecs -= 1000000000;
1510 * If the type of record given in the pseudo header indicate the presence of an extension
1511 * header then, read all the extension headers
1514 pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1515 int *err, gchar **err_info, guint * psize)
1517 guint8 erf_exhdr[8];
1518 guint64 erf_exhdr_sw;
1519 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1522 if (pseudo_header->erf.phdr.type & 0x80){
1524 if (!wtap_read_bytes(fh, erf_exhdr, 8, err, err_info))
1526 type = erf_exhdr[0];
1527 erf_exhdr_sw = pntoh64(erf_exhdr);
1529 memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw));
1532 } while (type & 0x80);
1538 * If the type of record given in the pseudo header indicate the precense of a subheader
1539 * then, read this optional subheader
1542 pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1543 int *err, gchar **err_info, guint * psize)
1545 guint8 erf_subhdr[sizeof(union erf_subhdr)];
1548 switch(pseudo_header->erf.phdr.type & 0x7F) {
1549 case ERF_TYPE_MC_HDLC:
1550 case ERF_TYPE_MC_RAW:
1551 case ERF_TYPE_MC_ATM:
1552 case ERF_TYPE_MC_RAW_CHANNEL:
1553 case ERF_TYPE_MC_AAL5:
1554 case ERF_TYPE_MC_AAL2:
1555 case ERF_TYPE_COLOR_MC_HDLC_POS:
1556 /* Extract the Multi Channel header to include it in the pseudo header part */
1557 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_mc_header_t), err, err_info))
1559 pseudo_header->erf.subhdr.mc_hdr = pntoh32(&erf_subhdr[0]);
1560 *psize = sizeof(erf_mc_header_t);
1563 /* Extract the AAL2 header to include it in the pseudo header part */
1564 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_aal2_header_t), err, err_info))
1566 pseudo_header->erf.subhdr.aal2_hdr = pntoh32(&erf_subhdr[0]);
1567 *psize = sizeof(erf_aal2_header_t);
1570 case ERF_TYPE_COLOR_ETH:
1571 case ERF_TYPE_DSM_COLOR_ETH:
1572 case ERF_TYPE_COLOR_HASH_ETH:
1573 /* Extract the Ethernet additional header to include it in the pseudo header part */
1574 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_eth_header_t), err, err_info))
1576 memcpy(&pseudo_header->erf.subhdr.eth_hdr, erf_subhdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
1577 *psize = sizeof(erf_eth_header_t);
1580 /* No optional pseudo header for this ERF type */
1587 pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1589 struct i2c_file_hdr i2c_hdr;
1591 if (!wtap_read_bytes(fh, &i2c_hdr, sizeof (i2c_hdr), err, err_info))
1594 pseudo_header->i2c.is_event = i2c_hdr.bus & 0x80 ? 1 : 0;
1595 pseudo_header->i2c.bus = i2c_hdr.bus & 0x7f;
1596 pseudo_header->i2c.flags = pntoh32(&i2c_hdr.flags);
1602 pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
1603 guint packet_size, gboolean check_packet_size,
1604 struct wtap_pkthdr *phdr, int *err, gchar **err_info)
1609 switch (wtap_encap) {
1611 case WTAP_ENCAP_ATM_PDUS:
1612 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1616 if (check_packet_size && packet_size < NOKIAATM_LEN) {
1618 * Uh-oh, the packet isn't big enough to even
1619 * have a pseudo-header.
1621 *err = WTAP_ERR_BAD_FILE;
1622 *err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1626 if (!pcap_read_nokiaatm_pseudoheader(fh,
1627 &phdr->pseudo_header, err, err_info))
1628 return -1; /* Read error */
1630 phdr_len = NOKIAATM_LEN;
1635 if (check_packet_size && packet_size < SUNATM_LEN) {
1637 * Uh-oh, the packet isn't big enough to even
1638 * have a pseudo-header.
1640 *err = WTAP_ERR_BAD_FILE;
1641 *err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1645 if (!pcap_read_sunatm_pseudoheader(fh,
1646 &phdr->pseudo_header, err, err_info))
1647 return -1; /* Read error */
1649 phdr_len = SUNATM_LEN;
1653 case WTAP_ENCAP_ETHERNET:
1654 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1656 * Nokia IPSO. Psuedo header has already been read, but it's not considered
1657 * part of the packet size, so reread it to store the data for later (when saving)
1659 if (!pcap_read_nokia_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1660 return -1; /* Read error */
1664 * We don't know whether there's an FCS in this frame or not.
1666 phdr->pseudo_header.eth.fcs_len = -1;
1669 case WTAP_ENCAP_IEEE_802_11:
1670 case WTAP_ENCAP_IEEE_802_11_PRISM:
1671 case WTAP_ENCAP_IEEE_802_11_RADIOTAP:
1672 case WTAP_ENCAP_IEEE_802_11_AVS:
1674 * We don't know whether there's an FCS in this frame or not,
1675 * at least in pcap files. For radiotap, that's indicated in
1676 * the radiotap header.
1678 * XXX - in pcap-ng, there *could* be a packet option
1679 * indicating the FCS length.
1681 memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11));
1682 phdr->pseudo_header.ieee_802_11.fcs_len = -1;
1683 phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
1684 phdr->pseudo_header.ieee_802_11.datapad = FALSE;
1687 case WTAP_ENCAP_IRDA:
1688 if (check_packet_size && packet_size < IRDA_SLL_LEN) {
1690 * Uh-oh, the packet isn't big enough to even
1691 * have a pseudo-header.
1693 *err = WTAP_ERR_BAD_FILE;
1694 *err_info = g_strdup_printf("pcap: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
1698 if (!pcap_read_irda_pseudoheader(fh, &phdr->pseudo_header,
1700 return -1; /* Read error */
1702 phdr_len = IRDA_SLL_LEN;
1705 case WTAP_ENCAP_MTP2_WITH_PHDR:
1706 if (check_packet_size && packet_size < MTP2_HDR_LEN) {
1708 * Uh-oh, the packet isn't big enough to even
1709 * have a pseudo-header.
1711 *err = WTAP_ERR_BAD_FILE;
1712 *err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
1716 if (!pcap_read_mtp2_pseudoheader(fh, &phdr->pseudo_header,
1718 return -1; /* Read error */
1720 phdr_len = MTP2_HDR_LEN;
1723 case WTAP_ENCAP_LINUX_LAPD:
1724 if (check_packet_size && packet_size < LAPD_SLL_LEN) {
1726 * Uh-oh, the packet isn't big enough to even
1727 * have a pseudo-header.
1729 *err = WTAP_ERR_BAD_FILE;
1730 *err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
1734 if (!pcap_read_lapd_pseudoheader(fh, &phdr->pseudo_header,
1736 return -1; /* Read error */
1738 phdr_len = LAPD_SLL_LEN;
1741 case WTAP_ENCAP_SITA:
1742 if (check_packet_size && packet_size < SITA_HDR_LEN) {
1744 * Uh-oh, the packet isn't big enough to even
1745 * have a pseudo-header.
1747 *err = WTAP_ERR_BAD_FILE;
1748 *err_info = g_strdup_printf("pcap: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
1752 if (!pcap_read_sita_pseudoheader(fh, &phdr->pseudo_header,
1754 return -1; /* Read error */
1756 phdr_len = SITA_HDR_LEN;
1759 case WTAP_ENCAP_BLUETOOTH_H4:
1760 /* We don't have pseudoheader, so just pretend we received everything. */
1761 phdr->pseudo_header.p2p.sent = FALSE;
1764 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1765 if (check_packet_size &&
1766 packet_size < sizeof (struct libpcap_bt_phdr)) {
1768 * Uh-oh, the packet isn't big enough to even
1769 * have a pseudo-header.
1771 *err = WTAP_ERR_BAD_FILE;
1772 *err_info = g_strdup_printf("pcap: libpcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
1776 if (!pcap_read_bt_pseudoheader(fh,
1777 &phdr->pseudo_header, err, err_info))
1778 return -1; /* Read error */
1780 phdr_len = (int)sizeof (struct libpcap_bt_phdr);
1783 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
1784 if (check_packet_size &&
1785 packet_size < sizeof (struct libpcap_bt_monitor_phdr)) {
1787 * Uh-oh, the packet isn't big enough to even
1788 * have a pseudo-header.
1790 *err = WTAP_ERR_BAD_FILE;
1791 *err_info = g_strdup_printf("pcap: libpcap bluetooth monitor file has a %u-byte packet, too small to have even a pseudo-header",
1795 if (!pcap_read_bt_monitor_pseudoheader(fh,
1796 &phdr->pseudo_header, err, err_info))
1797 return -1; /* Read error */
1799 phdr_len = (int)sizeof (struct libpcap_bt_monitor_phdr);
1802 case WTAP_ENCAP_NFC_LLCP:
1803 if (check_packet_size && packet_size < LLCP_HEADER_LEN) {
1804 *err = WTAP_ERR_BAD_FILE;
1805 *err_info = g_strdup("pcap: libpcap llcp file too short");
1808 if (!pcap_read_llcp_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1809 return -1; /* Read error */
1810 phdr_len = LLCP_HEADER_LEN;
1813 case WTAP_ENCAP_PPP_WITH_PHDR:
1814 if (check_packet_size &&
1815 packet_size < sizeof (struct libpcap_ppp_phdr)) {
1817 * Uh-oh, the packet isn't big enough to even
1818 * have a pseudo-header.
1820 *err = WTAP_ERR_BAD_FILE;
1821 *err_info = g_strdup_printf("pcap: libpcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
1825 if (!pcap_read_ppp_pseudoheader(fh,
1826 &phdr->pseudo_header, err, err_info))
1827 return -1; /* Read error */
1829 phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
1832 case WTAP_ENCAP_ERF:
1833 if (check_packet_size &&
1834 packet_size < sizeof(struct erf_phdr) ) {
1836 * Uh-oh, the packet isn't big enough to even
1837 * have a pseudo-header.
1839 *err = WTAP_ERR_BAD_FILE;
1840 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
1845 if (!pcap_read_erf_pseudoheader(fh, phdr, &phdr->pseudo_header,
1847 return -1; /* Read error */
1849 phdr_len = (int)sizeof(struct erf_phdr);
1851 /* check the optional Extension header */
1852 if (!pcap_read_erf_exheader(fh, &phdr->pseudo_header, err, err_info,
1854 return -1; /* Read error */
1858 /* check the optional Multi Channel header */
1859 if (!pcap_read_erf_subheader(fh, &phdr->pseudo_header, err, err_info,
1861 return -1; /* Read error */
1865 if (check_packet_size &&
1866 packet_size < (guint)phdr_len) {
1868 * Uh-oh, the packet isn't big enough for the pseudo-
1871 *err = WTAP_ERR_BAD_FILE;
1872 *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)",
1873 packet_size, phdr_len);
1878 case WTAP_ENCAP_I2C:
1879 if (check_packet_size &&
1880 packet_size < sizeof (struct i2c_file_hdr)) {
1882 * Uh-oh, the packet isn't big enough to even
1883 * have a pseudo-header.
1885 *err = WTAP_ERR_BAD_FILE;
1886 *err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
1890 if (!pcap_read_i2c_pseudoheader(fh, &phdr->pseudo_header,
1892 return -1; /* Read error */
1895 * Don't count the pseudo-header as part of the packet.
1897 phdr_len = (int)sizeof (struct i2c_file_hdr);
1905 pcap_read_post_process(int file_type, int wtap_encap,
1906 struct wtap_pkthdr *phdr, guint8 *pd, gboolean bytes_swapped, int fcs_len)
1908 switch (wtap_encap) {
1910 case WTAP_ENCAP_ATM_PDUS:
1911 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1915 * Guess the traffic type based on the packet
1918 atm_guess_traffic_type(phdr, pd);
1923 * If this is ATM LANE traffic, try to guess what
1924 * type of LANE traffic it is based on the packet
1927 if (phdr->pseudo_header.atm.type == TRAF_LANE)
1928 atm_guess_lane_type(phdr, pd);
1932 case WTAP_ENCAP_ETHERNET:
1933 phdr->pseudo_header.eth.fcs_len = fcs_len;
1936 case WTAP_ENCAP_SLL:
1938 pcap_byteswap_linux_sll_pseudoheader(phdr, pd);
1941 case WTAP_ENCAP_USB_LINUX:
1943 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, FALSE);
1946 case WTAP_ENCAP_USB_LINUX_MMAPPED:
1948 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, TRUE);
1951 case WTAP_ENCAP_NETANALYZER:
1953 * Not strictly necessary, as the netANALYZER
1954 * dissector calls the "Ethernet with FCS"
1955 * dissector, but we might as well set it.
1957 phdr->pseudo_header.eth.fcs_len = 4;
1960 case WTAP_ENCAP_NFLOG:
1962 pcap_byteswap_nflog_pseudoheader(phdr, pd);
1965 case WTAP_ENCAP_ERF:
1967 * Update packet size to account for ERF padding and snapping.
1968 * Captured length is minimum of wlen and previously calculated
1969 * caplen (which would have included padding but not phdr).
1971 phdr->len = phdr->pseudo_header.erf.phdr.wlen;
1972 phdr->caplen = MIN(phdr->len, phdr->caplen);
1981 pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
1987 case WTAP_ENCAP_ATM_PDUS:
1988 hdrsize = SUNATM_LEN;
1991 case WTAP_ENCAP_IRDA:
1992 hdrsize = IRDA_SLL_LEN;
1995 case WTAP_ENCAP_MTP2_WITH_PHDR:
1996 hdrsize = MTP2_HDR_LEN;
1999 case WTAP_ENCAP_LINUX_LAPD:
2000 hdrsize = LAPD_SLL_LEN;
2003 case WTAP_ENCAP_SITA:
2004 hdrsize = SITA_HDR_LEN;
2007 case WTAP_ENCAP_ERF:
2008 hdrsize = (int)sizeof (struct erf_phdr);
2009 switch (pseudo_header->erf.phdr.type & 0x7F) {
2011 case ERF_TYPE_MC_HDLC:
2012 case ERF_TYPE_MC_RAW:
2013 case ERF_TYPE_MC_ATM:
2014 case ERF_TYPE_MC_RAW_CHANNEL:
2015 case ERF_TYPE_MC_AAL5:
2016 case ERF_TYPE_MC_AAL2:
2017 case ERF_TYPE_COLOR_MC_HDLC_POS:
2018 hdrsize += (int)sizeof(struct erf_mc_hdr);
2021 hdrsize += (int)sizeof(struct erf_aal2_hdr);
2025 case ERF_TYPE_COLOR_ETH:
2026 case ERF_TYPE_DSM_COLOR_ETH:
2027 case ERF_TYPE_COLOR_HASH_ETH:
2028 hdrsize += (int)sizeof(struct erf_eth_hdr);
2036 * Add in the lengths of the extension headers.
2038 if (pseudo_header->erf.phdr.type & 0x80) {
2039 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
2040 guint8 erf_exhdr[8];
2044 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
2045 type = erf_exhdr[0];
2048 } while (type & 0x80 && i < max);
2052 case WTAP_ENCAP_I2C:
2053 hdrsize = (int)sizeof (struct i2c_file_hdr);
2056 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
2057 hdrsize = (int)sizeof (struct libpcap_bt_phdr);
2060 case WTAP_ENCAP_PPP_WITH_PHDR:
2061 hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
2064 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
2065 hdrsize = (int)sizeof (struct libpcap_bt_monitor_phdr);
2077 pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header,
2080 guint8 atm_hdr[SUNATM_LEN];
2081 guint8 irda_hdr[IRDA_SLL_LEN];
2082 guint8 lapd_hdr[LAPD_SLL_LEN];
2083 guint8 mtp2_hdr[MTP2_HDR_LEN];
2084 guint8 sita_hdr[SITA_HDR_LEN];
2085 guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
2086 guint8 erf_subhdr[sizeof(union erf_subhdr)];
2087 struct i2c_file_hdr i2c_hdr;
2088 struct libpcap_bt_phdr bt_hdr;
2089 struct libpcap_bt_monitor_phdr bt_monitor_hdr;
2090 struct libpcap_ppp_phdr ppp_hdr;
2092 size_t subhdr_size = 0;
2096 case WTAP_ENCAP_ATM_PDUS:
2098 * Write the ATM header.
2100 atm_hdr[SUNATM_FLAGS] =
2101 (pseudo_header->atm.channel == 0) ? 0x80 : 0x00;
2102 switch (pseudo_header->atm.aal) {
2104 case AAL_SIGNALLING:
2106 atm_hdr[SUNATM_FLAGS] |= 0x06;
2110 switch (pseudo_header->atm.type) {
2114 atm_hdr[SUNATM_FLAGS] |= 0x01;
2118 /* RFC 1483 LLC multiplexed traffic */
2119 atm_hdr[SUNATM_FLAGS] |= 0x02;
2124 atm_hdr[SUNATM_FLAGS] |= 0x05;
2129 atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi;
2130 phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci);
2131 if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err))
2133 wdh->bytes_dumped += sizeof(atm_hdr);
2136 case WTAP_ENCAP_IRDA:
2138 * Write the IrDA header.
2140 memset(irda_hdr, 0, sizeof(irda_hdr));
2141 phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET],
2142 pseudo_header->irda.pkttype);
2143 phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017);
2144 if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err))
2146 wdh->bytes_dumped += sizeof(irda_hdr);
2149 case WTAP_ENCAP_MTP2_WITH_PHDR:
2151 * Write the MTP2 header.
2153 memset(&mtp2_hdr, 0, sizeof(mtp2_hdr));
2154 mtp2_hdr[MTP2_SENT_OFFSET] = pseudo_header->mtp2.sent;
2155 mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET] = pseudo_header->mtp2.annex_a_used;
2156 phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET],
2157 pseudo_header->mtp2.link_number);
2158 if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err))
2160 wdh->bytes_dumped += sizeof(mtp2_hdr);
2163 case WTAP_ENCAP_LINUX_LAPD:
2165 * Write the LAPD header.
2167 memset(&lapd_hdr, 0, sizeof(lapd_hdr));
2168 phtons(&lapd_hdr[LAPD_SLL_PKTTYPE_OFFSET],
2169 pseudo_header->lapd.pkttype);
2170 phtons(&lapd_hdr[LAPD_SLL_PROTOCOL_OFFSET], ETH_P_LAPD);
2171 lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] =
2172 pseudo_header->lapd.we_network?0x01:0x00;
2173 if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err))
2175 wdh->bytes_dumped += sizeof(lapd_hdr);
2178 case WTAP_ENCAP_SITA:
2180 * Write the SITA header.
2182 memset(&sita_hdr, 0, sizeof(sita_hdr));
2183 sita_hdr[SITA_FLAGS_OFFSET] = pseudo_header->sita.sita_flags;
2184 sita_hdr[SITA_SIGNALS_OFFSET] = pseudo_header->sita.sita_signals;
2185 sita_hdr[SITA_ERRORS1_OFFSET] = pseudo_header->sita.sita_errors1;
2186 sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.sita_errors2;
2187 sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.sita_proto;
2188 if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err))
2190 wdh->bytes_dumped += sizeof(sita_hdr);
2193 case WTAP_ENCAP_ERF:
2195 * Write the ERF header.
2197 memset(&erf_hdr, 0, sizeof(erf_hdr));
2198 phtolell(&erf_hdr[0], pseudo_header->erf.phdr.ts);
2199 erf_hdr[8] = pseudo_header->erf.phdr.type;
2200 erf_hdr[9] = pseudo_header->erf.phdr.flags;
2203 * Recalculate rlen as padding (and maybe extension headers)
2204 * have been stripped from caplen.
2206 * XXX: Since we don't have phdr->caplen here, assume caplen was
2207 * calculated correctly and recalculate from wlen.
2209 phtons(&erf_hdr[10],
2210 MIN(pseudo_header->erf.phdr.rlen, pseudo_header->erf.phdr.wlen + pcap_get_phdr_size(WTAP_ENCAP_ERF, pseudo_header)));
2212 phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr);
2213 phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen);
2214 size = sizeof(struct erf_phdr);
2216 switch(pseudo_header->erf.phdr.type & 0x7F) {
2217 case ERF_TYPE_MC_HDLC:
2218 case ERF_TYPE_MC_RAW:
2219 case ERF_TYPE_MC_ATM:
2220 case ERF_TYPE_MC_RAW_CHANNEL:
2221 case ERF_TYPE_MC_AAL5:
2222 case ERF_TYPE_MC_AAL2:
2223 case ERF_TYPE_COLOR_MC_HDLC_POS:
2224 phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.mc_hdr);
2225 subhdr_size += (int)sizeof(struct erf_mc_hdr);
2228 phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.aal2_hdr);
2229 subhdr_size += (int)sizeof(struct erf_aal2_hdr);
2232 case ERF_TYPE_COLOR_ETH:
2233 case ERF_TYPE_DSM_COLOR_ETH:
2234 case ERF_TYPE_COLOR_HASH_ETH:
2235 memcpy(&erf_subhdr[0], &pseudo_header->erf.subhdr.eth_hdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
2236 subhdr_size += (int)sizeof(struct erf_eth_hdr);
2241 if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
2243 wdh->bytes_dumped += size;
2246 * Now write out the extension headers.
2248 if (pseudo_header->erf.phdr.type & 0x80) {
2249 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
2250 guint8 erf_exhdr[8];
2254 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
2255 type = erf_exhdr[0];
2256 /* Clear more extension headers bit if > 8 */
2258 erf_exhdr[0] = erf_exhdr[0] & 0x7F;
2260 if (!wtap_dump_file_write(wdh, erf_exhdr, 8, err))
2262 wdh->bytes_dumped += 8;
2264 } while (type & 0x80 && i < max);
2268 * Now write out the subheader.
2270 if(!wtap_dump_file_write(wdh, erf_subhdr, subhdr_size, err))
2272 wdh->bytes_dumped += subhdr_size;
2275 case WTAP_ENCAP_I2C:
2277 * Write the I2C header.
2279 memset(&i2c_hdr, 0, sizeof(i2c_hdr));
2280 i2c_hdr.bus = pseudo_header->i2c.bus |
2281 (pseudo_header->i2c.is_event ? 0x80 : 0x00);
2282 phtonl((guint8 *)&i2c_hdr.flags, pseudo_header->i2c.flags);
2283 if (!wtap_dump_file_write(wdh, &i2c_hdr, sizeof(i2c_hdr), err))
2285 wdh->bytes_dumped += sizeof(i2c_hdr);
2288 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
2289 bt_hdr.direction = GUINT32_TO_BE(pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV);
2290 if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err))
2292 wdh->bytes_dumped += sizeof bt_hdr;
2295 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
2296 bt_monitor_hdr.adapter_id = GUINT16_TO_BE(pseudo_header->btmon.adapter_id);
2297 bt_monitor_hdr.opcode = GUINT16_TO_BE(pseudo_header->btmon.opcode);
2299 if (!wtap_dump_file_write(wdh, &bt_monitor_hdr, sizeof bt_monitor_hdr, err))
2301 wdh->bytes_dumped += sizeof bt_monitor_hdr;
2304 case WTAP_ENCAP_PPP_WITH_PHDR:
2305 ppp_hdr.direction = (pseudo_header->p2p.sent ? LIBPCAP_PPP_PHDR_SENT : LIBPCAP_PPP_PHDR_RECV);
2306 if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err))
2308 wdh->bytes_dumped += sizeof ppp_hdr;
2315 * Editor modelines - http://www.wireshark.org/tools/modelines.html
2320 * indent-tabs-mode: t
2323 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
2324 * :indentSize=8:tabSize=8:noTabs=false: