2 * Code common to libpcap and pcap-NG file formats
7 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
9 * File format support for pcap-ng file format
10 * Copyright (c) 2007 by Ulf Lamping <ulf.lamping@web.de>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include "file_wrappers.h"
36 #include "pcap-encap.h"
37 #include "pcap-common.h"
40 * Map link-layer types (LINKTYPE_ values) to Wiretap encapsulations.
43 * Either LBL NRG wasn't an adequate central registry (e.g., because of
44 * the slow rate of releases from them), or nobody bothered using them
45 * as a central registry, as many different groups have patched libpcap
46 * (and BPF, on the BSDs) to add new encapsulation types, and have ended
47 * up using the same DLT_ values for different encapsulation types.
49 * For those numerical encapsulation type values that everybody uses for
50 * the same encapsulation type (which inclues those that some platforms
51 * specify different DLT_ names for but don't appear to use), we map
52 * those values to the appropriate Wiretap values.
54 * For those numerical encapsulation type values that different libpcap
55 * variants use for different encapsulation types, we check what
56 * <pcap.h> defined to determine how to interpret them, so that we
57 * interpret them the way the libpcap with which we're building
58 * Wireshark/Wiretap interprets them (which, if it doesn't support
59 * them at all, means we don't support them either - any capture files
60 * using them are foreign, and we don't hazard a guess as to which
61 * platform they came from; we could, I guess, choose the most likely
64 * Note: if you need a new encapsulation type for libpcap files, do
65 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
66 * add a new encapsulation type by changing an existing entry;
67 * leave the existing entries alone.
69 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking for
70 * a new DLT_ value, and specifying the purpose of the new value. When
71 * you get the new DLT_ value, use that numerical value in the "dlt_value"
72 * field of "pcap_to_wtap_map[]".
78 } pcap_to_wtap_map[] = {
80 * These are the values that are almost certainly the same
81 * in all libpcaps (I've yet to find one where the values
82 * in question are used for some purpose other than the
83 * one below, but...), and that Wiretap and Wireshark
86 { 0, WTAP_ENCAP_NULL }, /* null encapsulation */
87 { 1, WTAP_ENCAP_ETHERNET },
88 { 3, WTAP_ENCAP_AX25 },
89 { 6, WTAP_ENCAP_TOKEN_RING }, /* IEEE 802 Networks - assume token ring */
90 { 7, WTAP_ENCAP_ARCNET },
91 { 8, WTAP_ENCAP_SLIP },
92 { 9, WTAP_ENCAP_PPP },
93 #ifdef BIT_SWAPPED_MAC_ADDRS
94 { 10, WTAP_ENCAP_FDDI_BITSWAPPED },
96 { 10, WTAP_ENCAP_FDDI },
99 { 32, WTAP_ENCAP_REDBACK },
102 * 50 is DLT_PPP_SERIAL in NetBSD; it appears that DLT_PPP
103 * on BSD (at least according to standard tcpdump) has, as
104 * the first octet, an indication of whether the packet was
105 * transmitted or received (rather than having the standard
106 * PPP address value of 0xff), but that DLT_PPP_SERIAL puts
107 * a real live PPP header there, or perhaps a Cisco PPP header
108 * as per section 4.3.1 of RFC 1547 (implementations of this
109 * exist in various BSDs in "sys/net/if_spppsubr.c", and
110 * I think also exist either in standard Linux or in
111 * various Linux patches; the implementations show how to handle
112 * Cisco keepalive packets).
114 * However, I don't see any obvious place in FreeBSD "if_ppp.c"
115 * where anything other than the standard PPP header would be
116 * passed up. I see some stuff that sets the first octet
117 * to 0 for incoming and 1 for outgoing packets before applying
118 * a BPF filter to see whether to drop packets whose protocol
119 * field has the 0x8000 bit set, i.e. network control protocols -
120 * those are handed up to userland - but that code puts the
121 * address field back before passing the packet up.
123 * I also don't see anything immediately obvious that munges
124 * the address field for sync PPP, either.
126 * Wireshark currently assumes that if the first octet of a
127 * PPP frame is 0xFF, it's the address field and is followed
128 * by a control field and a 2-byte protocol, otherwise the
129 * address and control fields are absent and the frame begins
130 * with a protocol field. If we ever see a BSD/OS PPP
131 * capture, we'll have to handle it differently, and we may
132 * have to handle standard BSD captures differently if, in fact,
133 * they don't have 0xff 0x03 as the first two bytes - but, as per
134 * the two paragraphs preceding this, it's not clear that
135 * the address field *is* munged into an incoming/outgoing
136 * field when the packet is handed to the BPF device.
138 * For now, we just map DLT_PPP_SERIAL to WTAP_ENCAP_PPP, as
139 * we treat WTAP_ENCAP_PPP packets as if those beginning with
140 * 0xff have the standard RFC 1662 "PPP in HDLC-like Framing"
141 * 0xff 0x03 address/control header, and DLT_PPP_SERIAL frames
142 * appear to contain that unless they're Cisco frames (if we
143 * ever see a capture with them, we'd need to implement the
144 * RFC 1547 stuff, and the keepalive protocol stuff).
146 * We may have to distinguish between "PPP where if it doesn't
147 * begin with 0xff there's no HDLC encapsulation and the frame
148 * begins with the protocol field" (which is how we handle
149 * WTAP_ENCAP_PPP now) and "PPP where there's either HDLC
150 * encapsulation or Cisco PPP" (which is what DLT_PPP_SERIAL
153 * XXX - NetBSD has DLT_HDLC, which appears to be used for
154 * Cisco HDLC. Ideally, they should use DLT_PPP_SERIAL
155 * only for real live HDLC-encapsulated PPP, not for Cisco
158 { 50, WTAP_ENCAP_PPP },
161 * Used by NetBSD and OpenBSD pppoe(4).
163 { 51, WTAP_ENCAP_PPP_ETHER },
166 * Apparently used by the Axent Raptor firewall (now Symantec
167 * Enterprise Firewall).
168 * Thanks, Axent, for not reserving that type with tcpdump.org
169 * and not telling anybody about it.
171 { 99, WTAP_ENCAP_SYMANTEC },
174 * These are the values that libpcap 0.5 and later use in
175 * capture file headers, in an attempt to work around the
176 * confusion decried above, and that Wiretap and Wireshark
179 { 100, WTAP_ENCAP_ATM_RFC1483 },
180 { 101, WTAP_ENCAP_RAW_IP },
183 * More values used by libpcap 0.5 as DLT_ values and used by the
184 * current CVS version of libpcap in capture file headers.
185 * They are not yet handled in Wireshark.
186 * If we get a capture that contains them, we'll implement them.
188 { 102, WTAP_ENCAP_SLIP_BSDOS },
189 { 103, WTAP_ENCAP_PPP_BSDOS },
193 * These ones are handled in Wireshark, though.
195 { 104, WTAP_ENCAP_CHDLC }, /* Cisco HDLC */
196 { 105, WTAP_ENCAP_IEEE_802_11 }, /* IEEE 802.11 */
197 { 106, WTAP_ENCAP_LINUX_ATM_CLIP },
198 { 107, WTAP_ENCAP_FRELAY }, /* Frame Relay */
199 { 108, WTAP_ENCAP_NULL }, /* OpenBSD loopback */
200 { 109, WTAP_ENCAP_ENC }, /* OpenBSD IPSEC enc */
202 { 110, WTAP_ENCAP_LANE_802_3 },/* ATM LANE 802.3 */
203 { 111, WTAP_ENCAP_HIPPI }, /* NetBSD HIPPI */
205 { 112, WTAP_ENCAP_CHDLC }, /* NetBSD HDLC framing */
208 * Linux "cooked mode" captures, used by the current CVS version
211 * it could be a packet in Cisco's ERSPAN encapsulation which uses
212 * this number as well (why can't people stick to protocols when it
213 * comes to allocating/using DLT types).
215 { 113, WTAP_ENCAP_SLL }, /* Linux cooked capture */
217 { 114, WTAP_ENCAP_LOCALTALK }, /* Localtalk */
220 * The tcpdump.org version of libpcap uses 117, rather than 17,
221 * for OpenBSD packet filter logging, so as to avoid conflicting
222 * with DLT_LANE8023 in SuSE 6.3 libpcap.
224 { 117, WTAP_ENCAP_PFLOG },
226 { 118, WTAP_ENCAP_CISCO_IOS },
227 { 119, WTAP_ENCAP_IEEE_802_11_PRISM }, /* 802.11 plus Prism monitor mode radio header */
228 { 121, WTAP_ENCAP_HHDLC }, /* HiPath HDLC */
229 { 122, WTAP_ENCAP_IP_OVER_FC }, /* RFC 2625 IP-over-FC */
230 { 123, WTAP_ENCAP_ATM_PDUS }, /* SunATM */
231 { 127, WTAP_ENCAP_IEEE_802_11_RADIOTAP }, /* 802.11 plus radiotap radio header */
232 { 128, WTAP_ENCAP_TZSP }, /* Tazmen Sniffer Protocol */
233 { 129, WTAP_ENCAP_ARCNET_LINUX },
234 { 130, WTAP_ENCAP_JUNIPER_MLPPP }, /* Juniper MLPPP on ML-, LS-, AS- PICs */
235 { 131, WTAP_ENCAP_JUNIPER_MLFR }, /* Juniper MLFR (FRF.15) on ML-, LS-, AS- PICs */
236 { 133, WTAP_ENCAP_JUNIPER_GGSN},
238 * Values 132-134, 136 not listed here are reserved for use
239 * in Juniper hardware.
241 { 135, WTAP_ENCAP_JUNIPER_ATM2 }, /* various encapsulations captured on the ATM2 PIC */
242 { 137, WTAP_ENCAP_JUNIPER_ATM1 }, /* various encapsulations captured on the ATM1 PIC */
244 { 138, WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 },
245 /* Apple IP-over-IEEE 1394 */
247 { 139, WTAP_ENCAP_MTP2_WITH_PHDR },
248 { 140, WTAP_ENCAP_MTP2 },
249 { 141, WTAP_ENCAP_MTP3 },
250 { 142, WTAP_ENCAP_SCCP },
251 { 143, WTAP_ENCAP_DOCSIS },
252 { 144, WTAP_ENCAP_IRDA }, /* IrDA capture */
254 /* Reserved for private use. */
255 { 147, WTAP_ENCAP_USER0 },
256 { 148, WTAP_ENCAP_USER1 },
257 { 149, WTAP_ENCAP_USER2 },
258 { 150, WTAP_ENCAP_USER3 },
259 { 151, WTAP_ENCAP_USER4 },
260 { 152, WTAP_ENCAP_USER5 },
261 { 153, WTAP_ENCAP_USER6 },
262 { 154, WTAP_ENCAP_USER7 },
263 { 155, WTAP_ENCAP_USER8 },
264 { 156, WTAP_ENCAP_USER9 },
265 { 157, WTAP_ENCAP_USER10 },
266 { 158, WTAP_ENCAP_USER11 },
267 { 159, WTAP_ENCAP_USER12 },
268 { 160, WTAP_ENCAP_USER13 },
269 { 161, WTAP_ENCAP_USER14 },
270 { 162, WTAP_ENCAP_USER15 },
272 { 163, WTAP_ENCAP_IEEE_802_11_AVS }, /* 802.11 plus AVS radio header */
275 * 164 is reserved for Juniper-private chassis-internal
276 * meta-information such as QoS profiles, etc..
279 { 165, WTAP_ENCAP_BACNET_MS_TP },
282 * 166 is reserved for a PPP variant in which the first byte
283 * of the 0xff03 header, the 0xff, is replaced by a direction
284 * byte. I don't know whether any captures look like that,
285 * but it is used for some Linux IP filtering (ipfilter?).
288 /* Ethernet PPPoE frames captured on a service PIC */
289 { 167, WTAP_ENCAP_JUNIPER_PPPOE },
292 * 168 is reserved for more Juniper private-chassis-
293 * internal meta-information.
296 { 169, WTAP_ENCAP_GPRS_LLC },
299 * 170 and 171 are reserved for ITU-T G.7041/Y.1303 Generic
303 /* Registered by Gcom, Inc. */
304 { 172, WTAP_ENCAP_GCOM_TIE1 },
305 { 173, WTAP_ENCAP_GCOM_SERIAL },
307 { 177, WTAP_ENCAP_LINUX_LAPD },
309 /* Ethernet frames prepended with meta-information */
310 { 178, WTAP_ENCAP_JUNIPER_ETHER },
311 /* PPP frames prepended with meta-information */
312 { 179, WTAP_ENCAP_JUNIPER_PPP },
313 /* Frame-Relay frames prepended with meta-information */
314 { 180, WTAP_ENCAP_JUNIPER_FRELAY },
315 /* C-HDLC frames prepended with meta-information */
316 { 181, WTAP_ENCAP_JUNIPER_CHDLC },
317 /* VOIP Frames prepended with meta-information */
318 { 183, WTAP_ENCAP_JUNIPER_VP },
319 /* raw USB packets */
320 { 186, WTAP_ENCAP_USB },
321 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
322 { 187, WTAP_ENCAP_BLUETOOTH_H4 },
323 /* IEEE 802.16 MAC Common Part Sublayer */
324 { 188, WTAP_ENCAP_IEEE802_16_MAC_CPS },
325 /* USB packets with Linux-specified header */
326 { 189, WTAP_ENCAP_USB_LINUX },
328 { 190, WTAP_ENCAP_CAN20B },
329 /* Per-Packet Information header */
330 { 192, WTAP_ENCAP_PPI },
331 /* IEEE 802.15.4 Wireless PAN */
332 { 195, WTAP_ENCAP_IEEE802_15_4 },
333 /* SITA File Encapsulation */
334 { 196, WTAP_ENCAP_SITA },
335 /* Endace Record File Encapsulation */
336 { 197, WTAP_ENCAP_ERF },
338 { 199, WTAP_ENCAP_IPMB },
339 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
340 { 201, WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR },
341 /* AX.25 packet with a 1-byte KISS header */
342 { 202, WTAP_ENCAP_AX25_KISS },
344 { 203, WTAP_ENCAP_LAPD },
345 /* PPP with pseudoheader */
346 { 204, WTAP_ENCAP_PPP_WITH_PHDR },
348 { 209, WTAP_ENCAP_I2C },
350 { 210, WTAP_ENCAP_FLEXRAY },
352 { 211, WTAP_ENCAP_MOST },
354 { 212, WTAP_ENCAP_LIN },
355 /* X2E Xoraya serial frame */
356 { 213, WTAP_ENCAP_X2E_SERIAL },
357 /* X2E Xoraya frame */
358 { 214, WTAP_ENCAP_X2E_XORAYA },
359 /* IEEE 802.15.4 Wireless PAN non-ASK PHY */
360 { 215, WTAP_ENCAP_IEEE802_15_4_NONASK_PHY },
361 /* USB packets with padded Linux-specified header */
362 { 220, WTAP_ENCAP_USB_LINUX_MMAPPED },
363 /* Fibre Channel FC-2 frame */
364 { 224, WTAP_ENCAP_FIBRE_CHANNEL_FC2 },
365 /* Fibre Channel FC-2 frame with Delimiter */
366 { 225, WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS },
368 { 226, WTAP_ENCAP_IPNET },
369 /* SocketCAN frame */
370 { 227, WTAP_ENCAP_SOCKETCAN },
372 { 228, WTAP_ENCAP_RAW_IP4 },
374 { 229, WTAP_ENCAP_RAW_IP6 },
375 /* IEEE 802.15.4 Wireless PAN no fcs */
376 { 230, WTAP_ENCAP_IEEE802_15_4_NOFCS },
378 { 231, WTAP_ENCAP_DBUS },
379 /* DVB-CI (Common Interface) */
380 { 235, WTAP_ENCAP_DVBCI },
382 { 236, WTAP_ENCAP_MUX27010 },
384 { 239, WTAP_ENCAP_NFLOG },
385 /* netANALYZER pseudo-header followed by Ethernet with CRC */
386 { 240, WTAP_ENCAP_NETANALYZER },
387 /* netANALYZER pseudo-header in transparent mode */
388 { 241, WTAP_ENCAP_NETANALYZER_TRANSPARENT },
389 /* IP-over-Infiniband, as specified by RFC 4391 section 6 */
390 { 242, WTAP_ENCAP_IP_OVER_IB },
391 /* ISO/IEC 13818-1 MPEG2-TS packets */
392 { 243, WTAP_ENCAP_MPEG_2_TS },
394 { 245, WTAP_ENCAP_NFC_LLCP },
396 { 248, WTAP_ENCAP_SCTP},
401 * If you need a new encapsulation type for libpcap files, do
402 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
403 * add a new encapsulation type by changing an existing entry;
404 * leave the existing entries alone.
406 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
407 * for a new DLT_ value, and specifying the purpose of the new value.
408 * When you get the new DLT_ value, use that numerical value in
409 * the "dlt_value" field of "pcap_to_wtap_map[]".
413 * The following are entries for libpcap type values that have
414 * different meanings on different OSes.
416 * We put these *after* the entries for the platform-independent
417 * libpcap type values for those Wiretap encapsulation types, so
418 * that Wireshark chooses the platform-independent libpcap type
419 * value for those encapsulatioin types, not the platform-dependent
424 * 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
425 * seen that define anything other than DLT_ATM_RFC1483 as 11 are
426 * the BSD/OS one, which defines DLT_FR as 11, and libpcap 0.5,
427 * which define it as 100, mapping the kernel's value to 100, in
428 * an attempt to hide the different values used on different
431 * If this is a platform where DLT_FR is defined as 11, we
432 * don't handle 11 at all; otherwise, we handle it as
433 * DLT_ATM_RFC1483 (this means we'd misinterpret Frame Relay
434 * captures from BSD/OS if running on platforms other than BSD/OS,
437 * 1) we don't yet support DLT_FR
441 * 2) nothing short of a heuristic would let us interpret
444 #if defined(DLT_FR) && (DLT_FR == 11)
445 { 11, WTAP_ENCAP_FRELAY },
447 { 11, WTAP_ENCAP_ATM_RFC1483 },
451 * 12 is DLT_RAW on most platforms, but it's DLT_C_HDLC on
452 * BSD/OS, and DLT_LOOP on OpenBSD.
454 * We don't yet handle DLT_C_HDLC, but we can handle DLT_LOOP
455 * (it's just like DLT_NULL, only with the AF_ value in network
456 * rather than host byte order - Wireshark figures out the
457 * byte order from the data, so we don't care what byte order
458 * it's in), so if DLT_LOOP is defined as 12, interpret 12
459 * as WTAP_ENCAP_NULL, otherwise, unless DLT_C_HDLC is defined
460 * as 12, interpret it as WTAP_ENCAP_RAW_IP.
462 #if defined(DLT_LOOP) && (DLT_LOOP == 12)
463 { 12, WTAP_ENCAP_NULL },
464 #elif defined(DLT_C_HDLC) && (DLT_C_HDLC == 12)
466 * Put entry for Cisco HDLC here.
467 * XXX - is this just WTAP_ENCAP_CHDLC, i.e. does the frame
468 * start with a 4-byte Cisco HDLC header?
471 { 12, WTAP_ENCAP_RAW_IP },
475 * 13 is DLT_SLIP_BSDOS on FreeBSD and NetBSD, but those OSes
476 * don't actually generate it. I infer that BSD/OS translates
477 * DLT_SLIP from the kernel BPF code to DLT_SLIP_BSDOS in
478 * libpcap, as the BSD/OS link-layer header is different;
479 * however, in BSD/OS, DLT_SLIP_BSDOS is 15.
481 * From this, I infer that there's no point in handling 13
484 * 13 is DLT_ATM_RFC1483 on BSD/OS.
486 * 13 is DLT_ENC in OpenBSD, which is, I suspect, some kind
487 * of decrypted IPsec traffic.
489 * We treat 13 as WTAP_ENCAP_ENC on all systems except those
490 * that define DLT_ATM_RFC1483 as 13 - presumably only
491 * BSD/OS does so - so that, on BSD/OS systems, we still
492 * treate 13 as WTAP_ENCAP_ATM_RFC1483, but, on all other
493 * systems, we can read OpenBSD DLT_ENC captures.
495 #if defined(DLT_ATM_RFC1483) && (DLT_ATM_RFC1483 == 13)
496 { 13, WTAP_ENCAP_ATM_RFC1483 },
498 { 13, WTAP_ENCAP_ENC },
502 * 14 is DLT_PPP_BSDOS on FreeBSD and NetBSD, but those OSes
503 * don't actually generate it. I infer that BSD/OS translates
504 * DLT_PPP from the kernel BPF code to DLT_PPP_BSDOS in
505 * libpcap, as the BSD/OS link-layer header is different;
506 * however, in BSD/OS, DLT_PPP_BSDOS is 16.
508 * From this, I infer that there's no point in handling 14
511 * 14 is DLT_RAW on BSD/OS and OpenBSD.
513 { 14, WTAP_ENCAP_RAW_IP },
518 * DLT_SLIP_BSDOS on BSD/OS;
520 * DLT_HIPPI on NetBSD;
522 * DLT_LANE8023 with Alexey Kuznetzov's patches for
525 * DLT_I4L_RAWIP with the ISDN4Linux patches for libpcap
528 * but we don't currently handle any of those.
534 * DLT_PPP_BSDOS on BSD/OS;
536 * DLT_HDLC on NetBSD (Cisco HDLC);
538 * DLT_CIP with Alexey Kuznetzov's patches for
539 * Linux libpcap - this is WTAP_ENCAP_LINUX_ATM_CLIP;
541 * DLT_I4L_IP with the ISDN4Linux patches for libpcap
544 #if defined(DLT_CIP) && (DLT_CIP == 16)
545 { 16, WTAP_ENCAP_LINUX_ATM_CLIP },
547 #if defined(DLT_HDLC) && (DLT_HDLC == 16)
548 { 16, WTAP_ENCAP_CHDLC },
552 * 17 is DLT_LANE8023 in SuSE 6.3 libpcap; we don't currently
554 * It is also used as the PF (Packet Filter) logging format beginning
555 * with OpenBSD 3.0; we use 17 for PF logs unless DLT_LANE8023 is
556 * defined with the value 17.
558 #if !defined(DLT_LANE8023) || (DLT_LANE8023 != 17)
559 { 17, WTAP_ENCAP_OLD_PFLOG },
563 * 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
564 * DLT_CIP of 16 that the Alexey Kuznetzov patches for
565 * libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
566 * I've not found any libpcap that uses it for any other purpose -
567 * hopefully nobody will do so in the future.
569 { 18, WTAP_ENCAP_LINUX_ATM_CLIP },
572 * 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
573 * recent versions I've seen of the Linux ATM distribution;
574 * I've not yet found any libpcap that uses it for any other
575 * purpose - hopefully nobody will do so in the future.
577 { 19, WTAP_ENCAP_LINUX_ATM_CLIP },
582 * If you need a new encapsulation type for libpcap files, do
583 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
584 * add a new encapsulation type by changing an existing entry;
585 * leave the existing entries alone.
587 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
588 * for a new DLT_ value, and specifying the purpose of the new value.
589 * When you get the new DLT_ value, use that numerical value in
590 * the "dlt_value" field of "pcap_to_wtap_map[]".
593 #define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0])
597 wtap_pcap_encap_to_wtap_encap(int encap)
601 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
602 if (pcap_to_wtap_map[i].dlt_value == encap)
603 return pcap_to_wtap_map[i].wtap_encap_value;
605 return WTAP_ENCAP_UNKNOWN;
610 wtap_wtap_encap_to_pcap_encap(int encap)
616 case WTAP_ENCAP_FDDI:
617 case WTAP_ENCAP_FDDI_BITSWAPPED:
618 case WTAP_ENCAP_NETTL_FDDI:
620 * Special-case WTAP_ENCAP_FDDI and
621 * WTAP_ENCAP_FDDI_BITSWAPPED; both of them get mapped
622 * to DLT_FDDI (even though that may mean that the bit
623 * order in the FDDI MAC addresses is wrong; so it goes
624 * - libpcap format doesn't record the byte order,
625 * so that's not fixable).
627 return 10; /* that's DLT_FDDI */
629 case WTAP_ENCAP_FRELAY_WITH_PHDR:
631 * Do the same with Frame Relay.
635 case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
637 * Map this to DLT_IEEE802_11, for now, even though
638 * that means the radio information will be lost.
639 * Once tcpdump support for the BSD radiotap header
640 * is sufficiently widespread, we should probably
641 * use that, instead - although we should probably
642 * ultimately just have WTAP_ENCAP_IEEE_802_11
643 * as the only Wiretap encapsulation for 802.11,
644 * and have the pseudo-header include a radiotap-style
645 * list of attributes. If we do that, though, we
646 * should probably bypass the regular Wiretap code
647 * when writing out packets during a capture, and just
648 * do the equivalent of a libpcap write (unfortunately,
649 * libpcap doesn't have an "open dump by file descriptor"
650 * function, so we can't just use "pcap_dump()"), so
651 * that we don't spend cycles mapping from libpcap to
652 * Wiretap and then back to libpcap. (There are other
653 * reasons to do that, e.g. to handle AIX libpcap better.)
658 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
659 if (pcap_to_wtap_map[i].wtap_encap_value == encap)
660 return pcap_to_wtap_map[i].dlt_value;
667 wtap_encap_requires_phdr(int encap) {
669 (encap == WTAP_ENCAP_ATM_PDUS) ||
670 (encap == WTAP_ENCAP_IRDA) ||
671 (encap == WTAP_ENCAP_MTP2_WITH_PHDR) ||
672 (encap == WTAP_ENCAP_LINUX_LAPD) ||
673 (encap == WTAP_ENCAP_SITA) ||
674 (encap == WTAP_ENCAP_ERF) ||
675 (encap == WTAP_ENCAP_I2C) ||
676 (encap == WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR) ||
677 (encap == WTAP_ENCAP_PPP_WITH_PHDR)
686 * Various pseudo-headers that appear at the beginning of packet data.
688 * We represent them as sets of offsets, as they might not be aligned on
689 * an appropriate structure boundary in the buffer, and as that makes them
690 * independent of the way the compiler might align fields.
694 * The link-layer header on SunATM packets.
696 #define SUNATM_FLAGS 0 /* destination and traffic type - 1 byte */
697 #define SUNATM_VPI 1 /* VPI - 1 byte */
698 #define SUNATM_VCI 2 /* VCI - 2 bytes */
699 #define SUNATM_LEN 4 /* length of the header */
702 * The link-layer header on Nokia IPSO ATM packets.
704 #define NOKIAATM_FLAGS 0 /* destination - 1 byte */
705 #define NOKIAATM_VPI 1 /* VPI - 1 byte */
706 #define NOKIAATM_VCI 2 /* VCI - 2 bytes */
707 #define NOKIAATM_LEN 4 /* length of the header */
710 * The link-layer header on Nokia IPSO packets.
712 #define NOKIA_LEN 4 /* length of the header */
715 * The fake link-layer header of IrDA packets as introduced by Jean Tourrilhes
718 #define IRDA_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
719 /* 12 unused bytes */
720 #define IRDA_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
721 #define IRDA_SLL_LEN 16 /* length of the header */
724 * A header containing additional MTP information.
726 #define MTP2_SENT_OFFSET 0 /* 1 byte */
727 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
728 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
729 #define MTP2_HDR_LEN 4 /* length of the header */
732 * A header containing additional SITA WAN information.
734 #define SITA_FLAGS_OFFSET 0 /* 1 byte */
735 #define SITA_SIGNALS_OFFSET 1 /* 1 byte */
736 #define SITA_ERRORS1_OFFSET 2 /* 1 byte */
737 #define SITA_ERRORS2_OFFSET 3 /* 1 byte */
738 #define SITA_PROTO_OFFSET 4 /* 1 byte */
739 #define SITA_HDR_LEN 5 /* length of the header */
742 * The fake link-layer header of LAPD packets.
745 #define ETH_P_LAPD 0x0030
748 #define LAPD_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
749 #define LAPD_SLL_HATYPE_OFFSET 2 /* hardware address type - 2 bytes */
750 #define LAPD_SLL_HALEN_OFFSET 4 /* hardware address length - 2 bytes */
751 #define LAPD_SLL_ADDR_OFFSET 6 /* address - 8 bytes */
752 #define LAPD_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
753 #define LAPD_SLL_LEN 16 /* length of the header */
756 * The NFC LLCP per-packet header.
758 #define LLCP_ADAPTER_OFFSET 0
759 #define LLCP_FLAGS_OFFSET 1
760 #define LLCP_HEADER_LEN 2
763 * I2C link-layer on-disk format
765 struct i2c_file_hdr {
771 pcap_read_sunatm_pseudoheader(FILE_T fh,
772 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
774 guint8 atm_phdr[SUNATM_LEN];
779 errno = WTAP_ERR_CANT_READ;
780 bytes_read = file_read(atm_phdr, SUNATM_LEN, fh);
781 if (bytes_read != SUNATM_LEN) {
782 *err = file_error(fh, err_info);
784 *err = WTAP_ERR_SHORT_READ;
788 vpi = atm_phdr[SUNATM_VPI];
789 vci = pntohs(&atm_phdr[SUNATM_VCI]);
791 switch (atm_phdr[SUNATM_FLAGS] & 0x0F) {
793 case 0x01: /* LANE */
794 pseudo_header->atm.aal = AAL_5;
795 pseudo_header->atm.type = TRAF_LANE;
798 case 0x02: /* RFC 1483 LLC multiplexed traffic */
799 pseudo_header->atm.aal = AAL_5;
800 pseudo_header->atm.type = TRAF_LLCMX;
803 case 0x05: /* ILMI */
804 pseudo_header->atm.aal = AAL_5;
805 pseudo_header->atm.type = TRAF_ILMI;
808 case 0x06: /* Q.2931 */
809 pseudo_header->atm.aal = AAL_SIGNALLING;
810 pseudo_header->atm.type = TRAF_UNKNOWN;
813 case 0x03: /* MARS (RFC 2022) */
814 pseudo_header->atm.aal = AAL_5;
815 pseudo_header->atm.type = TRAF_UNKNOWN;
818 case 0x04: /* IFMP (Ipsilon Flow Management Protocol; see RFC 1954) */
819 pseudo_header->atm.aal = AAL_5;
820 pseudo_header->atm.type = TRAF_UNKNOWN; /* XXX - TRAF_IPSILON? */
825 * Assume it's AAL5, unless it's VPI 0 and VCI 5, in which
826 * case assume it's AAL_SIGNALLING; we know nothing more
829 * XXX - is this necessary? Or are we guaranteed that
830 * all signalling traffic has a type of 0x06?
832 * XXX - is this guaranteed to be AAL5? Or, if the type is
833 * 0x00 ("raw"), might it be non-AAL5 traffic?
835 if (vpi == 0 && vci == 5)
836 pseudo_header->atm.aal = AAL_SIGNALLING;
838 pseudo_header->atm.aal = AAL_5;
839 pseudo_header->atm.type = TRAF_UNKNOWN;
842 pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
844 pseudo_header->atm.vpi = vpi;
845 pseudo_header->atm.vci = vci;
846 pseudo_header->atm.channel = (atm_phdr[SUNATM_FLAGS] & 0x80) ? 0 : 1;
848 /* We don't have this information */
849 pseudo_header->atm.flags = 0;
850 pseudo_header->atm.cells = 0;
851 pseudo_header->atm.aal5t_u2u = 0;
852 pseudo_header->atm.aal5t_len = 0;
853 pseudo_header->atm.aal5t_chksum = 0;
859 pcap_read_nokiaatm_pseudoheader(FILE_T fh,
860 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
862 guint8 atm_phdr[NOKIAATM_LEN];
867 errno = WTAP_ERR_CANT_READ;
868 bytes_read = file_read(atm_phdr, NOKIAATM_LEN, fh);
869 if (bytes_read != NOKIAATM_LEN) {
870 *err = file_error(fh, err_info);
872 *err = WTAP_ERR_SHORT_READ;
876 vpi = atm_phdr[NOKIAATM_VPI];
877 vci = pntohs(&atm_phdr[NOKIAATM_VCI]);
879 pseudo_header->atm.vpi = vpi;
880 pseudo_header->atm.vci = vci;
881 pseudo_header->atm.channel = (atm_phdr[NOKIAATM_FLAGS] & 0x80) ? 0 : 1;
883 /* We don't have this information */
884 pseudo_header->atm.flags = 0;
885 pseudo_header->atm.cells = 0;
886 pseudo_header->atm.aal5t_u2u = 0;
887 pseudo_header->atm.aal5t_len = 0;
888 pseudo_header->atm.aal5t_chksum = 0;
894 pcap_read_nokia_pseudoheader(FILE_T fh,
895 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
897 guint8 phdr[NOKIA_LEN];
900 errno = WTAP_ERR_CANT_READ;
902 /* backtrack to read the 4 mysterious bytes that aren't considered
903 * part of the packet size
905 if (file_seek(fh, -NOKIA_LEN, SEEK_CUR, err) == -1)
907 *err = file_error(fh, err_info);
909 *err = WTAP_ERR_SHORT_READ;
913 bytes_read = file_read(phdr, NOKIA_LEN, fh);
914 if (bytes_read != NOKIA_LEN) {
915 *err = file_error(fh, err_info);
917 *err = WTAP_ERR_SHORT_READ;
921 memcpy(pseudo_header->nokia.stuff, phdr, NOKIA_LEN);
927 pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
928 int *err, gchar **err_info)
930 guint8 irda_phdr[IRDA_SLL_LEN];
933 errno = WTAP_ERR_CANT_READ;
934 bytes_read = file_read(irda_phdr, IRDA_SLL_LEN, fh);
935 if (bytes_read != IRDA_SLL_LEN) {
936 *err = file_error(fh, err_info);
938 *err = WTAP_ERR_SHORT_READ;
942 if (pntohs(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
943 *err = WTAP_ERR_BAD_FILE;
944 if (err_info != NULL)
945 *err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
949 pseudo_header->irda.pkttype = pntohs(&irda_phdr[IRDA_SLL_PKTTYPE_OFFSET]);
955 pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
957 guint8 mtp2_hdr[MTP2_HDR_LEN];
960 errno = WTAP_ERR_CANT_READ;
961 bytes_read = file_read(mtp2_hdr, MTP2_HDR_LEN, fh);
962 if (bytes_read != MTP2_HDR_LEN) {
963 *err = file_error(fh, err_info);
965 *err = WTAP_ERR_SHORT_READ;
969 pseudo_header->mtp2.sent = mtp2_hdr[MTP2_SENT_OFFSET];
970 pseudo_header->mtp2.annex_a_used = mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET];
971 pseudo_header->mtp2.link_number = pntohs(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET]);
977 pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
978 int *err, gchar **err_info)
980 guint8 lapd_phdr[LAPD_SLL_LEN];
983 errno = WTAP_ERR_CANT_READ;
984 bytes_read = file_read(lapd_phdr, LAPD_SLL_LEN, fh);
985 if (bytes_read != LAPD_SLL_LEN) {
986 *err = file_error(fh, err_info);
988 *err = WTAP_ERR_SHORT_READ;
992 if (pntohs(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
993 *err = WTAP_ERR_BAD_FILE;
994 if (err_info != NULL)
995 *err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
999 pseudo_header->lapd.pkttype = pntohs(&lapd_phdr[LAPD_SLL_PKTTYPE_OFFSET]);
1000 pseudo_header->lapd.we_network = !!lapd_phdr[LAPD_SLL_ADDR_OFFSET+0];
1006 pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1008 guint8 sita_phdr[SITA_HDR_LEN];
1011 errno = WTAP_ERR_CANT_READ;
1012 bytes_read = file_read(sita_phdr, SITA_HDR_LEN, fh);
1013 if (bytes_read != SITA_HDR_LEN) {
1014 *err = file_error(fh, err_info);
1016 *err = WTAP_ERR_SHORT_READ;
1020 pseudo_header->sita.sita_flags = sita_phdr[SITA_FLAGS_OFFSET];
1021 pseudo_header->sita.sita_signals = sita_phdr[SITA_SIGNALS_OFFSET];
1022 pseudo_header->sita.sita_errors1 = sita_phdr[SITA_ERRORS1_OFFSET];
1023 pseudo_header->sita.sita_errors2 = sita_phdr[SITA_ERRORS2_OFFSET];
1024 pseudo_header->sita.sita_proto = sita_phdr[SITA_PROTO_OFFSET];
1030 * When not using the memory-mapped interface to capture USB events,
1031 * code that reads those events can use the MON_IOCX_GET ioctl to
1032 * read a 48-byte header consisting of a "struct linux_usb_phdr", as
1033 * defined below, followed immediately by one of:
1035 * 8 bytes of a "struct usb_device_setup_hdr", if "setup_flag"
1036 * in the preceding "struct linux_usb_phdr" is 0;
1038 * in Linux 2.6.30 or later, 8 bytes of a "struct iso_rec", if
1039 * this is an isochronous transfer;
1041 * 8 bytes of junk, otherwise.
1043 * In Linux 2.6.31 and later, it can also use the MON_IOCX_GETX ioctl
1044 * to read a 64-byte header; that header consists of the 48 bytes
1045 * above, followed immediately by 16 bytes of a "struct linux_usb_phdr_ext",
1048 * In Linux 2.6.21 and later, there's a memory-mapped interface to
1049 * capture USB events. In that interface, the events in the memory-mapped
1050 * buffer have a 64-byte header, followed immediately by the data.
1051 * In Linux 2.6.21 through 2.6.30.x, the 64-byte header is the 48-byte
1052 * header described above, followed by 16 bytes of zeroes; in Linux
1053 * 2.6.31 and later, the 64-byte header is the 64-byte header described
1056 * See linux/Documentation/usb/usbmon.txt and libpcap/pcap/usb.h for details.
1058 * With WTAP_ENCAP_USB_LINUX, packets have the 48-byte header; with
1059 * WTAP_ENCAP_USB_LINUX_MMAPPED, they have the 64-byte header. There
1060 * is no indication of whether the header has the "struct iso_rec", or
1061 * whether the last 16 bytes of a 64-byte header are all zeros or are
1062 * a "struct linux_usb_phdr_ext".
1066 * URB transfer_type values
1068 #define URB_ISOCHRONOUS 0x0
1069 #define URB_INTERRUPT 0x1
1070 #define URB_CONTROL 0x2
1071 #define URB_BULK 0x3
1074 * Information from the URB for Isochronous transfers.
1076 * This structure is 8 bytes long.
1084 * Header prepended by Linux kernel to each USB event.
1086 * (Setup flag is '-', 'D', 'Z', or 0. Data flag is '<', '>', 'Z', or 0.)
1088 * The values are in *host* byte order.
1090 struct linux_usb_phdr {
1091 guint64 id; /* urb id, to link submission and completion events */
1092 guint8 event_type; /* Submit ('S'), Completed ('C'), Error ('E') */
1093 guint8 transfer_type; /* ISO (0), Intr, Control, Bulk (3) */
1094 guint8 endpoint_number; /* Endpoint number (0-15) and transfer direction */
1095 guint8 device_address; /* 0-127 */
1097 gint8 setup_flag; /* 0, if the urb setup header is meaningful */
1098 gint8 data_flag; /* 0, if urb data is present */
1102 guint32 urb_len; /* whole len of urb this event refers to */
1103 guint32 data_len; /* amount of urb data really present in this event */
1106 * Packet-type-dependent data.
1107 * USB setup information of setup_flag is true.
1108 * Otherwise, some isochronous transfer information.
1116 * This data is provided by Linux 2.6.31 and later kernels.
1118 * For WTAP_ENCAP_USB_LINUX, it's not in the pseudo-header, so
1119 * the pseudo-header is always 48 bytes long, including the
1120 * packet-type-dependent data.
1122 * For WTAP_ENCAP_USB_LINUX_MMAPPED, the pseudo-header is always
1123 * 64 bytes long, with the packet-type-dependent data preceding
1124 * these last 16 bytes. In pre-2.6.31 kernels, it's zero padding;
1125 * in 2.6.31 and later, it's the following data.
1127 gint32 interval; /* only for Interrupt and Isochronous events */
1128 gint32 start_frame; /* for Isochronous */
1129 guint32 xfer_flags; /* copy of URB's transfer_flags */
1130 guint32 ndesc; /* actual number of isochronous descriptors */
1133 struct linux_usb_isodesc {
1141 * USB setup header as defined in USB specification
1142 * See usb_20.pdf, Chapter 9.3 'USB Device Requests' for details.
1143 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
1145 * This structure is 8 bytes long.
1147 struct usb_device_setup_hdr {
1148 gint8 bmRequestType;
1157 * Offset of the *end* of a field within a particular structure.
1159 #define END_OFFSETOF(basep, fieldp) \
1160 (((char *)(void *)(fieldp)) - ((char *)(void *)(basep)) + \
1164 pcap_process_linux_usb_pseudoheader(guint packet_size, gboolean byte_swapped,
1165 gboolean header_len_64_bytes, guint8 *pd)
1167 struct linux_usb_phdr *phdr;
1168 struct linux_usb_isodesc *pisodesc;
1169 gint32 iso_numdesc, i;
1173 * Greasy hack, but we never directly direference any of
1174 * the fields in *phdr, we just get offsets of and
1175 * addresses of its members, so it's safe.
1177 phdr = (struct linux_usb_phdr *)(void *)pd;
1179 if (packet_size < END_OFFSETOF(phdr, &phdr->id))
1181 PBSWAP64((guint8 *)&phdr->id);
1182 if (packet_size < END_OFFSETOF(phdr, &phdr->bus_id))
1184 PBSWAP16((guint8 *)&phdr->bus_id);
1185 if (packet_size < END_OFFSETOF(phdr, &phdr->ts_sec))
1187 PBSWAP64((guint8 *)&phdr->ts_sec);
1188 if (packet_size < END_OFFSETOF(phdr, &phdr->ts_usec))
1190 PBSWAP32((guint8 *)&phdr->ts_usec);
1191 if (packet_size < END_OFFSETOF(phdr, &phdr->status))
1193 PBSWAP32((guint8 *)&phdr->status);
1194 if (packet_size < END_OFFSETOF(phdr, &phdr->urb_len))
1196 PBSWAP32((guint8 *)&phdr->urb_len);
1197 if (packet_size < END_OFFSETOF(phdr, &phdr->data_len))
1199 PBSWAP32((guint8 *)&phdr->data_len);
1201 if (phdr->transfer_type == URB_ISOCHRONOUS) {
1202 if (packet_size < END_OFFSETOF(phdr, &phdr->s.iso.error_count))
1204 PBSWAP32((guint8 *)&phdr->s.iso.error_count);
1206 if (packet_size < END_OFFSETOF(phdr, &phdr->s.iso.numdesc))
1208 PBSWAP32((guint8 *)&phdr->s.iso.numdesc);
1212 if (header_len_64_bytes) {
1214 * This is either the "version 1" header, with
1215 * 16 bytes of additional fields at the end, or
1216 * a "version 0" header from a memory-mapped
1217 * capture, with 16 bytes of zeroed-out padding
1218 * at the end. Byte swap them as if this were
1219 * a "version 1" header.
1221 * Yes, the first argument to END_OFFSETOF() should
1222 * be phdr, not phdr_ext; we want the offset of
1223 * the additional fields from the beginning of
1226 if (packet_size < END_OFFSETOF(phdr, &phdr->interval))
1228 PBSWAP32((guint8 *)&phdr->interval);
1229 if (packet_size < END_OFFSETOF(phdr, &phdr->start_frame))
1231 PBSWAP32((guint8 *)&phdr->start_frame);
1232 if (packet_size < END_OFFSETOF(phdr, &phdr->xfer_flags))
1234 PBSWAP32((guint8 *)&phdr->xfer_flags);
1235 if (packet_size < END_OFFSETOF(phdr, &phdr->ndesc))
1237 PBSWAP32((guint8 *)&phdr->ndesc);
1240 if (phdr->transfer_type == URB_ISOCHRONOUS) {
1241 /* swap the values in struct linux_usb_isodesc */
1244 * See previous "Greasy hack" comment.
1246 if (header_len_64_bytes) {
1247 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 64);
1249 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 48);
1251 iso_numdesc = phdr->s.iso.numdesc;
1252 for (i = 0; i < iso_numdesc; i++) {
1253 /* always check if we have enough data from the
1254 * beginnig of the packet (phdr)
1256 if (packet_size < END_OFFSETOF(phdr, &pisodesc->iso_status))
1258 PBSWAP32((guint8 *)&pisodesc->iso_status);
1259 if (packet_size < END_OFFSETOF(phdr, &pisodesc->iso_off))
1261 PBSWAP32((guint8 *)&pisodesc->iso_off);
1262 if (packet_size < END_OFFSETOF(phdr, &pisodesc->iso_len))
1264 PBSWAP32((guint8 *)&pisodesc->iso_len);
1265 if (packet_size < END_OFFSETOF(phdr, &pisodesc->_pad))
1267 PBSWAP32((guint8 *)&pisodesc->_pad);
1276 pcap_read_bt_pseudoheader(FILE_T fh,
1277 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1280 struct libpcap_bt_phdr phdr;
1282 errno = WTAP_ERR_CANT_READ;
1283 bytes_read = file_read(&phdr,
1284 sizeof (struct libpcap_bt_phdr), fh);
1285 if (bytes_read != sizeof (struct libpcap_bt_phdr)) {
1286 *err = file_error(fh, err_info);
1288 *err = WTAP_ERR_SHORT_READ;
1291 pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
1296 pcap_read_llcp_pseudoheader(FILE_T fh,
1297 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1300 guint8 phdr[LLCP_HEADER_LEN];
1302 errno = WTAP_ERR_CANT_READ;
1303 bytes_read = file_read(phdr, LLCP_HEADER_LEN, fh);
1304 if (bytes_read != LLCP_HEADER_LEN) {
1305 *err = file_error(fh, err_info);
1307 *err = WTAP_ERR_SHORT_READ;
1310 pseudo_header->llcp.adapter = phdr[LLCP_ADAPTER_OFFSET];
1311 pseudo_header->llcp.flags = phdr[LLCP_FLAGS_OFFSET];
1316 pcap_read_ppp_pseudoheader(FILE_T fh,
1317 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1320 struct libpcap_ppp_phdr phdr;
1322 errno = WTAP_ERR_CANT_READ;
1323 bytes_read = file_read(&phdr,
1324 sizeof (struct libpcap_ppp_phdr), fh);
1325 if (bytes_read != sizeof (struct libpcap_ppp_phdr)) {
1326 *err = file_error(fh, err_info);
1328 *err = WTAP_ERR_SHORT_READ;
1331 pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
1336 pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr,
1337 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1339 guint8 erf_hdr[sizeof(struct erf_phdr)];
1342 errno = WTAP_ERR_CANT_READ;
1343 bytes_read = file_read(erf_hdr, sizeof(struct erf_phdr), fh);
1344 if (bytes_read != sizeof(struct erf_phdr)) {
1345 *err = file_error(fh, err_info);
1347 *err = WTAP_ERR_SHORT_READ;
1350 pseudo_header->erf.phdr.ts = pletohll(&erf_hdr[0]); /* timestamp */
1351 pseudo_header->erf.phdr.type = erf_hdr[8];
1352 pseudo_header->erf.phdr.flags = erf_hdr[9];
1353 pseudo_header->erf.phdr.rlen = pntohs(&erf_hdr[10]);
1354 pseudo_header->erf.phdr.lctr = pntohs(&erf_hdr[12]);
1355 pseudo_header->erf.phdr.wlen = pntohs(&erf_hdr[14]);
1357 /* The high 32 bits of the timestamp contain the integer number of seconds
1358 * while the lower 32 bits contain the binary fraction of the second.
1359 * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */
1361 guint64 ts = pseudo_header->erf.phdr.ts;
1362 whdr->ts.secs = (guint32) (ts >> 32);
1363 ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000);
1364 ts += (ts & 0x80000000) << 1; /* rounding */
1365 whdr->ts.nsecs = ((guint32) (ts >> 32));
1366 if ( whdr->ts.nsecs >= 1000000000) {
1367 whdr->ts.nsecs -= 1000000000;
1375 * If the type of record given in the pseudo header indicate the presence of an extension
1376 * header then, read all the extension headers
1379 pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1380 int *err, gchar **err_info, guint * psize)
1383 guint8 erf_exhdr[8];
1384 guint64 erf_exhdr_sw;
1385 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1388 if (pseudo_header->erf.phdr.type & 0x80){
1390 errno = WTAP_ERR_CANT_READ;
1391 bytes_read = file_read(erf_exhdr, 8, fh);
1392 if (bytes_read != 8 ) {
1393 *err = file_error(fh, err_info);
1395 *err = WTAP_ERR_SHORT_READ;
1398 type = erf_exhdr[0];
1399 erf_exhdr_sw = pntohll(erf_exhdr);
1401 memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw));
1404 } while (type & 0x80);
1410 * If the type of record given in the pseudo header indicate the precense of a subheader
1411 * then, read this optional subheader
1414 pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1415 int *err, gchar **err_info, guint * psize)
1417 guint8 erf_subhdr[sizeof(union erf_subhdr)];
1421 switch(pseudo_header->erf.phdr.type & 0x7F) {
1422 case ERF_TYPE_MC_HDLC:
1423 case ERF_TYPE_MC_RAW:
1424 case ERF_TYPE_MC_ATM:
1425 case ERF_TYPE_MC_RAW_CHANNEL:
1426 case ERF_TYPE_MC_AAL5:
1427 case ERF_TYPE_MC_AAL2:
1428 case ERF_TYPE_COLOR_MC_HDLC_POS:
1429 /* Extract the Multi Channel header to include it in the pseudo header part */
1430 errno = WTAP_ERR_CANT_READ;
1431 bytes_read = file_read(erf_subhdr, sizeof(erf_mc_header_t), fh);
1432 if (bytes_read != sizeof(erf_mc_header_t) ) {
1433 *err = file_error(fh, err_info);
1435 *err = WTAP_ERR_SHORT_READ;
1438 pseudo_header->erf.subhdr.mc_hdr = pntohl(&erf_subhdr[0]);
1439 *psize = sizeof(erf_mc_header_t);
1442 case ERF_TYPE_COLOR_ETH:
1443 case ERF_TYPE_DSM_COLOR_ETH:
1444 /* Extract the Ethernet additional header to include it in the pseudo header part */
1445 errno = WTAP_ERR_CANT_READ;
1446 bytes_read = file_read(erf_subhdr, sizeof(erf_eth_header_t), fh);
1447 if (bytes_read != sizeof(erf_eth_header_t) ) {
1448 *err = file_error(fh, err_info);
1450 *err = WTAP_ERR_SHORT_READ;
1453 pseudo_header->erf.subhdr.eth_hdr = pntohs(&erf_subhdr[0]);
1454 *psize = sizeof(erf_eth_header_t);
1457 /* No optional pseudo header for this ERF type */
1464 pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1466 struct i2c_file_hdr i2c_hdr;
1469 errno = WTAP_ERR_CANT_READ;
1470 bytes_read = file_read(&i2c_hdr, sizeof (i2c_hdr), fh);
1471 if (bytes_read != sizeof (i2c_hdr)) {
1472 *err = file_error(fh, err_info);
1474 *err = WTAP_ERR_SHORT_READ;
1478 pseudo_header->i2c.is_event = i2c_hdr.bus & 0x80 ? 1 : 0;
1479 pseudo_header->i2c.bus = i2c_hdr.bus & 0x7f;
1480 pseudo_header->i2c.flags = pntohl(&i2c_hdr.flags);
1486 pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
1487 guint packet_size, gboolean check_packet_size, struct wtap_pkthdr *phdr,
1488 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1493 switch (wtap_encap) {
1495 case WTAP_ENCAP_ATM_PDUS:
1496 if (file_type == WTAP_FILE_PCAP_NOKIA) {
1500 if (check_packet_size && packet_size < NOKIAATM_LEN) {
1502 * Uh-oh, the packet isn't big enough to even
1503 * have a pseudo-header.
1505 *err = WTAP_ERR_BAD_FILE;
1506 *err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1510 if (!pcap_read_nokiaatm_pseudoheader(fh,
1511 pseudo_header, err, err_info))
1512 return -1; /* Read error */
1514 phdr_len = NOKIAATM_LEN;
1519 if (check_packet_size && packet_size < SUNATM_LEN) {
1521 * Uh-oh, the packet isn't big enough to even
1522 * have a pseudo-header.
1524 *err = WTAP_ERR_BAD_FILE;
1525 *err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1529 if (!pcap_read_sunatm_pseudoheader(fh,
1530 pseudo_header, err, err_info))
1531 return -1; /* Read error */
1533 phdr_len = SUNATM_LEN;
1537 case WTAP_ENCAP_ETHERNET:
1538 if (file_type == WTAP_FILE_PCAP_NOKIA) {
1540 * Nokia IPSO. Psuedo header has already been read, but it's not considered
1541 * part of the packet size, so reread it to store the data for later (when saving)
1543 if (!pcap_read_nokia_pseudoheader(fh, pseudo_header, err, err_info))
1544 return -1; /* Read error */
1548 * We don't know whether there's an FCS in this frame or not.
1550 pseudo_header->eth.fcs_len = -1;
1553 case WTAP_ENCAP_IEEE_802_11:
1554 case WTAP_ENCAP_IEEE_802_11_PRISM:
1555 case WTAP_ENCAP_IEEE_802_11_RADIOTAP:
1556 case WTAP_ENCAP_IEEE_802_11_AVS:
1558 * We don't know whether there's an FCS in this frame or not.
1559 * XXX - are there any OSes where the capture mechanism
1562 pseudo_header->ieee_802_11.fcs_len = -1;
1563 pseudo_header->ieee_802_11.decrypted = FALSE;
1564 pseudo_header->ieee_802_11.channel = 0;
1565 pseudo_header->ieee_802_11.data_rate = 0;
1566 pseudo_header->ieee_802_11.signal_level = 0;
1569 case WTAP_ENCAP_IRDA:
1570 if (check_packet_size && packet_size < IRDA_SLL_LEN) {
1572 * Uh-oh, the packet isn't big enough to even
1573 * have a pseudo-header.
1575 *err = WTAP_ERR_BAD_FILE;
1576 *err_info = g_strdup_printf("pcap: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
1580 if (!pcap_read_irda_pseudoheader(fh, pseudo_header,
1582 return -1; /* Read error */
1584 phdr_len = IRDA_SLL_LEN;
1587 case WTAP_ENCAP_MTP2_WITH_PHDR:
1588 if (check_packet_size && packet_size < MTP2_HDR_LEN) {
1590 * Uh-oh, the packet isn't big enough to even
1591 * have a pseudo-header.
1593 *err = WTAP_ERR_BAD_FILE;
1594 *err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
1598 if (!pcap_read_mtp2_pseudoheader(fh, pseudo_header,
1600 return -1; /* Read error */
1602 phdr_len = MTP2_HDR_LEN;
1605 case WTAP_ENCAP_LINUX_LAPD:
1606 if (check_packet_size && packet_size < LAPD_SLL_LEN) {
1608 * Uh-oh, the packet isn't big enough to even
1609 * have a pseudo-header.
1611 *err = WTAP_ERR_BAD_FILE;
1612 *err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
1616 if (!pcap_read_lapd_pseudoheader(fh, pseudo_header,
1618 return -1; /* Read error */
1620 phdr_len = LAPD_SLL_LEN;
1623 case WTAP_ENCAP_SITA:
1624 if (check_packet_size && packet_size < SITA_HDR_LEN) {
1626 * Uh-oh, the packet isn't big enough to even
1627 * have a pseudo-header.
1629 *err = WTAP_ERR_BAD_FILE;
1630 *err_info = g_strdup_printf("pcap: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
1634 if (!pcap_read_sita_pseudoheader(fh, pseudo_header,
1636 return -1; /* Read error */
1638 phdr_len = SITA_HDR_LEN;
1641 case WTAP_ENCAP_BLUETOOTH_H4:
1642 /* We don't have pseudoheader, so just pretend we received everything. */
1643 pseudo_header->p2p.sent = FALSE;
1646 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1647 if (check_packet_size &&
1648 packet_size < sizeof (struct libpcap_bt_phdr)) {
1650 * Uh-oh, the packet isn't big enough to even
1651 * have a pseudo-header.
1653 *err = WTAP_ERR_BAD_FILE;
1654 *err_info = g_strdup_printf("pcap: libpcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
1658 if (!pcap_read_bt_pseudoheader(fh,
1659 pseudo_header, err, err_info))
1660 return -1; /* Read error */
1662 phdr_len = (int)sizeof (struct libpcap_bt_phdr);
1665 case WTAP_ENCAP_NFC_LLCP:
1666 if (check_packet_size && packet_size < LLCP_HEADER_LEN) {
1667 *err = WTAP_ERR_BAD_FILE;
1668 *err_info = g_strdup_printf("pcap: libpcap llcp file too short");
1671 if (!pcap_read_llcp_pseudoheader(fh, pseudo_header, err, err_info))
1672 return -1; /* Read error */
1673 phdr_len = LLCP_HEADER_LEN;
1676 case WTAP_ENCAP_PPP_WITH_PHDR:
1677 if (check_packet_size &&
1678 packet_size < sizeof (struct libpcap_ppp_phdr)) {
1680 * Uh-oh, the packet isn't big enough to even
1681 * have a pseudo-header.
1683 *err = WTAP_ERR_BAD_FILE;
1684 *err_info = g_strdup_printf("pcap: libpcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
1688 if (!pcap_read_ppp_pseudoheader(fh,
1689 pseudo_header, err, err_info))
1690 return -1; /* Read error */
1692 phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
1695 case WTAP_ENCAP_ERF:
1696 if (check_packet_size &&
1697 packet_size < sizeof(struct erf_phdr) ) {
1699 * Uh-oh, the packet isn't big enough to even
1700 * have a pseudo-header.
1702 *err = WTAP_ERR_BAD_FILE;
1703 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
1708 if (!pcap_read_erf_pseudoheader(fh, phdr, pseudo_header,
1710 return -1; /* Read error */
1712 phdr_len = (int)sizeof(struct erf_phdr);
1714 /* check the optional Extension header */
1715 if (!pcap_read_erf_exheader(fh, pseudo_header, err, err_info,
1717 return -1; /* Read error */
1721 /* check the optional Multi Channel header */
1722 if (!pcap_read_erf_subheader(fh, pseudo_header, err, err_info,
1724 return -1; /* Read error */
1728 if (check_packet_size &&
1729 packet_size < (guint)phdr_len) {
1731 * Uh-oh, the packet isn't big enough for the pseudo-
1734 *err = WTAP_ERR_BAD_FILE;
1735 *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)",
1736 packet_size, phdr_len);
1741 case WTAP_ENCAP_I2C:
1742 if (check_packet_size &&
1743 packet_size < sizeof (struct i2c_file_hdr)) {
1745 * Uh-oh, the packet isn't big enough to even
1746 * have a pseudo-header.
1748 *err = WTAP_ERR_BAD_FILE;
1749 *err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
1753 if (!pcap_read_i2c_pseudoheader(fh, pseudo_header,
1755 return -1; /* Read error */
1758 * Don't count the pseudo-header as part of the packet.
1760 phdr_len = (int)sizeof (struct i2c_file_hdr);
1768 pcap_read_post_process(int file_type, int wtap_encap,
1769 union wtap_pseudo_header *pseudo_header,
1770 guint8 *pd, guint packet_size, gboolean bytes_swapped, int fcs_len)
1772 switch (wtap_encap) {
1774 case WTAP_ENCAP_ATM_PDUS:
1775 if (file_type == WTAP_FILE_PCAP_NOKIA) {
1779 * Guess the traffic type based on the packet
1782 atm_guess_traffic_type(pd, packet_size, pseudo_header);
1787 * If this is ATM LANE traffic, try to guess what
1788 * type of LANE traffic it is based on the packet
1791 if (pseudo_header->atm.type == TRAF_LANE)
1792 atm_guess_lane_type(pd, packet_size,
1797 case WTAP_ENCAP_ETHERNET:
1798 pseudo_header->eth.fcs_len = fcs_len;
1801 case WTAP_ENCAP_USB_LINUX:
1802 pcap_process_linux_usb_pseudoheader(packet_size,
1803 bytes_swapped, FALSE, pd);
1806 case WTAP_ENCAP_USB_LINUX_MMAPPED:
1807 pcap_process_linux_usb_pseudoheader(packet_size,
1808 bytes_swapped, TRUE, pd);
1811 case WTAP_ENCAP_NETANALYZER:
1813 * Not strictly necessary, as the netANALYZER
1814 * dissector calls the "Ethernet with FCS"
1815 * dissector, but we might as well set it.
1817 pseudo_header->eth.fcs_len = 4;
1826 pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
1832 case WTAP_ENCAP_ATM_PDUS:
1833 hdrsize = SUNATM_LEN;
1836 case WTAP_ENCAP_IRDA:
1837 hdrsize = IRDA_SLL_LEN;
1840 case WTAP_ENCAP_MTP2_WITH_PHDR:
1841 hdrsize = MTP2_HDR_LEN;
1844 case WTAP_ENCAP_LINUX_LAPD:
1845 hdrsize = LAPD_SLL_LEN;
1848 case WTAP_ENCAP_SITA:
1849 hdrsize = SITA_HDR_LEN;
1852 case WTAP_ENCAP_ERF:
1853 hdrsize = (int)sizeof (struct erf_phdr);
1854 switch (pseudo_header->erf.phdr.type & 0x7F) {
1856 case ERF_TYPE_MC_HDLC:
1857 case ERF_TYPE_MC_RAW:
1858 case ERF_TYPE_MC_ATM:
1859 case ERF_TYPE_MC_RAW_CHANNEL:
1860 case ERF_TYPE_MC_AAL5:
1861 case ERF_TYPE_MC_AAL2:
1862 case ERF_TYPE_COLOR_MC_HDLC_POS:
1863 hdrsize += (int)sizeof(struct erf_mc_hdr);
1867 case ERF_TYPE_COLOR_ETH:
1868 case ERF_TYPE_DSM_COLOR_ETH:
1869 hdrsize += (int)sizeof(struct erf_eth_hdr);
1877 * Add in the lengths of the extension headers.
1879 if (pseudo_header->erf.phdr.type & 0x80) {
1880 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1881 guint8 erf_exhdr[8];
1885 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
1886 type = erf_exhdr[0];
1889 } while (type & 0x80 && i < max);
1893 case WTAP_ENCAP_I2C:
1894 hdrsize = (int)sizeof (struct i2c_file_hdr);
1897 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1898 hdrsize = (int)sizeof (struct libpcap_bt_phdr);
1901 case WTAP_ENCAP_PPP_WITH_PHDR:
1902 hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
1914 pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header,
1917 guint8 atm_hdr[SUNATM_LEN];
1918 guint8 irda_hdr[IRDA_SLL_LEN];
1919 guint8 lapd_hdr[LAPD_SLL_LEN];
1920 guint8 mtp2_hdr[MTP2_HDR_LEN];
1921 guint8 sita_hdr[SITA_HDR_LEN];
1922 guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
1923 struct i2c_file_hdr i2c_hdr;
1924 struct libpcap_bt_phdr bt_hdr;
1925 struct libpcap_ppp_phdr ppp_hdr;
1930 case WTAP_ENCAP_ATM_PDUS:
1932 * Write the ATM header.
1934 atm_hdr[SUNATM_FLAGS] =
1935 (pseudo_header->atm.channel == 0) ? 0x80 : 0x00;
1936 switch (pseudo_header->atm.aal) {
1938 case AAL_SIGNALLING:
1940 atm_hdr[SUNATM_FLAGS] |= 0x06;
1944 switch (pseudo_header->atm.type) {
1948 atm_hdr[SUNATM_FLAGS] |= 0x01;
1952 /* RFC 1483 LLC multiplexed traffic */
1953 atm_hdr[SUNATM_FLAGS] |= 0x02;
1958 atm_hdr[SUNATM_FLAGS] |= 0x05;
1963 atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi;
1964 phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci);
1965 if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err))
1967 wdh->bytes_dumped += sizeof(atm_hdr);
1970 case WTAP_ENCAP_IRDA:
1972 * Write the IrDA header.
1974 memset(irda_hdr, 0, sizeof(irda_hdr));
1975 phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET],
1976 pseudo_header->irda.pkttype);
1977 phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017);
1978 if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err))
1980 wdh->bytes_dumped += sizeof(irda_hdr);
1983 case WTAP_ENCAP_MTP2_WITH_PHDR:
1985 * Write the MTP2 header.
1987 memset(&mtp2_hdr, 0, sizeof(mtp2_hdr));
1988 mtp2_hdr[MTP2_SENT_OFFSET] = pseudo_header->mtp2.sent;
1989 mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET] = pseudo_header->mtp2.annex_a_used;
1990 phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET],
1991 pseudo_header->mtp2.link_number);
1992 if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err))
1994 wdh->bytes_dumped += sizeof(mtp2_hdr);
1997 case WTAP_ENCAP_LINUX_LAPD:
1999 * Write the LAPD header.
2001 memset(&lapd_hdr, 0, sizeof(lapd_hdr));
2002 phtons(&lapd_hdr[LAPD_SLL_PKTTYPE_OFFSET],
2003 pseudo_header->lapd.pkttype);
2004 phtons(&lapd_hdr[LAPD_SLL_PROTOCOL_OFFSET], ETH_P_LAPD);
2005 lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] =
2006 pseudo_header->lapd.we_network?0x01:0x00;
2007 if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err))
2009 wdh->bytes_dumped += sizeof(lapd_hdr);
2012 case WTAP_ENCAP_SITA:
2014 * Write the SITA header.
2016 memset(&sita_hdr, 0, sizeof(sita_hdr));
2017 sita_hdr[SITA_FLAGS_OFFSET] = pseudo_header->sita.sita_flags;
2018 sita_hdr[SITA_SIGNALS_OFFSET] = pseudo_header->sita.sita_signals;
2019 sita_hdr[SITA_ERRORS1_OFFSET] = pseudo_header->sita.sita_errors1;
2020 sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.sita_errors2;
2021 sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.sita_proto;
2022 if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err))
2024 wdh->bytes_dumped += sizeof(sita_hdr);
2027 case WTAP_ENCAP_ERF:
2029 * Write the ERF header.
2031 memset(&erf_hdr, 0, sizeof(erf_hdr));
2032 phtolell(&erf_hdr[0], pseudo_header->erf.phdr.ts);
2033 erf_hdr[8] = pseudo_header->erf.phdr.type;
2034 erf_hdr[9] = pseudo_header->erf.phdr.flags;
2035 phtons(&erf_hdr[10], pseudo_header->erf.phdr.rlen);
2036 phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr);
2037 phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen);
2038 size = sizeof(struct erf_phdr);
2040 switch(pseudo_header->erf.phdr.type & 0x7F) {
2041 case ERF_TYPE_MC_HDLC:
2042 case ERF_TYPE_MC_RAW:
2043 case ERF_TYPE_MC_ATM:
2044 case ERF_TYPE_MC_RAW_CHANNEL:
2045 case ERF_TYPE_MC_AAL5:
2046 case ERF_TYPE_MC_AAL2:
2047 case ERF_TYPE_COLOR_MC_HDLC_POS:
2048 phtonl(&erf_hdr[16], pseudo_header->erf.subhdr.mc_hdr);
2049 size += (int)sizeof(struct erf_mc_hdr);
2052 case ERF_TYPE_COLOR_ETH:
2053 case ERF_TYPE_DSM_COLOR_ETH:
2054 phtons(&erf_hdr[16], pseudo_header->erf.subhdr.eth_hdr);
2055 size += (int)sizeof(struct erf_eth_hdr);
2060 if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
2062 wdh->bytes_dumped += size;
2065 * Now write out the extension headers.
2067 if (pseudo_header->erf.phdr.type & 0x80) {
2068 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
2069 guint8 erf_exhdr[8];
2073 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
2074 type = erf_exhdr[0];
2075 if (!wtap_dump_file_write(wdh, erf_exhdr, 8, err))
2077 wdh->bytes_dumped += 8;
2079 } while (type & 0x80 && i < max);
2083 case WTAP_ENCAP_I2C:
2085 * Write the I2C header.
2087 memset(&i2c_hdr, 0, sizeof(i2c_hdr));
2088 i2c_hdr.bus = pseudo_header->i2c.bus |
2089 (pseudo_header->i2c.is_event ? 0x80 : 0x00);
2090 phtonl((guint8 *)&i2c_hdr.flags, pseudo_header->i2c.flags);
2091 if (!wtap_dump_file_write(wdh, &i2c_hdr, sizeof(i2c_hdr), err))
2093 wdh->bytes_dumped += sizeof(i2c_hdr);
2096 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
2097 bt_hdr.direction = GUINT32_TO_BE(pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV);
2098 if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err))
2100 wdh->bytes_dumped += sizeof bt_hdr;
2103 case WTAP_ENCAP_PPP_WITH_PHDR:
2104 ppp_hdr.direction = (pseudo_header->p2p.sent ? LIBPCAP_PPP_PHDR_SENT : LIBPCAP_PPP_PHDR_RECV);
2105 if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err))
2107 wdh->bytes_dumped += sizeof ppp_hdr;