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.
35 #include "file_wrappers.h"
38 #include "pcap-encap.h"
39 #include "pcap-common.h"
42 * Map link-layer types (LINKTYPE_ values) to Wiretap encapsulations.
45 * Either LBL NRG wasn't an adequate central registry (e.g., because of
46 * the slow rate of releases from them), or nobody bothered using them
47 * as a central registry, as many different groups have patched libpcap
48 * (and BPF, on the BSDs) to add new encapsulation types, and have ended
49 * up using the same DLT_ values for different encapsulation types.
51 * For those numerical encapsulation type values that everybody uses for
52 * the same encapsulation type (which inclues those that some platforms
53 * specify different DLT_ names for but don't appear to use), we map
54 * those values to the appropriate Wiretap values.
56 * For those numerical encapsulation type values that different libpcap
57 * variants use for different encapsulation types, we check what
58 * <pcap.h> defined to determine how to interpret them, so that we
59 * interpret them the way the libpcap with which we're building
60 * Wireshark/Wiretap interprets them (which, if it doesn't support
61 * them at all, means we don't support them either - any capture files
62 * using them are foreign, and we don't hazard a guess as to which
63 * platform they came from; we could, I guess, choose the most likely
66 * Note: if you need a new encapsulation type for libpcap files, do
67 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
68 * add a new encapsulation type by changing an existing entry;
69 * leave the existing entries alone.
71 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking for
72 * a new DLT_ value, and specifying the purpose of the new value. When
73 * you get the new DLT_ value, use that numerical value in the "dlt_value"
74 * field of "pcap_to_wtap_map[]".
80 } pcap_to_wtap_map[] = {
82 * These are the values that are almost certainly the same
83 * in all libpcaps (I've yet to find one where the values
84 * in question are used for some purpose other than the
85 * one below, but...), and that Wiretap and Wireshark
88 { 0, WTAP_ENCAP_NULL }, /* null encapsulation */
89 { 1, WTAP_ENCAP_ETHERNET },
90 { 6, WTAP_ENCAP_TOKEN_RING }, /* IEEE 802 Networks - assume token ring */
91 { 7, WTAP_ENCAP_ARCNET },
92 { 8, WTAP_ENCAP_SLIP },
93 { 9, WTAP_ENCAP_PPP },
94 #ifdef BIT_SWAPPED_MAC_ADDRS
95 { 10, WTAP_ENCAP_FDDI_BITSWAPPED },
97 { 10, WTAP_ENCAP_FDDI },
100 { 32, WTAP_ENCAP_REDBACK },
103 * 50 is DLT_PPP_SERIAL in NetBSD; it appears that DLT_PPP
104 * on BSD (at least according to standard tcpdump) has, as
105 * the first octet, an indication of whether the packet was
106 * transmitted or received (rather than having the standard
107 * PPP address value of 0xff), but that DLT_PPP_SERIAL puts
108 * a real live PPP header there, or perhaps a Cisco PPP header
109 * as per section 4.3.1 of RFC 1547 (implementations of this
110 * exist in various BSDs in "sys/net/if_spppsubr.c", and
111 * I think also exist either in standard Linux or in
112 * various Linux patches; the implementations show how to handle
113 * Cisco keepalive packets).
115 * However, I don't see any obvious place in FreeBSD "if_ppp.c"
116 * where anything other than the standard PPP header would be
117 * passed up. I see some stuff that sets the first octet
118 * to 0 for incoming and 1 for outgoing packets before applying
119 * a BPF filter to see whether to drop packets whose protocol
120 * field has the 0x8000 bit set, i.e. network control protocols -
121 * those are handed up to userland - but that code puts the
122 * address field back before passing the packet up.
124 * I also don't see anything immediately obvious that munges
125 * the address field for sync PPP, either.
127 * Wireshark currently assumes that if the first octet of a
128 * PPP frame is 0xFF, it's the address field and is followed
129 * by a control field and a 2-byte protocol, otherwise the
130 * address and control fields are absent and the frame begins
131 * with a protocol field. If we ever see a BSD/OS PPP
132 * capture, we'll have to handle it differently, and we may
133 * have to handle standard BSD captures differently if, in fact,
134 * they don't have 0xff 0x03 as the first two bytes - but, as per
135 * the two paragraphs preceding this, it's not clear that
136 * the address field *is* munged into an incoming/outgoing
137 * field when the packet is handed to the BPF device.
139 * For now, we just map DLT_PPP_SERIAL to WTAP_ENCAP_PPP, as
140 * we treat WTAP_ENCAP_PPP packets as if those beginning with
141 * 0xff have the standard RFC 1662 "PPP in HDLC-like Framing"
142 * 0xff 0x03 address/control header, and DLT_PPP_SERIAL frames
143 * appear to contain that unless they're Cisco frames (if we
144 * ever see a capture with them, we'd need to implement the
145 * RFC 1547 stuff, and the keepalive protocol stuff).
147 * We may have to distinguish between "PPP where if it doesn't
148 * begin with 0xff there's no HDLC encapsulation and the frame
149 * begins with the protocol field" (which is how we handle
150 * WTAP_ENCAP_PPP now) and "PPP where there's either HDLC
151 * encapsulation or Cisco PPP" (which is what DLT_PPP_SERIAL
154 * XXX - NetBSD has DLT_HDLC, which appears to be used for
155 * Cisco HDLC. Ideally, they should use DLT_PPP_SERIAL
156 * only for real live HDLC-encapsulated PPP, not for Cisco
159 { 50, WTAP_ENCAP_PPP },
162 * Used by NetBSD and OpenBSD pppoe(4).
164 { 51, WTAP_ENCAP_PPP_ETHER },
167 * Apparently used by the Axent Raptor firewall (now Symantec
168 * Enterprise Firewall).
169 * Thanks, Axent, for not reserving that type with tcpdump.org
170 * and not telling anybody about it.
172 { 99, WTAP_ENCAP_SYMANTEC },
175 * These are the values that libpcap 0.5 and later use in
176 * capture file headers, in an attempt to work around the
177 * confusion decried above, and that Wiretap and Wireshark
180 { 100, WTAP_ENCAP_ATM_RFC1483 },
181 { 101, WTAP_ENCAP_RAW_IP },
184 * More values used by libpcap 0.5 as DLT_ values and used by the
185 * current CVS version of libpcap in capture file headers.
186 * They are not yet handled in Wireshark.
187 * If we get a capture that contains them, we'll implement them.
189 { 102, WTAP_ENCAP_SLIP_BSDOS },
190 { 103, WTAP_ENCAP_PPP_BSDOS },
194 * These ones are handled in Wireshark, though.
196 { 104, WTAP_ENCAP_CHDLC }, /* Cisco HDLC */
197 { 105, WTAP_ENCAP_IEEE_802_11 }, /* IEEE 802.11 */
198 { 106, WTAP_ENCAP_LINUX_ATM_CLIP },
199 { 107, WTAP_ENCAP_FRELAY }, /* Frame Relay */
200 { 108, WTAP_ENCAP_NULL }, /* OpenBSD loopback */
201 { 109, WTAP_ENCAP_ENC }, /* OpenBSD IPSEC enc */
203 { 110, WTAP_ENCAP_LANE_802_3 },/* ATM LANE 802.3 */
204 { 111, WTAP_ENCAP_HIPPI }, /* NetBSD HIPPI */
206 { 112, WTAP_ENCAP_CHDLC }, /* NetBSD HDLC framing */
209 * Linux "cooked mode" captures, used by the current CVS version
212 * it could be a packet in Cisco's ERSPAN encapsulation which uses
213 * this number as well (why can't people stick to protocols when it
214 * comes to allocating/using DLT types).
216 { 113, WTAP_ENCAP_SLL }, /* Linux cooked capture */
218 { 114, WTAP_ENCAP_LOCALTALK }, /* Localtalk */
221 * The tcpdump.org version of libpcap uses 117, rather than 17,
222 * for OpenBSD packet filter logging, so as to avoid conflicting
223 * with DLT_LANE8023 in SuSE 6.3 libpcap.
225 { 117, WTAP_ENCAP_PFLOG },
227 { 118, WTAP_ENCAP_CISCO_IOS },
228 { 119, WTAP_ENCAP_IEEE_802_11_PRISM }, /* 802.11 plus Prism monitor mode radio header */
229 { 121, WTAP_ENCAP_HHDLC }, /* HiPath HDLC */
230 { 122, WTAP_ENCAP_IP_OVER_FC }, /* RFC 2625 IP-over-FC */
231 { 123, WTAP_ENCAP_ATM_PDUS }, /* SunATM */
232 { 127, WTAP_ENCAP_IEEE_802_11_RADIOTAP }, /* 802.11 plus radiotap radio header */
233 { 128, WTAP_ENCAP_TZSP }, /* Tazmen Sniffer Protocol */
234 { 129, WTAP_ENCAP_ARCNET_LINUX },
235 { 130, WTAP_ENCAP_JUNIPER_MLPPP }, /* Juniper MLPPP on ML-, LS-, AS- PICs */
236 { 131, WTAP_ENCAP_JUNIPER_MLFR }, /* Juniper MLFR (FRF.15) on ML-, LS-, AS- PICs */
237 { 133, WTAP_ENCAP_JUNIPER_GGSN},
239 * Values 132-134, 136 not listed here are reserved for use
240 * in Juniper hardware.
242 { 135, WTAP_ENCAP_JUNIPER_ATM2 }, /* various encapsulations captured on the ATM2 PIC */
243 { 137, WTAP_ENCAP_JUNIPER_ATM1 }, /* various encapsulations captured on the ATM1 PIC */
245 { 138, WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 },
246 /* Apple IP-over-IEEE 1394 */
248 { 139, WTAP_ENCAP_MTP2_WITH_PHDR },
249 { 140, WTAP_ENCAP_MTP2 },
250 { 141, WTAP_ENCAP_MTP3 },
251 { 142, WTAP_ENCAP_SCCP },
252 { 143, WTAP_ENCAP_DOCSIS },
253 { 144, WTAP_ENCAP_IRDA }, /* IrDA capture */
255 /* Reserved for private use. */
256 { 147, WTAP_ENCAP_USER0 },
257 { 148, WTAP_ENCAP_USER1 },
258 { 149, WTAP_ENCAP_USER2 },
259 { 150, WTAP_ENCAP_USER3 },
260 { 151, WTAP_ENCAP_USER4 },
261 { 152, WTAP_ENCAP_USER5 },
262 { 153, WTAP_ENCAP_USER6 },
263 { 154, WTAP_ENCAP_USER7 },
264 { 155, WTAP_ENCAP_USER8 },
265 { 156, WTAP_ENCAP_USER9 },
266 { 157, WTAP_ENCAP_USER10 },
267 { 158, WTAP_ENCAP_USER11 },
268 { 159, WTAP_ENCAP_USER12 },
269 { 160, WTAP_ENCAP_USER13 },
270 { 161, WTAP_ENCAP_USER14 },
271 { 162, WTAP_ENCAP_USER15 },
273 { 163, WTAP_ENCAP_IEEE_802_11_AVS }, /* 802.11 plus AVS radio header */
276 * 164 is reserved for Juniper-private chassis-internal
277 * meta-information such as QoS profiles, etc..
280 { 165, WTAP_ENCAP_BACNET_MS_TP },
283 * 166 is reserved for a PPP variant in which the first byte
284 * of the 0xff03 header, the 0xff, is replaced by a direction
285 * byte. I don't know whether any captures look like that,
286 * but it is used for some Linux IP filtering (ipfilter?).
289 /* Ethernet PPPoE frames captured on a service PIC */
290 { 167, WTAP_ENCAP_JUNIPER_PPPOE },
293 * 168 is reserved for more Juniper private-chassis-
294 * internal meta-information.
297 { 169, WTAP_ENCAP_GPRS_LLC },
300 * 170 and 171 are reserved for ITU-T G.7041/Y.1303 Generic
304 /* Registered by Gcom, Inc. */
305 { 172, WTAP_ENCAP_GCOM_TIE1 },
306 { 173, WTAP_ENCAP_GCOM_SERIAL },
308 { 177, WTAP_ENCAP_LINUX_LAPD },
310 /* Ethernet frames prepended with meta-information */
311 { 178, WTAP_ENCAP_JUNIPER_ETHER },
312 /* PPP frames prepended with meta-information */
313 { 179, WTAP_ENCAP_JUNIPER_PPP },
314 /* Frame-Relay frames prepended with meta-information */
315 { 180, WTAP_ENCAP_JUNIPER_FRELAY },
316 /* C-HDLC frames prepended with meta-information */
317 { 181, WTAP_ENCAP_JUNIPER_CHDLC },
318 /* VOIP Frames prepended with meta-information */
319 { 183, WTAP_ENCAP_JUNIPER_VP },
320 /* raw USB packets */
321 { 186, WTAP_ENCAP_USB },
322 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
323 { 187, WTAP_ENCAP_BLUETOOTH_H4 },
324 /* IEEE 802.16 MAC Common Part Sublayer */
325 { 188, WTAP_ENCAP_IEEE802_16_MAC_CPS },
326 /* USB packets with Linux-specified header */
327 { 189, WTAP_ENCAP_USB_LINUX },
329 { 190, WTAP_ENCAP_CAN20B },
330 /* Per-Packet Information header */
331 { 192, WTAP_ENCAP_PPI },
332 /* IEEE 802.15.4 Wireless PAN */
333 { 195, WTAP_ENCAP_IEEE802_15_4 },
334 /* SITA File Encapsulation */
335 { 196, WTAP_ENCAP_SITA },
336 /* Endace Record File Encapsulation */
337 { 197, WTAP_ENCAP_ERF },
339 { 199, WTAP_ENCAP_IPMB },
340 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
341 { 201, WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR },
343 { 203, WTAP_ENCAP_LAPD },
344 /* PPP with pseudoheader */
345 { 204, WTAP_ENCAP_PPP_WITH_PHDR },
347 { 209, WTAP_ENCAP_I2C },
349 { 210, WTAP_ENCAP_FLEXRAY },
351 { 211, WTAP_ENCAP_MOST },
353 { 212, WTAP_ENCAP_LIN },
354 /* X2E Xoraya serial frame */
355 { 213, WTAP_ENCAP_X2E_SERIAL },
356 /* X2E Xoraya frame */
357 { 214, WTAP_ENCAP_X2E_XORAYA },
358 /* IEEE 802.15.4 Wireless PAN non-ASK PHY */
359 { 215, WTAP_ENCAP_IEEE802_15_4_NONASK_PHY },
360 /* USB packets with padded Linux-specified header */
361 { 220, WTAP_ENCAP_USB_LINUX_MMAPPED },
362 /* Fibre Channel FC-2 frame */
363 { 224, WTAP_ENCAP_FIBRE_CHANNEL_FC2 },
364 /* Fibre Channel FC-2 frame with Delimiter */
365 { 225, WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS },
367 { 226, WTAP_ENCAP_IPNET },
368 /* SocketCAN frame */
369 { 227, WTAP_ENCAP_SOCKETCAN },
371 { 228, WTAP_ENCAP_RAW_IP4 },
373 { 229, WTAP_ENCAP_RAW_IP6 },
374 /* IEEE 802.15.4 Wireless PAN no fcs */
375 { 230, WTAP_ENCAP_IEEE802_15_4_NOFCS },
377 { 231, WTAP_ENCAP_DBUS },
378 /* DVB-CI (Common Interface) */
379 { 235, WTAP_ENCAP_DVBCI },
381 { 236, WTAP_ENCAP_MUX27010 },
383 { 239, WTAP_ENCAP_NFLOG },
384 /* netANALYZER pseudo-header followed by Ethernet with CRC */
385 { 240, WTAP_ENCAP_NETANALYZER },
386 /* netANALYZER pseudo-header in transparent mode */
387 { 241, WTAP_ENCAP_NETANALYZER_TRANSPARENT },
388 /* IP-over-Infiniband, as specified by RFC 4391 section 6 */
389 { 242, WTAP_ENCAP_IP_OVER_IB },
390 /* ISO/IEC 13818-1 MPEG2-TS packets */
391 { 243, WTAP_ENCAP_MPEG_2_TS },
393 { 245, WTAP_ENCAP_NFC_LLCP },
398 * If you need a new encapsulation type for libpcap files, do
399 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
400 * add a new encapsulation type by changing an existing entry;
401 * leave the existing entries alone.
403 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
404 * for a new DLT_ value, and specifying the purpose of the new value.
405 * When you get the new DLT_ value, use that numerical value in
406 * the "dlt_value" field of "pcap_to_wtap_map[]".
410 * The following are entries for libpcap type values that have
411 * different meanings on different OSes.
413 * We put these *after* the entries for the platform-independent
414 * libpcap type values for those Wiretap encapsulation types, so
415 * that Wireshark chooses the platform-independent libpcap type
416 * value for those encapsulatioin types, not the platform-dependent
421 * 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
422 * seen that define anything other than DLT_ATM_RFC1483 as 11 are
423 * the BSD/OS one, which defines DLT_FR as 11, and libpcap 0.5,
424 * which define it as 100, mapping the kernel's value to 100, in
425 * an attempt to hide the different values used on different
428 * If this is a platform where DLT_FR is defined as 11, we
429 * don't handle 11 at all; otherwise, we handle it as
430 * DLT_ATM_RFC1483 (this means we'd misinterpret Frame Relay
431 * captures from BSD/OS if running on platforms other than BSD/OS,
434 * 1) we don't yet support DLT_FR
438 * 2) nothing short of a heuristic would let us interpret
441 #if defined(DLT_FR) && (DLT_FR == 11)
442 { 11, WTAP_ENCAP_FRELAY },
444 { 11, WTAP_ENCAP_ATM_RFC1483 },
448 * 12 is DLT_RAW on most platforms, but it's DLT_C_HDLC on
449 * BSD/OS, and DLT_LOOP on OpenBSD.
451 * We don't yet handle DLT_C_HDLC, but we can handle DLT_LOOP
452 * (it's just like DLT_NULL, only with the AF_ value in network
453 * rather than host byte order - Wireshark figures out the
454 * byte order from the data, so we don't care what byte order
455 * it's in), so if DLT_LOOP is defined as 12, interpret 12
456 * as WTAP_ENCAP_NULL, otherwise, unless DLT_C_HDLC is defined
457 * as 12, interpret it as WTAP_ENCAP_RAW_IP.
459 #if defined(DLT_LOOP) && (DLT_LOOP == 12)
460 { 12, WTAP_ENCAP_NULL },
461 #elif defined(DLT_C_HDLC) && (DLT_C_HDLC == 12)
463 * Put entry for Cisco HDLC here.
464 * XXX - is this just WTAP_ENCAP_CHDLC, i.e. does the frame
465 * start with a 4-byte Cisco HDLC header?
468 { 12, WTAP_ENCAP_RAW_IP },
472 * 13 is DLT_SLIP_BSDOS on FreeBSD and NetBSD, but those OSes
473 * don't actually generate it. I infer that BSD/OS translates
474 * DLT_SLIP from the kernel BPF code to DLT_SLIP_BSDOS in
475 * libpcap, as the BSD/OS link-layer header is different;
476 * however, in BSD/OS, DLT_SLIP_BSDOS is 15.
478 * From this, I infer that there's no point in handling 13
481 * 13 is DLT_ATM_RFC1483 on BSD/OS.
483 * 13 is DLT_ENC in OpenBSD, which is, I suspect, some kind
484 * of decrypted IPsec traffic.
486 * We treat 13 as WTAP_ENCAP_ENC on all systems except those
487 * that define DLT_ATM_RFC1483 as 13 - presumably only
488 * BSD/OS does so - so that, on BSD/OS systems, we still
489 * treate 13 as WTAP_ENCAP_ATM_RFC1483, but, on all other
490 * systems, we can read OpenBSD DLT_ENC captures.
492 #if defined(DLT_ATM_RFC1483) && (DLT_ATM_RFC1483 == 13)
493 { 13, WTAP_ENCAP_ATM_RFC1483 },
495 { 13, WTAP_ENCAP_ENC },
499 * 14 is DLT_PPP_BSDOS on FreeBSD and NetBSD, but those OSes
500 * don't actually generate it. I infer that BSD/OS translates
501 * DLT_PPP from the kernel BPF code to DLT_PPP_BSDOS in
502 * libpcap, as the BSD/OS link-layer header is different;
503 * however, in BSD/OS, DLT_PPP_BSDOS is 16.
505 * From this, I infer that there's no point in handling 14
508 * 14 is DLT_RAW on BSD/OS and OpenBSD.
510 { 14, WTAP_ENCAP_RAW_IP },
515 * DLT_SLIP_BSDOS on BSD/OS;
517 * DLT_HIPPI on NetBSD;
519 * DLT_LANE8023 with Alexey Kuznetzov's patches for
522 * DLT_I4L_RAWIP with the ISDN4Linux patches for libpcap
525 * but we don't currently handle any of those.
531 * DLT_PPP_BSDOS on BSD/OS;
533 * DLT_HDLC on NetBSD (Cisco HDLC);
535 * DLT_CIP with Alexey Kuznetzov's patches for
536 * Linux libpcap - this is WTAP_ENCAP_LINUX_ATM_CLIP;
538 * DLT_I4L_IP with the ISDN4Linux patches for libpcap
541 #if defined(DLT_CIP) && (DLT_CIP == 16)
542 { 16, WTAP_ENCAP_LINUX_ATM_CLIP },
544 #if defined(DLT_HDLC) && (DLT_HDLC == 16)
545 { 16, WTAP_ENCAP_CHDLC },
549 * 17 is DLT_LANE8023 in SuSE 6.3 libpcap; we don't currently
551 * It is also used as the PF (Packet Filter) logging format beginning
552 * with OpenBSD 3.0; we use 17 for PF logs unless DLT_LANE8023 is
553 * defined with the value 17.
555 #if !defined(DLT_LANE8023) || (DLT_LANE8023 != 17)
556 { 17, WTAP_ENCAP_OLD_PFLOG },
560 * 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
561 * DLT_CIP of 16 that the Alexey Kuznetzov patches for
562 * libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
563 * I've not found any libpcap that uses it for any other purpose -
564 * hopefully nobody will do so in the future.
566 { 18, WTAP_ENCAP_LINUX_ATM_CLIP },
569 * 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
570 * recent versions I've seen of the Linux ATM distribution;
571 * I've not yet found any libpcap that uses it for any other
572 * purpose - hopefully nobody will do so in the future.
574 { 19, WTAP_ENCAP_LINUX_ATM_CLIP },
579 * If you need a new encapsulation type for libpcap files, do
580 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
581 * add a new encapsulation type by changing an existing entry;
582 * leave the existing entries alone.
584 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
585 * for a new DLT_ value, and specifying the purpose of the new value.
586 * When you get the new DLT_ value, use that numerical value in
587 * the "dlt_value" field of "pcap_to_wtap_map[]".
590 #define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0])
593 wtap_pcap_encap_to_wtap_encap(int encap)
597 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
598 if (pcap_to_wtap_map[i].dlt_value == encap)
599 return pcap_to_wtap_map[i].wtap_encap_value;
601 return WTAP_ENCAP_UNKNOWN;
605 wtap_wtap_encap_to_pcap_encap(int encap)
611 case WTAP_ENCAP_FDDI:
612 case WTAP_ENCAP_FDDI_BITSWAPPED:
613 case WTAP_ENCAP_NETTL_FDDI:
615 * Special-case WTAP_ENCAP_FDDI and
616 * WTAP_ENCAP_FDDI_BITSWAPPED; both of them get mapped
617 * to DLT_FDDI (even though that may mean that the bit
618 * order in the FDDI MAC addresses is wrong; so it goes
619 * - libpcap format doesn't record the byte order,
620 * so that's not fixable).
622 return 10; /* that's DLT_FDDI */
624 case WTAP_ENCAP_FRELAY_WITH_PHDR:
626 * Do the same with Frame Relay.
630 case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
632 * Map this to DLT_IEEE802_11, for now, even though
633 * that means the radio information will be lost.
634 * Once tcpdump support for the BSD radiotap header
635 * is sufficiently widespread, we should probably
636 * use that, instead - although we should probably
637 * ultimately just have WTAP_ENCAP_IEEE_802_11
638 * as the only Wiretap encapsulation for 802.11,
639 * and have the pseudo-header include a radiotap-style
640 * list of attributes. If we do that, though, we
641 * should probably bypass the regular Wiretap code
642 * when writing out packets during a capture, and just
643 * do the equivalent of a libpcap write (unfortunately,
644 * libpcap doesn't have an "open dump by file descriptor"
645 * function, so we can't just use "pcap_dump()"), so
646 * that we don't spend cycles mapping from libpcap to
647 * Wiretap and then back to libpcap. (There are other
648 * reasons to do that, e.g. to handle AIX libpcap better.)
653 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
654 if (pcap_to_wtap_map[i].wtap_encap_value == encap)
655 return pcap_to_wtap_map[i].dlt_value;
661 * Various pseudo-headers that appear at the beginning of packet data.
663 * We represent them as sets of offsets, as they might not be aligned on
664 * an appropriate structure boundary in the buffer, and as that makes them
665 * independent of the way the compiler might align fields.
669 * The link-layer header on SunATM packets.
671 #define SUNATM_FLAGS 0 /* destination and traffic type - 1 byte */
672 #define SUNATM_VPI 1 /* VPI - 1 byte */
673 #define SUNATM_VCI 2 /* VCI - 2 bytes */
674 #define SUNATM_LEN 4 /* length of the header */
677 * The link-layer header on Nokia IPSO ATM packets.
679 #define NOKIAATM_FLAGS 0 /* destination - 1 byte */
680 #define NOKIAATM_VPI 1 /* VPI - 1 byte */
681 #define NOKIAATM_VCI 2 /* VCI - 2 bytes */
682 #define NOKIAATM_LEN 4 /* length of the header */
685 * The link-layer header on Nokia IPSO packets.
687 #define NOKIA_LEN 4 /* length of the header */
690 * The fake link-layer header of IrDA packets as introduced by Jean Tourrilhes
693 #define IRDA_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
694 /* 12 unused bytes */
695 #define IRDA_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
696 #define IRDA_SLL_LEN 16 /* length of the header */
699 * A header containing additional MTP information.
701 #define MTP2_SENT_OFFSET 0 /* 1 byte */
702 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
703 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
704 #define MTP2_HDR_LEN 4 /* length of the header */
707 * A header containing additional SITA WAN information.
709 #define SITA_FLAGS_OFFSET 0 /* 1 byte */
710 #define SITA_SIGNALS_OFFSET 1 /* 1 byte */
711 #define SITA_ERRORS1_OFFSET 2 /* 1 byte */
712 #define SITA_ERRORS2_OFFSET 3 /* 1 byte */
713 #define SITA_PROTO_OFFSET 4 /* 1 byte */
714 #define SITA_HDR_LEN 5 /* length of the header */
717 * The fake link-layer header of LAPD packets.
720 #define ETH_P_LAPD 0x0030
723 #define LAPD_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
724 #define LAPD_SLL_HATYPE_OFFSET 2 /* hardware address type - 2 bytes */
725 #define LAPD_SLL_HALEN_OFFSET 4 /* hardware address length - 2 bytes */
726 #define LAPD_SLL_ADDR_OFFSET 6 /* address - 8 bytes */
727 #define LAPD_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
728 #define LAPD_SLL_LEN 16 /* length of the header */
731 * The NFC LLCP per-packet header.
733 #define LLCP_ADAPTER_OFFSET 0
734 #define LLCP_FLAGS_OFFSET 1
735 #define LLCP_HEADER_LEN 2
738 * I2C link-layer on-disk format
740 struct i2c_file_hdr {
746 pcap_read_sunatm_pseudoheader(FILE_T fh,
747 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
749 guint8 atm_phdr[SUNATM_LEN];
754 errno = WTAP_ERR_CANT_READ;
755 bytes_read = file_read(atm_phdr, SUNATM_LEN, fh);
756 if (bytes_read != SUNATM_LEN) {
757 *err = file_error(fh, err_info);
759 *err = WTAP_ERR_SHORT_READ;
763 vpi = atm_phdr[SUNATM_VPI];
764 vci = pntohs(&atm_phdr[SUNATM_VCI]);
766 switch (atm_phdr[SUNATM_FLAGS] & 0x0F) {
768 case 0x01: /* LANE */
769 pseudo_header->atm.aal = AAL_5;
770 pseudo_header->atm.type = TRAF_LANE;
773 case 0x02: /* RFC 1483 LLC multiplexed traffic */
774 pseudo_header->atm.aal = AAL_5;
775 pseudo_header->atm.type = TRAF_LLCMX;
778 case 0x05: /* ILMI */
779 pseudo_header->atm.aal = AAL_5;
780 pseudo_header->atm.type = TRAF_ILMI;
783 case 0x06: /* Q.2931 */
784 pseudo_header->atm.aal = AAL_SIGNALLING;
785 pseudo_header->atm.type = TRAF_UNKNOWN;
788 case 0x03: /* MARS (RFC 2022) */
789 pseudo_header->atm.aal = AAL_5;
790 pseudo_header->atm.type = TRAF_UNKNOWN;
793 case 0x04: /* IFMP (Ipsilon Flow Management Protocol; see RFC 1954) */
794 pseudo_header->atm.aal = AAL_5;
795 pseudo_header->atm.type = TRAF_UNKNOWN; /* XXX - TRAF_IPSILON? */
800 * Assume it's AAL5, unless it's VPI 0 and VCI 5, in which
801 * case assume it's AAL_SIGNALLING; we know nothing more
804 * XXX - is this necessary? Or are we guaranteed that
805 * all signalling traffic has a type of 0x06?
807 * XXX - is this guaranteed to be AAL5? Or, if the type is
808 * 0x00 ("raw"), might it be non-AAL5 traffic?
810 if (vpi == 0 && vci == 5)
811 pseudo_header->atm.aal = AAL_SIGNALLING;
813 pseudo_header->atm.aal = AAL_5;
814 pseudo_header->atm.type = TRAF_UNKNOWN;
817 pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
819 pseudo_header->atm.vpi = vpi;
820 pseudo_header->atm.vci = vci;
821 pseudo_header->atm.channel = (atm_phdr[SUNATM_FLAGS] & 0x80) ? 0 : 1;
823 /* We don't have this information */
824 pseudo_header->atm.flags = 0;
825 pseudo_header->atm.cells = 0;
826 pseudo_header->atm.aal5t_u2u = 0;
827 pseudo_header->atm.aal5t_len = 0;
828 pseudo_header->atm.aal5t_chksum = 0;
834 pcap_read_nokiaatm_pseudoheader(FILE_T fh,
835 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
837 guint8 atm_phdr[NOKIAATM_LEN];
842 errno = WTAP_ERR_CANT_READ;
843 bytes_read = file_read(atm_phdr, NOKIAATM_LEN, fh);
844 if (bytes_read != NOKIAATM_LEN) {
845 *err = file_error(fh, err_info);
847 *err = WTAP_ERR_SHORT_READ;
851 vpi = atm_phdr[NOKIAATM_VPI];
852 vci = pntohs(&atm_phdr[NOKIAATM_VCI]);
854 pseudo_header->atm.vpi = vpi;
855 pseudo_header->atm.vci = vci;
856 pseudo_header->atm.channel = (atm_phdr[NOKIAATM_FLAGS] & 0x80) ? 0 : 1;
858 /* We don't have this information */
859 pseudo_header->atm.flags = 0;
860 pseudo_header->atm.cells = 0;
861 pseudo_header->atm.aal5t_u2u = 0;
862 pseudo_header->atm.aal5t_len = 0;
863 pseudo_header->atm.aal5t_chksum = 0;
869 pcap_read_nokia_pseudoheader(FILE_T fh,
870 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
872 guint8 phdr[NOKIA_LEN];
875 errno = WTAP_ERR_CANT_READ;
877 /* backtrack to read the 4 mysterious bytes that aren't considered
878 * part of the packet size
880 if (file_seek(fh, -NOKIA_LEN, SEEK_CUR, err) == -1)
882 *err = file_error(fh, err_info);
884 *err = WTAP_ERR_SHORT_READ;
888 bytes_read = file_read(phdr, NOKIA_LEN, fh);
889 if (bytes_read != NOKIA_LEN) {
890 *err = file_error(fh, err_info);
892 *err = WTAP_ERR_SHORT_READ;
896 memcpy(pseudo_header->nokia.stuff, phdr, NOKIA_LEN);
902 pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
903 int *err, gchar **err_info)
905 guint8 irda_phdr[IRDA_SLL_LEN];
908 errno = WTAP_ERR_CANT_READ;
909 bytes_read = file_read(irda_phdr, IRDA_SLL_LEN, fh);
910 if (bytes_read != IRDA_SLL_LEN) {
911 *err = file_error(fh, err_info);
913 *err = WTAP_ERR_SHORT_READ;
917 if (pntohs(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
918 *err = WTAP_ERR_BAD_FILE;
919 if (err_info != NULL)
920 *err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
924 pseudo_header->irda.pkttype = pntohs(&irda_phdr[IRDA_SLL_PKTTYPE_OFFSET]);
930 pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
932 guint8 mtp2_hdr[MTP2_HDR_LEN];
935 errno = WTAP_ERR_CANT_READ;
936 bytes_read = file_read(mtp2_hdr, MTP2_HDR_LEN, fh);
937 if (bytes_read != MTP2_HDR_LEN) {
938 *err = file_error(fh, err_info);
940 *err = WTAP_ERR_SHORT_READ;
944 pseudo_header->mtp2.sent = mtp2_hdr[MTP2_SENT_OFFSET];
945 pseudo_header->mtp2.annex_a_used = mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET];
946 pseudo_header->mtp2.link_number = pntohs(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET]);
952 pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
953 int *err, gchar **err_info)
955 guint8 lapd_phdr[LAPD_SLL_LEN];
958 errno = WTAP_ERR_CANT_READ;
959 bytes_read = file_read(lapd_phdr, LAPD_SLL_LEN, fh);
960 if (bytes_read != LAPD_SLL_LEN) {
961 *err = file_error(fh, err_info);
963 *err = WTAP_ERR_SHORT_READ;
967 if (pntohs(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
968 *err = WTAP_ERR_BAD_FILE;
969 if (err_info != NULL)
970 *err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
974 pseudo_header->lapd.pkttype = pntohs(&lapd_phdr[LAPD_SLL_PKTTYPE_OFFSET]);
975 pseudo_header->lapd.we_network = !!lapd_phdr[LAPD_SLL_ADDR_OFFSET+0];
981 pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
983 guint8 sita_phdr[SITA_HDR_LEN];
986 errno = WTAP_ERR_CANT_READ;
987 bytes_read = file_read(sita_phdr, SITA_HDR_LEN, fh);
988 if (bytes_read != SITA_HDR_LEN) {
989 *err = file_error(fh, err_info);
991 *err = WTAP_ERR_SHORT_READ;
995 pseudo_header->sita.sita_flags = sita_phdr[SITA_FLAGS_OFFSET];
996 pseudo_header->sita.sita_signals = sita_phdr[SITA_SIGNALS_OFFSET];
997 pseudo_header->sita.sita_errors1 = sita_phdr[SITA_ERRORS1_OFFSET];
998 pseudo_header->sita.sita_errors2 = sita_phdr[SITA_ERRORS2_OFFSET];
999 pseudo_header->sita.sita_proto = sita_phdr[SITA_PROTO_OFFSET];
1005 * When not using the memory-mapped interface to capture USB events,
1006 * code that reads those events can use the MON_IOCX_GET ioctl to
1007 * read a 48-byte header consisting of a "struct linux_usb_phdr", as
1008 * defined below, followed immediately by one of:
1010 * 8 bytes of a "struct usb_device_setup_hdr", if "setup_flag"
1011 * in the preceding "struct linux_usb_phdr" is 0;
1013 * in Linux 2.6.30 or later, 8 bytes of a "struct iso_rec", if
1014 * this is an isochronous transfer;
1016 * 8 bytes of junk, otherwise.
1018 * In Linux 2.6.31 and later, it can also use the MON_IOCX_GETX ioctl
1019 * to read a 64-byte header; that header consists of the 48 bytes
1020 * above, followed immediately by 16 bytes of a "struct linux_usb_phdr_ext",
1023 * In Linux 2.6.21 and later, there's a memory-mapped interface to
1024 * capture USB events. In that interface, the events in the memory-mapped
1025 * buffer have a 64-byte header, followed immediately by the data.
1026 * In Linux 2.6.21 through 2.6.30.x, the 64-byte header is the 48-byte
1027 * header described above, followed by 16 bytes of zeroes; in Linux
1028 * 2.6.31 and later, the 64-byte header is the 64-byte header described
1031 * See linux/Documentation/usb/usbmon.txt and libpcap/pcap/usb.h for details.
1033 * With WTAP_ENCAP_USB_LINUX, packets have the 48-byte header; with
1034 * WTAP_ENCAP_USB_LINUX_MMAPPED, they have the 64-byte header. There
1035 * is no indication of whether the header has the "struct iso_rec", or
1036 * whether the last 16 bytes of a 64-byte header are all zeros or are
1037 * a "struct linux_usb_phdr_ext".
1041 * URB transfer_type values
1043 #define URB_ISOCHRONOUS 0x0
1044 #define URB_INTERRUPT 0x1
1045 #define URB_CONTROL 0x2
1046 #define URB_BULK 0x3
1049 * Information from the URB for Isochronous transfers.
1051 * This structure is 8 bytes long.
1059 * Header prepended by Linux kernel to each USB event.
1061 * (Setup flag is '-', 'D', 'Z', or 0. Data flag is '<', '>', 'Z', or 0.)
1063 * The values are in *host* byte order.
1065 struct linux_usb_phdr {
1066 guint64 id; /* urb id, to link submission and completion events */
1067 guint8 event_type; /* Submit ('S'), Completed ('C'), Error ('E') */
1068 guint8 transfer_type; /* ISO (0), Intr, Control, Bulk (3) */
1069 guint8 endpoint_number; /* Endpoint number (0-15) and transfer direction */
1070 guint8 device_address; /* 0-127 */
1072 gint8 setup_flag; /* 0, if the urb setup header is meaningful */
1073 gint8 data_flag; /* 0, if urb data is present */
1077 guint32 urb_len; /* whole len of urb this event refers to */
1078 guint32 data_len; /* amount of urb data really present in this event */
1081 * Packet-type-dependent data.
1082 * USB setup information of setup_flag is true.
1083 * Otherwise, some isochronous transfer information.
1091 * This data is provided by Linux 2.6.31 and later kernels.
1093 * For WTAP_ENCAP_USB_LINUX, it's not in the pseudo-header, so
1094 * the pseudo-header is always 48 bytes long, including the
1095 * packet-type-dependent data.
1097 * For WTAP_ENCAP_USB_LINUX_MMAPPED, the pseudo-header is always
1098 * 64 bytes long, with the packet-type-dependent data preceding
1099 * these last 16 bytes. In pre-2.6.31 kernels, it's zero padding;
1100 * in 2.6.31 and later, it's the following data.
1102 gint32 interval; /* only for Interrupt and Isochronous events */
1103 gint32 start_frame; /* for Isochronous */
1104 guint32 xfer_flags; /* copy of URB's transfer_flags */
1105 guint32 ndesc; /* actual number of isochronous descriptors */
1108 struct linux_usb_isodesc {
1116 * USB setup header as defined in USB specification
1117 * See usb_20.pdf, Chapter 9.3 'USB Device Requests' for details.
1118 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
1120 * This structure is 8 bytes long.
1122 struct usb_device_setup_hdr {
1123 gint8 bmRequestType;
1132 * Offset of the *end* of a field within a particular structure.
1134 #define END_OFFSETOF(basep, fieldp) \
1135 (((char *)(void *)(fieldp)) - ((char *)(void *)(basep)) + \
1139 pcap_process_linux_usb_pseudoheader(guint packet_size, gboolean byte_swapped,
1140 gboolean header_len_64_bytes, guint8 *pd)
1142 struct linux_usb_phdr *phdr;
1143 struct linux_usb_isodesc *pisodesc;
1144 gint32 iso_numdesc, i;
1148 * Greasy hack, but we never directly direference any of
1149 * the fields in *phdr, we just get offsets of and
1150 * addresses of its members, so it's safe.
1152 phdr = (struct linux_usb_phdr *)(void *)pd;
1154 if (packet_size < END_OFFSETOF(phdr, &phdr->id))
1156 PBSWAP64((guint8 *)&phdr->id);
1157 if (packet_size < END_OFFSETOF(phdr, &phdr->bus_id))
1159 PBSWAP16((guint8 *)&phdr->bus_id);
1160 if (packet_size < END_OFFSETOF(phdr, &phdr->ts_sec))
1162 PBSWAP64((guint8 *)&phdr->ts_sec);
1163 if (packet_size < END_OFFSETOF(phdr, &phdr->ts_usec))
1165 PBSWAP32((guint8 *)&phdr->ts_usec);
1166 if (packet_size < END_OFFSETOF(phdr, &phdr->status))
1168 PBSWAP32((guint8 *)&phdr->status);
1169 if (packet_size < END_OFFSETOF(phdr, &phdr->urb_len))
1171 PBSWAP32((guint8 *)&phdr->urb_len);
1172 if (packet_size < END_OFFSETOF(phdr, &phdr->data_len))
1174 PBSWAP32((guint8 *)&phdr->data_len);
1176 if (phdr->transfer_type == URB_ISOCHRONOUS) {
1177 if (packet_size < END_OFFSETOF(phdr, &phdr->s.iso.error_count))
1179 PBSWAP32((guint8 *)&phdr->s.iso.error_count);
1181 if (packet_size < END_OFFSETOF(phdr, &phdr->s.iso.numdesc))
1183 PBSWAP32((guint8 *)&phdr->s.iso.numdesc);
1187 if (header_len_64_bytes) {
1189 * This is either the "version 1" header, with
1190 * 16 bytes of additional fields at the end, or
1191 * a "version 0" header from a memory-mapped
1192 * capture, with 16 bytes of zeroed-out padding
1193 * at the end. Byte swap them as if this were
1194 * a "version 1" header.
1196 * Yes, the first argument to END_OFFSETOF() should
1197 * be phdr, not phdr_ext; we want the offset of
1198 * the additional fields from the beginning of
1201 if (packet_size < END_OFFSETOF(phdr, &phdr->interval))
1203 PBSWAP32((guint8 *)&phdr->interval);
1204 if (packet_size < END_OFFSETOF(phdr, &phdr->start_frame))
1206 PBSWAP32((guint8 *)&phdr->start_frame);
1207 if (packet_size < END_OFFSETOF(phdr, &phdr->xfer_flags))
1209 PBSWAP32((guint8 *)&phdr->xfer_flags);
1210 if (packet_size < END_OFFSETOF(phdr, &phdr->ndesc))
1212 PBSWAP32((guint8 *)&phdr->ndesc);
1215 if (phdr->transfer_type == URB_ISOCHRONOUS) {
1216 /* swap the values in struct linux_usb_isodesc */
1219 * See previous "Greasy hack" comment.
1221 if (header_len_64_bytes) {
1222 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 64);
1224 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 48);
1226 iso_numdesc = phdr->s.iso.numdesc;
1227 for (i = 0; i < iso_numdesc; i++) {
1228 /* always check if we have enough data from the
1229 * beginnig of the packet (phdr)
1231 if (packet_size < END_OFFSETOF(phdr, &pisodesc->iso_status))
1233 PBSWAP32((guint8 *)&pisodesc->iso_status);
1234 if (packet_size < END_OFFSETOF(phdr, &pisodesc->iso_off))
1236 PBSWAP32((guint8 *)&pisodesc->iso_off);
1237 if (packet_size < END_OFFSETOF(phdr, &pisodesc->iso_len))
1239 PBSWAP32((guint8 *)&pisodesc->iso_len);
1240 if (packet_size < END_OFFSETOF(phdr, &pisodesc->_pad))
1242 PBSWAP32((guint8 *)&pisodesc->_pad);
1251 pcap_read_bt_pseudoheader(FILE_T fh,
1252 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1255 struct libpcap_bt_phdr phdr;
1257 errno = WTAP_ERR_CANT_READ;
1258 bytes_read = file_read(&phdr,
1259 sizeof (struct libpcap_bt_phdr), fh);
1260 if (bytes_read != sizeof (struct libpcap_bt_phdr)) {
1261 *err = file_error(fh, err_info);
1263 *err = WTAP_ERR_SHORT_READ;
1266 pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
1271 pcap_read_llcp_pseudoheader(FILE_T fh,
1272 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1275 guint8 phdr[LLCP_HEADER_LEN];
1277 errno = WTAP_ERR_CANT_READ;
1278 bytes_read = file_read(phdr, LLCP_HEADER_LEN, fh);
1279 if (bytes_read != LLCP_HEADER_LEN) {
1280 *err = file_error(fh, err_info);
1282 *err = WTAP_ERR_SHORT_READ;
1285 pseudo_header->llcp.adapter = phdr[LLCP_ADAPTER_OFFSET];
1286 pseudo_header->llcp.flags = phdr[LLCP_FLAGS_OFFSET];
1291 pcap_read_ppp_pseudoheader(FILE_T fh,
1292 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1295 struct libpcap_ppp_phdr phdr;
1297 errno = WTAP_ERR_CANT_READ;
1298 bytes_read = file_read(&phdr,
1299 sizeof (struct libpcap_ppp_phdr), fh);
1300 if (bytes_read != sizeof (struct libpcap_ppp_phdr)) {
1301 *err = file_error(fh, err_info);
1303 *err = WTAP_ERR_SHORT_READ;
1306 pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
1311 pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr,
1312 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1314 guint8 erf_hdr[sizeof(struct erf_phdr)];
1317 errno = WTAP_ERR_CANT_READ;
1318 bytes_read = file_read(erf_hdr, sizeof(struct erf_phdr), fh);
1319 if (bytes_read != sizeof(struct erf_phdr)) {
1320 *err = file_error(fh, err_info);
1322 *err = WTAP_ERR_SHORT_READ;
1325 pseudo_header->erf.phdr.ts = pletohll(&erf_hdr[0]); /* timestamp */
1326 pseudo_header->erf.phdr.type = erf_hdr[8];
1327 pseudo_header->erf.phdr.flags = erf_hdr[9];
1328 pseudo_header->erf.phdr.rlen = pntohs(&erf_hdr[10]);
1329 pseudo_header->erf.phdr.lctr = pntohs(&erf_hdr[12]);
1330 pseudo_header->erf.phdr.wlen = pntohs(&erf_hdr[14]);
1332 /* The high 32 bits of the timestamp contain the integer number of seconds
1333 * while the lower 32 bits contain the binary fraction of the second.
1334 * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */
1336 guint64 ts = pseudo_header->erf.phdr.ts;
1337 whdr->ts.secs = (guint32) (ts >> 32);
1338 ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000);
1339 ts += (ts & 0x80000000) << 1; /* rounding */
1340 whdr->ts.nsecs = ((guint32) (ts >> 32));
1341 if ( whdr->ts.nsecs >= 1000000000) {
1342 whdr->ts.nsecs -= 1000000000;
1350 * If the type of record given in the pseudo header indicate the presence of an extension
1351 * header then, read all the extension headers
1354 pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1355 int *err, gchar **err_info, guint * psize)
1358 guint8 erf_exhdr[8];
1359 guint64 erf_exhdr_sw;
1360 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1363 if (pseudo_header->erf.phdr.type & 0x80){
1365 errno = WTAP_ERR_CANT_READ;
1366 bytes_read = file_read(erf_exhdr, 8, fh);
1367 if (bytes_read != 8 ) {
1368 *err = file_error(fh, err_info);
1370 *err = WTAP_ERR_SHORT_READ;
1373 type = erf_exhdr[0];
1374 erf_exhdr_sw = pntohll(erf_exhdr);
1376 memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw));
1379 } while (type & 0x80);
1385 * If the type of record given in the pseudo header indicate the precense of a subheader
1386 * then, read this optional subheader
1389 pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1390 int *err, gchar **err_info, guint * psize)
1392 guint8 erf_subhdr[sizeof(union erf_subhdr)];
1396 switch(pseudo_header->erf.phdr.type & 0x7F) {
1397 case ERF_TYPE_MC_HDLC:
1398 case ERF_TYPE_MC_RAW:
1399 case ERF_TYPE_MC_ATM:
1400 case ERF_TYPE_MC_RAW_CHANNEL:
1401 case ERF_TYPE_MC_AAL5:
1402 case ERF_TYPE_MC_AAL2:
1403 case ERF_TYPE_COLOR_MC_HDLC_POS:
1404 /* Extract the Multi Channel header to include it in the pseudo header part */
1405 errno = WTAP_ERR_CANT_READ;
1406 bytes_read = file_read(erf_subhdr, sizeof(erf_mc_header_t), fh);
1407 if (bytes_read != sizeof(erf_mc_header_t) ) {
1408 *err = file_error(fh, err_info);
1410 *err = WTAP_ERR_SHORT_READ;
1413 pseudo_header->erf.subhdr.mc_hdr = pntohl(&erf_subhdr[0]);
1414 *psize = sizeof(erf_mc_header_t);
1417 case ERF_TYPE_COLOR_ETH:
1418 case ERF_TYPE_DSM_COLOR_ETH:
1419 /* Extract the Ethernet additional header to include it in the pseudo header part */
1420 errno = WTAP_ERR_CANT_READ;
1421 bytes_read = file_read(erf_subhdr, sizeof(erf_eth_header_t), fh);
1422 if (bytes_read != sizeof(erf_eth_header_t) ) {
1423 *err = file_error(fh, err_info);
1425 *err = WTAP_ERR_SHORT_READ;
1428 pseudo_header->erf.subhdr.eth_hdr = pntohs(&erf_subhdr[0]);
1429 *psize = sizeof(erf_eth_header_t);
1432 /* No optional pseudo header for this ERF type */
1439 pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1441 struct i2c_file_hdr i2c_hdr;
1444 errno = WTAP_ERR_CANT_READ;
1445 bytes_read = file_read(&i2c_hdr, sizeof (i2c_hdr), fh);
1446 if (bytes_read != sizeof (i2c_hdr)) {
1447 *err = file_error(fh, err_info);
1449 *err = WTAP_ERR_SHORT_READ;
1453 pseudo_header->i2c.is_event = i2c_hdr.bus & 0x80 ? 1 : 0;
1454 pseudo_header->i2c.bus = i2c_hdr.bus & 0x7f;
1455 pseudo_header->i2c.flags = pntohl(&i2c_hdr.flags);
1461 pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
1462 guint packet_size, gboolean check_packet_size, struct wtap_pkthdr *phdr,
1463 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1468 switch (wtap_encap) {
1470 case WTAP_ENCAP_ATM_PDUS:
1471 if (file_type == WTAP_FILE_PCAP_NOKIA) {
1475 if (check_packet_size && packet_size < NOKIAATM_LEN) {
1477 * Uh-oh, the packet isn't big enough to even
1478 * have a pseudo-header.
1480 *err = WTAP_ERR_BAD_FILE;
1481 *err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1485 if (!pcap_read_nokiaatm_pseudoheader(fh,
1486 pseudo_header, err, err_info))
1487 return -1; /* Read error */
1489 phdr_len = NOKIAATM_LEN;
1494 if (check_packet_size && packet_size < SUNATM_LEN) {
1496 * Uh-oh, the packet isn't big enough to even
1497 * have a pseudo-header.
1499 *err = WTAP_ERR_BAD_FILE;
1500 *err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1504 if (!pcap_read_sunatm_pseudoheader(fh,
1505 pseudo_header, err, err_info))
1506 return -1; /* Read error */
1508 phdr_len = SUNATM_LEN;
1512 case WTAP_ENCAP_ETHERNET:
1513 if (file_type == WTAP_FILE_PCAP_NOKIA) {
1515 * Nokia IPSO. Psuedo header has already been read, but its not considered
1516 * part of the packet size, so reread it to store the data for later (when saving)
1518 if (!pcap_read_nokia_pseudoheader(fh, pseudo_header, err, err_info))
1519 return -1; /* Read error */
1523 * We don't know whether there's an FCS in this frame or not.
1525 pseudo_header->eth.fcs_len = -1;
1528 case WTAP_ENCAP_IEEE_802_11:
1529 case WTAP_ENCAP_IEEE_802_11_PRISM:
1530 case WTAP_ENCAP_IEEE_802_11_RADIOTAP:
1531 case WTAP_ENCAP_IEEE_802_11_AVS:
1533 * We don't know whether there's an FCS in this frame or not.
1534 * XXX - are there any OSes where the capture mechanism
1537 pseudo_header->ieee_802_11.fcs_len = -1;
1538 pseudo_header->ieee_802_11.decrypted = FALSE;
1539 pseudo_header->ieee_802_11.channel = 0;
1540 pseudo_header->ieee_802_11.data_rate = 0;
1541 pseudo_header->ieee_802_11.signal_level = 0;
1544 case WTAP_ENCAP_IRDA:
1545 if (check_packet_size && packet_size < IRDA_SLL_LEN) {
1547 * Uh-oh, the packet isn't big enough to even
1548 * have a pseudo-header.
1550 *err = WTAP_ERR_BAD_FILE;
1551 *err_info = g_strdup_printf("pcap: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
1555 if (!pcap_read_irda_pseudoheader(fh, pseudo_header,
1557 return -1; /* Read error */
1559 phdr_len = IRDA_SLL_LEN;
1562 case WTAP_ENCAP_MTP2_WITH_PHDR:
1563 if (check_packet_size && packet_size < MTP2_HDR_LEN) {
1565 * Uh-oh, the packet isn't big enough to even
1566 * have a pseudo-header.
1568 *err = WTAP_ERR_BAD_FILE;
1569 *err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
1573 if (!pcap_read_mtp2_pseudoheader(fh, pseudo_header,
1575 return -1; /* Read error */
1577 phdr_len = MTP2_HDR_LEN;
1580 case WTAP_ENCAP_LINUX_LAPD:
1581 if (check_packet_size && packet_size < LAPD_SLL_LEN) {
1583 * Uh-oh, the packet isn't big enough to even
1584 * have a pseudo-header.
1586 *err = WTAP_ERR_BAD_FILE;
1587 *err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
1591 if (!pcap_read_lapd_pseudoheader(fh, pseudo_header,
1593 return -1; /* Read error */
1595 phdr_len = LAPD_SLL_LEN;
1598 case WTAP_ENCAP_SITA:
1599 if (check_packet_size && packet_size < SITA_HDR_LEN) {
1601 * Uh-oh, the packet isn't big enough to even
1602 * have a pseudo-header.
1604 *err = WTAP_ERR_BAD_FILE;
1605 *err_info = g_strdup_printf("pcap: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
1609 if (!pcap_read_sita_pseudoheader(fh, pseudo_header,
1611 return -1; /* Read error */
1613 phdr_len = SITA_HDR_LEN;
1616 case WTAP_ENCAP_BLUETOOTH_H4:
1617 /* We don't have pseudoheader, so just pretend we received everything. */
1618 pseudo_header->p2p.sent = FALSE;
1621 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1622 if (check_packet_size &&
1623 packet_size < sizeof (struct libpcap_bt_phdr)) {
1625 * Uh-oh, the packet isn't big enough to even
1626 * have a pseudo-header.
1628 *err = WTAP_ERR_BAD_FILE;
1629 *err_info = g_strdup_printf("pcap: libpcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
1633 if (!pcap_read_bt_pseudoheader(fh,
1634 pseudo_header, err, err_info))
1635 return -1; /* Read error */
1637 phdr_len = (int)sizeof (struct libpcap_bt_phdr);
1640 case WTAP_ENCAP_NFC_LLCP:
1641 if (check_packet_size && packet_size < LLCP_HEADER_LEN) {
1642 *err = WTAP_ERR_BAD_FILE;
1643 *err_info = g_strdup_printf("pcap: libpcap llcp file too short");
1646 if (!pcap_read_llcp_pseudoheader(fh, pseudo_header, err, err_info))
1647 return -1; /* Read error */
1648 phdr_len = LLCP_HEADER_LEN;
1651 case WTAP_ENCAP_PPP_WITH_PHDR:
1652 if (check_packet_size &&
1653 packet_size < sizeof (struct libpcap_ppp_phdr)) {
1655 * Uh-oh, the packet isn't big enough to even
1656 * have a pseudo-header.
1658 *err = WTAP_ERR_BAD_FILE;
1659 *err_info = g_strdup_printf("pcap: libpcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
1663 if (!pcap_read_ppp_pseudoheader(fh,
1664 pseudo_header, err, err_info))
1665 return -1; /* Read error */
1667 phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
1670 case WTAP_ENCAP_ERF:
1671 if (check_packet_size &&
1672 packet_size < sizeof(struct erf_phdr) ) {
1674 * Uh-oh, the packet isn't big enough to even
1675 * have a pseudo-header.
1677 *err = WTAP_ERR_BAD_FILE;
1678 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
1683 if (!pcap_read_erf_pseudoheader(fh, phdr, pseudo_header,
1685 return -1; /* Read error */
1687 phdr_len = (int)sizeof(struct erf_phdr);
1689 /* check the optional Extension header */
1690 if (!pcap_read_erf_exheader(fh, pseudo_header, err, err_info,
1692 return -1; /* Read error */
1696 /* check the optional Multi Channel header */
1697 if (!pcap_read_erf_subheader(fh, pseudo_header, err, err_info,
1699 return -1; /* Read error */
1703 if (check_packet_size &&
1704 packet_size < (guint)phdr_len) {
1706 * Uh-oh, the packet isn't big enough for the pseudo-
1709 *err = WTAP_ERR_BAD_FILE;
1710 *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)",
1711 packet_size, phdr_len);
1716 case WTAP_ENCAP_I2C:
1717 if (check_packet_size &&
1718 packet_size < sizeof (struct i2c_file_hdr)) {
1720 * Uh-oh, the packet isn't big enough to even
1721 * have a pseudo-header.
1723 *err = WTAP_ERR_BAD_FILE;
1724 *err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
1728 if (!pcap_read_i2c_pseudoheader(fh, pseudo_header,
1730 return -1; /* Read error */
1733 * Don't count the pseudo-header as part of the packet.
1735 phdr_len = (int)sizeof (struct i2c_file_hdr);
1743 pcap_read_post_process(int file_type, int wtap_encap,
1744 union wtap_pseudo_header *pseudo_header,
1745 guint8 *pd, guint packet_size, gboolean bytes_swapped, int fcs_len)
1747 switch (wtap_encap) {
1749 case WTAP_ENCAP_ATM_PDUS:
1750 if (file_type == WTAP_FILE_PCAP_NOKIA) {
1754 * Guess the traffic type based on the packet
1757 atm_guess_traffic_type(pd, packet_size, pseudo_header);
1762 * If this is ATM LANE traffic, try to guess what
1763 * type of LANE traffic it is based on the packet
1766 if (pseudo_header->atm.type == TRAF_LANE)
1767 atm_guess_lane_type(pd, packet_size,
1772 case WTAP_ENCAP_ETHERNET:
1773 pseudo_header->eth.fcs_len = fcs_len;
1776 case WTAP_ENCAP_USB_LINUX:
1777 pcap_process_linux_usb_pseudoheader(packet_size,
1778 bytes_swapped, FALSE, pd);
1781 case WTAP_ENCAP_USB_LINUX_MMAPPED:
1782 pcap_process_linux_usb_pseudoheader(packet_size,
1783 bytes_swapped, TRUE, pd);
1786 case WTAP_ENCAP_NETANALYZER:
1788 * Not strictly necessary, as the netANALYZER
1789 * dissector calls the "Ethernet with FCS"
1790 * dissector, but we might as well set it.
1792 pseudo_header->eth.fcs_len = 4;
1801 pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
1807 case WTAP_ENCAP_ATM_PDUS:
1808 hdrsize = SUNATM_LEN;
1811 case WTAP_ENCAP_IRDA:
1812 hdrsize = IRDA_SLL_LEN;
1815 case WTAP_ENCAP_MTP2_WITH_PHDR:
1816 hdrsize = MTP2_HDR_LEN;
1819 case WTAP_ENCAP_LINUX_LAPD:
1820 hdrsize = LAPD_SLL_LEN;
1823 case WTAP_ENCAP_SITA:
1824 hdrsize = SITA_HDR_LEN;
1827 case WTAP_ENCAP_ERF:
1828 hdrsize = (int)sizeof (struct erf_phdr);
1829 switch (pseudo_header->erf.phdr.type & 0x7F) {
1831 case ERF_TYPE_MC_HDLC:
1832 case ERF_TYPE_MC_RAW:
1833 case ERF_TYPE_MC_ATM:
1834 case ERF_TYPE_MC_RAW_CHANNEL:
1835 case ERF_TYPE_MC_AAL5:
1836 case ERF_TYPE_MC_AAL2:
1837 case ERF_TYPE_COLOR_MC_HDLC_POS:
1838 hdrsize += (int)sizeof(struct erf_mc_hdr);
1842 case ERF_TYPE_COLOR_ETH:
1843 case ERF_TYPE_DSM_COLOR_ETH:
1844 hdrsize += (int)sizeof(struct erf_eth_hdr);
1852 * Add in the lengths of the extension headers.
1854 if (pseudo_header->erf.phdr.type & 0x80) {
1855 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1856 guint8 erf_exhdr[8];
1860 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
1861 type = erf_exhdr[0];
1864 } while (type & 0x80 && i < max);
1868 case WTAP_ENCAP_I2C:
1869 hdrsize = (int)sizeof (struct i2c_file_hdr);
1872 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1873 hdrsize = (int)sizeof (struct libpcap_bt_phdr);
1876 case WTAP_ENCAP_PPP_WITH_PHDR:
1877 hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
1889 pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header,
1892 guint8 atm_hdr[SUNATM_LEN];
1893 guint8 irda_hdr[IRDA_SLL_LEN];
1894 guint8 lapd_hdr[LAPD_SLL_LEN];
1895 guint8 mtp2_hdr[MTP2_HDR_LEN];
1896 guint8 sita_hdr[SITA_HDR_LEN];
1897 guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
1898 struct i2c_file_hdr i2c_hdr;
1899 struct libpcap_bt_phdr bt_hdr;
1900 struct libpcap_ppp_phdr ppp_hdr;
1905 case WTAP_ENCAP_ATM_PDUS:
1907 * Write the ATM header.
1909 atm_hdr[SUNATM_FLAGS] =
1910 (pseudo_header->atm.channel == 0) ? 0x80 : 0x00;
1911 switch (pseudo_header->atm.aal) {
1913 case AAL_SIGNALLING:
1915 atm_hdr[SUNATM_FLAGS] |= 0x06;
1919 switch (pseudo_header->atm.type) {
1923 atm_hdr[SUNATM_FLAGS] |= 0x01;
1927 /* RFC 1483 LLC multiplexed traffic */
1928 atm_hdr[SUNATM_FLAGS] |= 0x02;
1933 atm_hdr[SUNATM_FLAGS] |= 0x05;
1938 atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi;
1939 phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci);
1940 if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err))
1942 wdh->bytes_dumped += sizeof(atm_hdr);
1945 case WTAP_ENCAP_IRDA:
1947 * Write the IrDA header.
1949 memset(irda_hdr, 0, sizeof(irda_hdr));
1950 phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET],
1951 pseudo_header->irda.pkttype);
1952 phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017);
1953 if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err))
1955 wdh->bytes_dumped += sizeof(irda_hdr);
1958 case WTAP_ENCAP_MTP2_WITH_PHDR:
1960 * Write the MTP2 header.
1962 memset(&mtp2_hdr, 0, sizeof(mtp2_hdr));
1963 mtp2_hdr[MTP2_SENT_OFFSET] = pseudo_header->mtp2.sent;
1964 mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET] = pseudo_header->mtp2.annex_a_used;
1965 phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET],
1966 pseudo_header->mtp2.link_number);
1967 if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err))
1969 wdh->bytes_dumped += sizeof(mtp2_hdr);
1972 case WTAP_ENCAP_LINUX_LAPD:
1974 * Write the LAPD header.
1976 memset(&lapd_hdr, 0, sizeof(lapd_hdr));
1977 phtons(&lapd_hdr[LAPD_SLL_PKTTYPE_OFFSET],
1978 pseudo_header->lapd.pkttype);
1979 phtons(&lapd_hdr[LAPD_SLL_PROTOCOL_OFFSET], ETH_P_LAPD);
1980 lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] =
1981 pseudo_header->lapd.we_network?0x01:0x00;
1982 if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err))
1984 wdh->bytes_dumped += sizeof(lapd_hdr);
1987 case WTAP_ENCAP_SITA:
1989 * Write the SITA header.
1991 memset(&sita_hdr, 0, sizeof(sita_hdr));
1992 sita_hdr[SITA_FLAGS_OFFSET] = pseudo_header->sita.sita_flags;
1993 sita_hdr[SITA_SIGNALS_OFFSET] = pseudo_header->sita.sita_signals;
1994 sita_hdr[SITA_ERRORS1_OFFSET] = pseudo_header->sita.sita_errors1;
1995 sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.sita_errors2;
1996 sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.sita_proto;
1997 if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err))
1999 wdh->bytes_dumped += sizeof(sita_hdr);
2002 case WTAP_ENCAP_ERF:
2004 * Write the ERF header.
2006 memset(&erf_hdr, 0, sizeof(erf_hdr));
2007 phtolell(&erf_hdr[0], pseudo_header->erf.phdr.ts);
2008 erf_hdr[8] = pseudo_header->erf.phdr.type;
2009 erf_hdr[9] = pseudo_header->erf.phdr.flags;
2010 phtons(&erf_hdr[10], pseudo_header->erf.phdr.rlen);
2011 phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr);
2012 phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen);
2013 size = sizeof(struct erf_phdr);
2015 switch(pseudo_header->erf.phdr.type & 0x7F) {
2016 case ERF_TYPE_MC_HDLC:
2017 case ERF_TYPE_MC_RAW:
2018 case ERF_TYPE_MC_ATM:
2019 case ERF_TYPE_MC_RAW_CHANNEL:
2020 case ERF_TYPE_MC_AAL5:
2021 case ERF_TYPE_MC_AAL2:
2022 case ERF_TYPE_COLOR_MC_HDLC_POS:
2023 phtonl(&erf_hdr[16], pseudo_header->erf.subhdr.mc_hdr);
2024 size += (int)sizeof(struct erf_mc_hdr);
2027 case ERF_TYPE_COLOR_ETH:
2028 case ERF_TYPE_DSM_COLOR_ETH:
2029 phtons(&erf_hdr[16], pseudo_header->erf.subhdr.eth_hdr);
2030 size += (int)sizeof(struct erf_eth_hdr);
2035 if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
2037 wdh->bytes_dumped += size;
2040 * Now write out the extension headers.
2042 if (pseudo_header->erf.phdr.type & 0x80) {
2043 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
2044 guint8 erf_exhdr[8];
2048 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
2049 type = erf_exhdr[0];
2050 if (!wtap_dump_file_write(wdh, erf_exhdr, 8, err))
2052 wdh->bytes_dumped += 8;
2054 } while (type & 0x80 && i < max);
2058 case WTAP_ENCAP_I2C:
2060 * Write the I2C header.
2062 memset(&i2c_hdr, 0, sizeof(i2c_hdr));
2063 i2c_hdr.bus = pseudo_header->i2c.bus |
2064 (pseudo_header->i2c.is_event ? 0x80 : 0x00);
2065 phtonl((guint8 *)&i2c_hdr.flags, pseudo_header->i2c.flags);
2066 if (!wtap_dump_file_write(wdh, &i2c_hdr, sizeof(i2c_hdr), err))
2068 wdh->bytes_dumped += sizeof(i2c_hdr);
2071 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
2072 bt_hdr.direction = GUINT32_TO_BE(pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV);
2073 if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err))
2075 wdh->bytes_dumped += sizeof bt_hdr;
2078 case WTAP_ENCAP_PPP_WITH_PHDR:
2079 ppp_hdr.direction = (pseudo_header->p2p.sent ? LIBPCAP_PPP_PHDR_SENT : LIBPCAP_PPP_PHDR_RECV);
2080 if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err))
2082 wdh->bytes_dumped += sizeof ppp_hdr;