2 * Code common to libpcap and pcap-NG file formats
5 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
7 * File format support for pcap-ng file format
8 * Copyright (c) 2007 by Ulf Lamping <ulf.lamping@web.de>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include "file_wrappers.h"
34 #include "pcap-encap.h"
35 #include "pcap-common.h"
38 * Map link-layer header types (LINKTYPE_ values) to Wiretap encapsulations.
40 * Either LBL NRG wasn't an adequate central registry (e.g., because of
41 * the slow rate of releases from them), or nobody bothered using them
42 * as a central registry, as many different groups have patched libpcap
43 * (and BPF, on the BSDs) to add new encapsulation types, and have ended
44 * up using the same DLT_ values for different encapsulation types.
46 * The Tcpdump Group now maintains the list of link-layer header types;
47 * they introduced a separate namespace of LINKTYPE_ values for the
48 * values to be used in capture files, and have libpcap map between
49 * those values in capture file headers and the DLT_ values that the
50 * pcap_datalink() and pcap_open_dead() APIs use. See
51 * http://www.tcpdump.org/linktypes.html for a list of LINKTYPE_ values.
53 * In most cases, the corresponding LINKTYPE_ and DLT_ values are the
54 * same. In the cases where the same link-layer header type was given
55 * different values in different OSes, a new LINKTYPE_ value was defined,
56 * different from all of the existing DLT_ values.
58 * This table maps LINKTYPE_ values to the corresponding Wiretap
59 * encapsulation. For cases where multiple DLT_ values were in use,
60 * it also checks what <pcap.h> defineds to determine how to interpret
61 * them, so that if a file was written by a version of libpcap prior
62 * to the introduction of the LINKTYPE_ values, and has a DLT_ value
63 * from the OS on which it was written rather than a LINKTYPE_ value
64 * as its linktype value in the file header, we map the numerical
65 * DLT_ value, as interpreted by the libpcap with which we're building
66 * Wireshark/Wiretap interprets them (which, if it doesn't support
67 * them at all, means we don't support them either - any capture files
68 * using them are foreign, and we don't hazard a guess as to which
69 * platform they came from; we could, I guess, choose the most likely
70 * platform), to the corresponding Wiretap encapsulation.
72 * Note: if you need a new encapsulation type for libpcap files, do
73 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
74 * add a new encapsulation type by changing an existing entry;
75 * leave the existing entries alone.
77 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking for
78 * a new LINKTYPE_/DLT_ value, and specifying the purpose of the new
79 * value. When you get the new LINKTYPE_/DLT_ value, use that numerical
80 * value in the "linktype_value" field of "pcap_to_wtap_map[]".
86 } pcap_to_wtap_map[] = {
88 * These are the values that are almost certainly the same
89 * in all libpcaps (I've yet to find one where the values
90 * in question are used for some purpose other than the
91 * one below, but...), and thus assigned as LINKTYPE_ values,
92 * and that Wiretap and Wireshark currently support.
94 { 0, WTAP_ENCAP_NULL }, /* null encapsulation */
95 { 1, WTAP_ENCAP_ETHERNET },
96 { 3, WTAP_ENCAP_AX25 },
97 { 6, WTAP_ENCAP_TOKEN_RING }, /* IEEE 802 Networks - assume token ring */
98 { 7, WTAP_ENCAP_ARCNET },
99 { 8, WTAP_ENCAP_SLIP },
100 { 9, WTAP_ENCAP_PPP },
101 #ifdef BIT_SWAPPED_MAC_ADDRS
102 { 10, WTAP_ENCAP_FDDI_BITSWAPPED },
104 { 10, WTAP_ENCAP_FDDI },
107 { 32, WTAP_ENCAP_REDBACK },
110 * 50 is DLT_PPP_SERIAL in NetBSD; it appears that DLT_PPP
111 * on BSD (at least according to standard tcpdump) has, as
112 * the first octet, an indication of whether the packet was
113 * transmitted or received (rather than having the standard
114 * PPP address value of 0xff), but that DLT_PPP_SERIAL puts
115 * a real live PPP header there, or perhaps a Cisco PPP header
116 * as per section 4.3.1 of RFC 1547 (implementations of this
117 * exist in various BSDs in "sys/net/if_spppsubr.c", and
118 * I think also exist either in standard Linux or in
119 * various Linux patches; the implementations show how to handle
120 * Cisco keepalive packets).
122 * However, I don't see any obvious place in FreeBSD "if_ppp.c"
123 * where anything other than the standard PPP header would be
124 * passed up. I see some stuff that sets the first octet
125 * to 0 for incoming and 1 for outgoing packets before applying
126 * a BPF filter to see whether to drop packets whose protocol
127 * field has the 0x8000 bit set, i.e. network control protocols -
128 * those are handed up to userland - but that code puts the
129 * address field back before passing the packet up.
131 * I also don't see anything immediately obvious that munges
132 * the address field for sync PPP, either.
134 * Wireshark currently assumes that if the first octet of a
135 * PPP frame is 0xFF, it's the address field and is followed
136 * by a control field and a 2-byte protocol, otherwise the
137 * address and control fields are absent and the frame begins
138 * with a protocol field. If we ever see a BSD/OS PPP
139 * capture, we'll have to handle it differently, and we may
140 * have to handle standard BSD captures differently if, in fact,
141 * they don't have 0xff 0x03 as the first two bytes - but, as per
142 * the two paragraphs preceding this, it's not clear that
143 * the address field *is* munged into an incoming/outgoing
144 * field when the packet is handed to the BPF device.
146 * For now, we just map DLT_PPP_SERIAL to WTAP_ENCAP_PPP, as
147 * we treat WTAP_ENCAP_PPP packets as if those beginning with
148 * 0xff have the standard RFC 1662 "PPP in HDLC-like Framing"
149 * 0xff 0x03 address/control header, and DLT_PPP_SERIAL frames
150 * appear to contain that unless they're Cisco frames (if we
151 * ever see a capture with them, we'd need to implement the
152 * RFC 1547 stuff, and the keepalive protocol stuff).
154 * We may have to distinguish between "PPP where if it doesn't
155 * begin with 0xff there's no HDLC encapsulation and the frame
156 * begins with the protocol field" (which is how we handle
157 * WTAP_ENCAP_PPP now) and "PPP where there's either HDLC
158 * encapsulation or Cisco PPP" (which is what DLT_PPP_SERIAL
161 * XXX - NetBSD has DLT_HDLC, which appears to be used for
162 * Cisco HDLC. Ideally, they should use DLT_PPP_SERIAL
163 * only for real live HDLC-encapsulated PPP, not for Cisco
166 { 50, WTAP_ENCAP_PPP },
169 * Used by NetBSD and OpenBSD pppoe(4).
171 { 51, WTAP_ENCAP_PPP_ETHER },
174 * Apparently used by the Axent Raptor firewall (now Symantec
175 * Enterprise Firewall).
176 * Thanks, Axent, for not reserving that type with tcpdump.org
177 * and not telling anybody about it.
179 { 99, WTAP_ENCAP_SYMANTEC },
182 * These are the values that libpcap 0.5 and later use in
183 * capture file headers, in an attempt to work around the
184 * confusion decried above, and that Wiretap and Wireshark
185 * currently support. I.e., they're the LINKTYPE_ values
186 * for RFC 1483 ATM and "raw IP", respectively, not the
187 * DLT_ values for them on all platforms.
189 { 100, WTAP_ENCAP_ATM_RFC1483 },
190 { 101, WTAP_ENCAP_RAW_IP },
193 * More values used by libpcap 0.5 as DLT_ values and used by the
194 * current CVS version of libpcap in capture file headers.
195 * They are not yet handled in Wireshark.
196 * If we get a capture that contains them, we'll implement them.
198 { 102, WTAP_ENCAP_SLIP_BSDOS },
199 { 103, WTAP_ENCAP_PPP_BSDOS },
203 * These ones are handled in Wireshark, though.
205 { 104, WTAP_ENCAP_CHDLC }, /* Cisco HDLC */
206 { 105, WTAP_ENCAP_IEEE_802_11 }, /* IEEE 802.11 */
207 { 106, WTAP_ENCAP_LINUX_ATM_CLIP },
208 { 107, WTAP_ENCAP_FRELAY }, /* Frame Relay */
209 { 108, WTAP_ENCAP_LOOP }, /* OpenBSD loopback */
210 { 109, WTAP_ENCAP_ENC }, /* OpenBSD IPSEC enc */
212 { 110, WTAP_ENCAP_LANE_802_3 },/* ATM LANE 802.3 */
213 { 111, WTAP_ENCAP_HIPPI }, /* NetBSD HIPPI */
215 { 112, WTAP_ENCAP_CHDLC }, /* NetBSD HDLC framing */
218 * Linux "cooked mode" captures, used by the current CVS version
221 * it could be a packet in Cisco's ERSPAN encapsulation which uses
222 * this number as well (why can't people stick to protocols when it
223 * comes to allocating/using DLT types).
225 { 113, WTAP_ENCAP_SLL }, /* Linux cooked capture */
227 { 114, WTAP_ENCAP_LOCALTALK }, /* Localtalk */
230 * The tcpdump.org version of libpcap uses 117, rather than 17,
231 * for OpenBSD packet filter logging, so as to avoid conflicting
232 * with DLT_LANE8023 in SuSE 6.3 libpcap.
234 { 117, WTAP_ENCAP_PFLOG },
236 { 118, WTAP_ENCAP_CISCO_IOS },
237 { 119, WTAP_ENCAP_IEEE_802_11_PRISM }, /* 802.11 plus Prism monitor mode radio header */
238 { 121, WTAP_ENCAP_HHDLC }, /* HiPath HDLC */
239 { 122, WTAP_ENCAP_IP_OVER_FC }, /* RFC 2625 IP-over-FC */
240 { 123, WTAP_ENCAP_ATM_PDUS }, /* SunATM */
241 { 127, WTAP_ENCAP_IEEE_802_11_RADIOTAP }, /* 802.11 plus radiotap radio header */
242 { 128, WTAP_ENCAP_TZSP }, /* Tazmen Sniffer Protocol */
243 { 129, WTAP_ENCAP_ARCNET_LINUX },
244 { 130, WTAP_ENCAP_JUNIPER_MLPPP }, /* Juniper MLPPP on ML-, LS-, AS- PICs */
245 { 131, WTAP_ENCAP_JUNIPER_MLFR }, /* Juniper MLFR (FRF.15) on ML-, LS-, AS- PICs */
246 { 133, WTAP_ENCAP_JUNIPER_GGSN},
248 * Values 132 and 134 not listed here are reserved for use
249 * in Juniper hardware.
251 { 135, WTAP_ENCAP_JUNIPER_ATM2 }, /* various encapsulations captured on the ATM2 PIC */
252 { 136, WTAP_ENCAP_JUNIPER_SVCS }, /* various encapsulations captured on the services PIC */
253 { 137, WTAP_ENCAP_JUNIPER_ATM1 }, /* various encapsulations captured on the ATM1 PIC */
255 { 138, WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 },
256 /* Apple IP-over-IEEE 1394 */
258 { 139, WTAP_ENCAP_MTP2_WITH_PHDR },
259 { 140, WTAP_ENCAP_MTP2 },
260 { 141, WTAP_ENCAP_MTP3 },
261 { 142, WTAP_ENCAP_SCCP },
262 { 143, WTAP_ENCAP_DOCSIS },
263 { 144, WTAP_ENCAP_IRDA }, /* IrDA capture */
265 /* Reserved for private use. */
266 { 147, WTAP_ENCAP_USER0 },
267 { 148, WTAP_ENCAP_USER1 },
268 { 149, WTAP_ENCAP_USER2 },
269 { 150, WTAP_ENCAP_USER3 },
270 { 151, WTAP_ENCAP_USER4 },
271 { 152, WTAP_ENCAP_USER5 },
272 { 153, WTAP_ENCAP_USER6 },
273 { 154, WTAP_ENCAP_USER7 },
274 { 155, WTAP_ENCAP_USER8 },
275 { 156, WTAP_ENCAP_USER9 },
276 { 157, WTAP_ENCAP_USER10 },
277 { 158, WTAP_ENCAP_USER11 },
278 { 159, WTAP_ENCAP_USER12 },
279 { 160, WTAP_ENCAP_USER13 },
280 { 161, WTAP_ENCAP_USER14 },
281 { 162, WTAP_ENCAP_USER15 },
283 { 163, WTAP_ENCAP_IEEE_802_11_AVS }, /* 802.11 plus AVS radio header */
286 * 164 is reserved for Juniper-private chassis-internal
287 * meta-information such as QoS profiles, etc..
290 { 165, WTAP_ENCAP_BACNET_MS_TP },
293 * 166 is reserved for a PPP variant in which the first byte
294 * of the 0xff03 header, the 0xff, is replaced by a direction
295 * byte. I don't know whether any captures look like that,
296 * but it is used for some Linux IP filtering (ipfilter?).
299 /* Ethernet PPPoE frames captured on a service PIC */
300 { 167, WTAP_ENCAP_JUNIPER_PPPOE },
303 * 168 is reserved for more Juniper private-chassis-
304 * internal meta-information.
307 { 169, WTAP_ENCAP_GPRS_LLC },
309 /* ITU-T G.7041/Y.1303 Generic Framing Procedure. */
310 { 170, WTAP_ENCAP_GFP_T },
311 { 171, WTAP_ENCAP_GFP_F },
313 /* Registered by Gcom, Inc. */
314 { 172, WTAP_ENCAP_GCOM_TIE1 },
315 { 173, WTAP_ENCAP_GCOM_SERIAL },
317 { 177, WTAP_ENCAP_LINUX_LAPD },
319 /* Ethernet frames prepended with meta-information */
320 { 178, WTAP_ENCAP_JUNIPER_ETHER },
321 /* PPP frames prepended with meta-information */
322 { 179, WTAP_ENCAP_JUNIPER_PPP },
323 /* Frame-Relay frames prepended with meta-information */
324 { 180, WTAP_ENCAP_JUNIPER_FRELAY },
325 /* C-HDLC frames prepended with meta-information */
326 { 181, WTAP_ENCAP_JUNIPER_CHDLC },
327 /* VOIP Frames prepended with meta-information */
328 { 183, WTAP_ENCAP_JUNIPER_VP },
329 /* USB packets from FreeBSD's USB BPF tap */
330 { 186, WTAP_ENCAP_USB_FREEBSD },
331 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
332 { 187, WTAP_ENCAP_BLUETOOTH_H4 },
333 /* IEEE 802.16 MAC Common Part Sublayer */
334 { 188, WTAP_ENCAP_IEEE802_16_MAC_CPS },
335 /* USB packets with Linux-specified header */
336 { 189, WTAP_ENCAP_USB_LINUX },
338 { 190, WTAP_ENCAP_CAN20B },
339 /* Per-Packet Information header */
340 { 192, WTAP_ENCAP_PPI },
341 /* IEEE 802.15.4 Wireless PAN */
342 { 195, WTAP_ENCAP_IEEE802_15_4 },
343 /* SITA File Encapsulation */
344 { 196, WTAP_ENCAP_SITA },
345 /* Endace Record File Encapsulation */
346 { 197, WTAP_ENCAP_ERF },
348 { 199, WTAP_ENCAP_IPMB },
349 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
350 { 201, WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR },
351 /* AX.25 packet with a 1-byte KISS header */
352 { 202, WTAP_ENCAP_AX25_KISS },
354 { 203, WTAP_ENCAP_LAPD },
355 /* PPP with pseudoheader */
356 { 204, WTAP_ENCAP_PPP_WITH_PHDR },
358 { 209, WTAP_ENCAP_I2C },
360 { 210, WTAP_ENCAP_FLEXRAY },
362 { 211, WTAP_ENCAP_MOST },
364 { 212, WTAP_ENCAP_LIN },
365 /* X2E Xoraya serial frame */
366 { 213, WTAP_ENCAP_X2E_SERIAL },
367 /* X2E Xoraya frame */
368 { 214, WTAP_ENCAP_X2E_XORAYA },
369 /* IEEE 802.15.4 Wireless PAN non-ASK PHY */
370 { 215, WTAP_ENCAP_IEEE802_15_4_NONASK_PHY },
371 /* USB packets with padded Linux-specified header */
372 { 220, WTAP_ENCAP_USB_LINUX_MMAPPED },
373 /* Fibre Channel FC-2 frame */
374 { 224, WTAP_ENCAP_FIBRE_CHANNEL_FC2 },
375 /* Fibre Channel FC-2 frame with Delimiter */
376 { 225, WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS },
378 { 226, WTAP_ENCAP_IPNET },
379 /* SocketCAN frame */
380 { 227, WTAP_ENCAP_SOCKETCAN },
382 { 228, WTAP_ENCAP_RAW_IP4 },
384 { 229, WTAP_ENCAP_RAW_IP6 },
385 /* IEEE 802.15.4 Wireless PAN no fcs */
386 { 230, WTAP_ENCAP_IEEE802_15_4_NOFCS },
388 { 231, WTAP_ENCAP_DBUS },
389 /* DVB-CI (Common Interface) */
390 { 235, WTAP_ENCAP_DVBCI },
392 { 236, WTAP_ENCAP_MUX27010 },
393 /* STANAG 5066 - DTS(Data Transfer Sublayer) PDU */
394 { 237, WTAP_ENCAP_STANAG_5066_D_PDU },
396 { 239, WTAP_ENCAP_NFLOG },
397 /* netANALYZER pseudo-header followed by Ethernet with CRC */
398 { 240, WTAP_ENCAP_NETANALYZER },
399 /* netANALYZER pseudo-header in transparent mode */
400 { 241, WTAP_ENCAP_NETANALYZER_TRANSPARENT },
401 /* IP-over-Infiniband, as specified by RFC 4391 section 6 */
402 { 242, WTAP_ENCAP_IP_OVER_IB_PCAP },
403 /* ISO/IEC 13818-1 MPEG2-TS packets */
404 { 243, WTAP_ENCAP_MPEG_2_TS },
406 { 245, WTAP_ENCAP_NFC_LLCP },
408 { 248, WTAP_ENCAP_SCTP},
410 { 249, WTAP_ENCAP_USBPCAP},
412 { 250, WTAP_ENCAP_RTAC_SERIAL},
413 /* Bluetooth Low Energy Link Layer */
414 { 251, WTAP_ENCAP_BLUETOOTH_LE_LL},
415 /* Wireshark Upper PDU export */
416 { 252, WTAP_ENCAP_WIRESHARK_UPPER_PDU},
417 /* Netlink Protocol (nlmon devices) */
418 { 253, WTAP_ENCAP_NETLINK },
419 /* Bluetooth Linux Monitor */
420 { 254, WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR },
421 /* Bluetooth BR/EDR Baseband RF captures */
422 { 255, WTAP_ENCAP_BLUETOOTH_BREDR_BB },
423 /* Bluetooth Low Energy Link Layer RF captures */
424 { 256, WTAP_ENCAP_BLUETOOTH_LE_LL_WITH_PHDR },
427 { 258, WTAP_ENCAP_PKTAP },
429 /* Ethernet Passive Optical Network */
430 { 259, WTAP_ENCAP_EPON },
432 /* IPMI Trace Data Collection */
433 { 260, WTAP_ENCAP_IPMI_TRACE },
435 /* ISO14443 contactless smartcard standards */
436 { 264, WTAP_ENCAP_ISO14443 },
441 * If you need a new encapsulation type for libpcap files, do
442 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
443 * add a new encapsulation type by changing an existing entry;
444 * leave the existing entries alone.
446 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
447 * for a new DLT_ value, and specifying the purpose of the new value.
448 * When you get the new DLT_ value, use that numerical value in
449 * the "linktype_value" field of "pcap_to_wtap_map[]".
453 * The following are entries for libpcap type values that have
454 * different meanings on different OSes. I.e., these are DLT_
455 * values that are different on different OSes, and that have
456 * a separate LINKTYPE_ value assigned to them.
458 * We put these *after* the entries for the LINKTYPE_ values for
459 * those Wiretap encapsulation types, so that, when writing a
460 * pcap or pcap-ng file, Wireshark writes the LINKTYPE_ value,
461 * not the OS's DLT_ value, as the file's link-layer header type
462 * for pcap or the interface's link-layer header type.
466 * 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
467 * seen that define anything other than DLT_ATM_RFC1483 as 11 are
468 * the BSD/OS one, which defines DLT_FR as 11. We handle it as
469 * Frame Relay on BSD/OS and LLC-encapsulated ATM on all other
472 #if defined(__bsdi__) /* BSD/OS */
473 { 11, WTAP_ENCAP_FRELAY },
475 { 11, WTAP_ENCAP_ATM_RFC1483 },
479 * 12 is DLT_RAW on most platforms, but it's DLT_C_HDLC on
480 * BSD/OS, and DLT_LOOP on OpenBSD.
482 * We don't yet handle DLT_C_HDLC, but we can handle DLT_LOOP
483 * (it's just like DLT_NULL, only with the AF_ value in network
484 * rather than host byte order - Wireshark figures out the
485 * byte order from the data, so we don't care what byte order
486 * it's in), so, on OpenBSD, interpret 12 as WTAP_ENCAP_LOOP,
487 * otherwise, if we're not on BSD/OS, interpret it as
490 #if defined(__OpenBSD__)
491 { 12, WTAP_ENCAP_LOOP },
492 #elif defined(__bsdi__) /* BSD/OS */
494 * Put entry for Cisco HDLC here.
495 * XXX - is this just WTAP_ENCAP_CHDLC, i.e. does the frame
496 * start with a 4-byte Cisco HDLC header?
499 { 12, WTAP_ENCAP_RAW_IP },
503 * 13 is DLT_SLIP_BSDOS on FreeBSD and NetBSD, but those OSes
504 * don't actually generate it. I infer that BSD/OS translates
505 * DLT_SLIP from the kernel BPF code to DLT_SLIP_BSDOS in
506 * libpcap, as the BSD/OS link-layer header is different;
507 * however, in BSD/OS, DLT_SLIP_BSDOS is 15.
509 * From this, I infer that there's no point in handling 13
512 * 13 is DLT_ATM_RFC1483 on BSD/OS.
514 * 13 is DLT_ENC in OpenBSD, which is, I suspect, some kind
515 * of decrypted IPsec traffic.
517 * We treat 13 as WTAP_ENCAP_ENC on all systems except those
518 * that define DLT_ATM_RFC1483 as 13 - presumably only
519 * BSD/OS does so - so that, on BSD/OS systems, we still
520 * treate 13 as WTAP_ENCAP_ATM_RFC1483, but, on all other
521 * systems, we can read OpenBSD DLT_ENC captures.
523 #if defined(__bsdi__) /* BSD/OS */
524 { 13, WTAP_ENCAP_ATM_RFC1483 },
526 { 13, WTAP_ENCAP_ENC },
530 * 14 is DLT_PPP_BSDOS on FreeBSD and NetBSD, but those OSes
531 * don't actually generate it. I infer that BSD/OS translates
532 * DLT_PPP from the kernel BPF code to DLT_PPP_BSDOS in
533 * libpcap, as the BSD/OS link-layer header is different;
534 * however, in BSD/OS, DLT_PPP_BSDOS is 16.
536 * From this, I infer that there's no point in handling 14
539 * 14 is DLT_RAW on BSD/OS and OpenBSD.
541 { 14, WTAP_ENCAP_RAW_IP },
546 * DLT_SLIP_BSDOS on BSD/OS;
548 * DLT_HIPPI on NetBSD;
550 * DLT_LANE8023 with Alexey Kuznetzov's patches for
553 * DLT_I4L_RAWIP with the ISDN4Linux patches for libpcap
556 * but we don't currently handle any of those.
562 * DLT_PPP_BSDOS on BSD/OS;
564 * DLT_HDLC on NetBSD (Cisco HDLC);
566 * DLT_CIP with Alexey Kuznetzov's patches for
567 * Linux libpcap - this is WTAP_ENCAP_LINUX_ATM_CLIP;
569 * DLT_I4L_IP with the ISDN4Linux patches for libpcap
572 #if defined(__NetBSD__)
573 { 16, WTAP_ENCAP_CHDLC },
574 #elif !defined(__bsdi__)
576 * If you care about the two different Linux interpretations
577 * of 16, fix it yourself.
579 { 16, WTAP_ENCAP_LINUX_ATM_CLIP },
583 * 17 is DLT_LANE8023 in SuSE 6.3 libpcap; we don't currently
585 * It is also used as the PF (Packet Filter) logging format beginning
586 * with OpenBSD 3.0; we use 17 for PF logs on OpenBSD and don't
589 #if defined(__OpenBSD__)
590 { 17, WTAP_ENCAP_OLD_PFLOG },
594 * 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
595 * DLT_CIP of 16 that the Alexey Kuznetzov patches for
596 * libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
597 * I've not found any libpcap that uses it for any other purpose -
598 * hopefully nobody will do so in the future.
600 { 18, WTAP_ENCAP_LINUX_ATM_CLIP },
603 * 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
604 * recent versions I've seen of the Linux ATM distribution;
605 * I've not yet found any libpcap that uses it for any other
606 * purpose - hopefully nobody will do so in the future.
608 { 19, WTAP_ENCAP_LINUX_ATM_CLIP },
613 * If you need a new encapsulation type for libpcap files, do
614 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
615 * add a new encapsulation type by changing an existing entry;
616 * leave the existing entries alone.
618 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
619 * for a new DLT_ value, and specifying the purpose of the new value.
620 * When you get the new DLT_ value, use that numerical value in
621 * the "linktype_value" field of "pcap_to_wtap_map[]".
624 #define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0])
627 wtap_pcap_encap_to_wtap_encap(int encap)
631 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
632 if (pcap_to_wtap_map[i].linktype_value == encap)
633 return pcap_to_wtap_map[i].wtap_encap_value;
635 return WTAP_ENCAP_UNKNOWN;
639 wtap_wtap_encap_to_pcap_encap(int encap)
645 case WTAP_ENCAP_FDDI:
646 case WTAP_ENCAP_FDDI_BITSWAPPED:
648 * Special-case WTAP_ENCAP_FDDI and
649 * WTAP_ENCAP_FDDI_BITSWAPPED; both of them get mapped
650 * to DLT_FDDI (even though that may mean that the bit
651 * order in the FDDI MAC addresses is wrong; so it goes
652 * - libpcap format doesn't record the byte order,
653 * so that's not fixable).
655 * The pcap_to_wtap_map[] table will only have an
656 * entry for one of the above, which is why we have
657 * to special-case them.
659 return 10; /* that's DLT_FDDI */
661 case WTAP_ENCAP_NETTL_FDDI:
663 * This will discard the nettl information, as that's
664 * in the pseudo-header.
666 * XXX - what about Ethernet and Token Ring?
668 return 10; /* that's DLT_FDDI */
670 case WTAP_ENCAP_FRELAY_WITH_PHDR:
672 * This will discard the pseudo-header information.
676 case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
678 * Map this to DLT_IEEE802_11, for now, even though
679 * that means the radio information will be lost.
680 * We should try to map those values to radiotap
681 * values and write this out as a radiotap file,
687 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
688 if (pcap_to_wtap_map[i].wtap_encap_value == encap)
689 return pcap_to_wtap_map[i].linktype_value;
695 wtap_encap_requires_phdr(int wtap_encap)
697 switch (wtap_encap) {
699 case WTAP_ENCAP_ATM_PDUS:
700 case WTAP_ENCAP_IRDA:
701 case WTAP_ENCAP_MTP2_WITH_PHDR:
702 case WTAP_ENCAP_LINUX_LAPD:
703 case WTAP_ENCAP_SITA:
704 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
705 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
706 case WTAP_ENCAP_NFC_LLCP:
707 case WTAP_ENCAP_PPP_WITH_PHDR:
717 * Various pseudo-headers that appear at the beginning of packet data.
719 * We represent them as sets of offsets, as they might not be aligned on
720 * an appropriate structure boundary in the buffer, and as that makes them
721 * independent of the way the compiler might align fields.
725 * The link-layer header on SunATM packets.
727 #define SUNATM_FLAGS 0 /* destination and traffic type - 1 byte */
728 #define SUNATM_VPI 1 /* VPI - 1 byte */
729 #define SUNATM_VCI 2 /* VCI - 2 bytes */
730 #define SUNATM_LEN 4 /* length of the header */
733 * The link-layer header on Nokia IPSO ATM packets.
735 #define NOKIAATM_FLAGS 0 /* destination - 1 byte */
736 #define NOKIAATM_VPI 1 /* VPI - 1 byte */
737 #define NOKIAATM_VCI 2 /* VCI - 2 bytes */
738 #define NOKIAATM_LEN 4 /* length of the header */
741 * The link-layer header on Nokia IPSO packets.
743 #define NOKIA_LEN 4 /* length of the header */
746 * The fake link-layer header of IrDA packets as introduced by Jean Tourrilhes
749 #define IRDA_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
750 /* 12 unused bytes */
751 #define IRDA_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
752 #define IRDA_SLL_LEN 16 /* length of the header */
755 * A header containing additional MTP information.
757 #define MTP2_SENT_OFFSET 0 /* 1 byte */
758 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
759 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
760 #define MTP2_HDR_LEN 4 /* length of the header */
763 * A header containing additional SITA WAN information.
765 #define SITA_FLAGS_OFFSET 0 /* 1 byte */
766 #define SITA_SIGNALS_OFFSET 1 /* 1 byte */
767 #define SITA_ERRORS1_OFFSET 2 /* 1 byte */
768 #define SITA_ERRORS2_OFFSET 3 /* 1 byte */
769 #define SITA_PROTO_OFFSET 4 /* 1 byte */
770 #define SITA_HDR_LEN 5 /* length of the header */
773 * The fake link-layer header of LAPD packets.
776 #define ETH_P_LAPD 0x0030
779 #define LAPD_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
780 #define LAPD_SLL_HATYPE_OFFSET 2 /* hardware address type - 2 bytes */
781 #define LAPD_SLL_HALEN_OFFSET 4 /* hardware address length - 2 bytes */
782 #define LAPD_SLL_ADDR_OFFSET 6 /* address - 8 bytes */
783 #define LAPD_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
784 #define LAPD_SLL_LEN 16 /* length of the header */
787 * The NFC LLCP per-packet header.
789 #define LLCP_ADAPTER_OFFSET 0
790 #define LLCP_FLAGS_OFFSET 1
791 #define LLCP_HEADER_LEN 2
794 * I2C link-layer on-disk format
796 struct i2c_file_hdr {
802 pcap_read_sunatm_pseudoheader(FILE_T fh,
803 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
805 guint8 atm_phdr[SUNATM_LEN];
809 if (!wtap_read_bytes(fh, atm_phdr, SUNATM_LEN, err, err_info))
812 vpi = atm_phdr[SUNATM_VPI];
813 vci = pntoh16(&atm_phdr[SUNATM_VCI]);
815 switch (atm_phdr[SUNATM_FLAGS] & 0x0F) {
817 case 0x01: /* LANE */
818 pseudo_header->atm.aal = AAL_5;
819 pseudo_header->atm.type = TRAF_LANE;
822 case 0x02: /* RFC 1483 LLC multiplexed traffic */
823 pseudo_header->atm.aal = AAL_5;
824 pseudo_header->atm.type = TRAF_LLCMX;
827 case 0x05: /* ILMI */
828 pseudo_header->atm.aal = AAL_5;
829 pseudo_header->atm.type = TRAF_ILMI;
832 case 0x06: /* Q.2931 */
833 pseudo_header->atm.aal = AAL_SIGNALLING;
834 pseudo_header->atm.type = TRAF_UNKNOWN;
837 case 0x03: /* MARS (RFC 2022) */
838 pseudo_header->atm.aal = AAL_5;
839 pseudo_header->atm.type = TRAF_UNKNOWN;
842 case 0x04: /* IFMP (Ipsilon Flow Management Protocol; see RFC 1954) */
843 pseudo_header->atm.aal = AAL_5;
844 pseudo_header->atm.type = TRAF_UNKNOWN; /* XXX - TRAF_IPSILON? */
849 * Assume it's AAL5, unless it's VPI 0 and VCI 5, in which
850 * case assume it's AAL_SIGNALLING; we know nothing more
853 * XXX - is this necessary? Or are we guaranteed that
854 * all signalling traffic has a type of 0x06?
856 * XXX - is this guaranteed to be AAL5? Or, if the type is
857 * 0x00 ("raw"), might it be non-AAL5 traffic?
859 if (vpi == 0 && vci == 5)
860 pseudo_header->atm.aal = AAL_SIGNALLING;
862 pseudo_header->atm.aal = AAL_5;
863 pseudo_header->atm.type = TRAF_UNKNOWN;
866 pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
868 pseudo_header->atm.vpi = vpi;
869 pseudo_header->atm.vci = vci;
870 pseudo_header->atm.channel = (atm_phdr[SUNATM_FLAGS] & 0x80) ? 0 : 1;
872 /* We don't have this information */
873 pseudo_header->atm.flags = 0;
874 pseudo_header->atm.cells = 0;
875 pseudo_header->atm.aal5t_u2u = 0;
876 pseudo_header->atm.aal5t_len = 0;
877 pseudo_header->atm.aal5t_chksum = 0;
883 pcap_read_nokiaatm_pseudoheader(FILE_T fh,
884 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
886 guint8 atm_phdr[NOKIAATM_LEN];
890 if (!wtap_read_bytes(fh, atm_phdr, NOKIAATM_LEN, err, err_info))
893 vpi = atm_phdr[NOKIAATM_VPI];
894 vci = pntoh16(&atm_phdr[NOKIAATM_VCI]);
896 pseudo_header->atm.vpi = vpi;
897 pseudo_header->atm.vci = vci;
898 pseudo_header->atm.channel = (atm_phdr[NOKIAATM_FLAGS] & 0x80) ? 0 : 1;
900 /* We don't have this information */
901 pseudo_header->atm.flags = 0;
902 pseudo_header->atm.cells = 0;
903 pseudo_header->atm.aal5t_u2u = 0;
904 pseudo_header->atm.aal5t_len = 0;
905 pseudo_header->atm.aal5t_chksum = 0;
911 pcap_read_nokia_pseudoheader(FILE_T fh,
912 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
914 guint8 phdr[NOKIA_LEN];
917 /* backtrack to read the 4 mysterious bytes that aren't considered
918 * part of the packet size
920 if (file_seek(fh, -NOKIA_LEN, SEEK_CUR, err) == -1)
922 *err = file_error(fh, err_info);
924 *err = WTAP_ERR_SHORT_READ;
928 if (!wtap_read_bytes(fh, phdr, NOKIA_LEN, err, err_info))
931 memcpy(pseudo_header->nokia.stuff, phdr, NOKIA_LEN);
937 pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
938 int *err, gchar **err_info)
940 guint8 irda_phdr[IRDA_SLL_LEN];
942 if (!wtap_read_bytes(fh, irda_phdr, IRDA_SLL_LEN, err, err_info))
945 if (pntoh16(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
946 *err = WTAP_ERR_BAD_FILE;
947 if (err_info != NULL)
948 *err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
952 pseudo_header->irda.pkttype = pntoh16(&irda_phdr[IRDA_SLL_PKTTYPE_OFFSET]);
958 pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
960 guint8 mtp2_hdr[MTP2_HDR_LEN];
962 if (!wtap_read_bytes(fh, mtp2_hdr, MTP2_HDR_LEN, err, err_info))
965 pseudo_header->mtp2.sent = mtp2_hdr[MTP2_SENT_OFFSET];
966 pseudo_header->mtp2.annex_a_used = mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET];
967 pseudo_header->mtp2.link_number = pntoh16(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET]);
973 pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
974 int *err, gchar **err_info)
976 guint8 lapd_phdr[LAPD_SLL_LEN];
978 if (!wtap_read_bytes(fh, lapd_phdr, LAPD_SLL_LEN, err, err_info))
981 if (pntoh16(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
982 *err = WTAP_ERR_BAD_FILE;
983 if (err_info != NULL)
984 *err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
988 pseudo_header->lapd.pkttype = pntoh16(&lapd_phdr[LAPD_SLL_PKTTYPE_OFFSET]);
989 pseudo_header->lapd.we_network = !!lapd_phdr[LAPD_SLL_ADDR_OFFSET+0];
995 pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
997 guint8 sita_phdr[SITA_HDR_LEN];
999 if (!wtap_read_bytes(fh, sita_phdr, SITA_HDR_LEN, err, err_info))
1002 pseudo_header->sita.sita_flags = sita_phdr[SITA_FLAGS_OFFSET];
1003 pseudo_header->sita.sita_signals = sita_phdr[SITA_SIGNALS_OFFSET];
1004 pseudo_header->sita.sita_errors1 = sita_phdr[SITA_ERRORS1_OFFSET];
1005 pseudo_header->sita.sita_errors2 = sita_phdr[SITA_ERRORS2_OFFSET];
1006 pseudo_header->sita.sita_proto = sita_phdr[SITA_PROTO_OFFSET];
1012 * When not using the memory-mapped interface to capture USB events,
1013 * code that reads those events can use the MON_IOCX_GET ioctl to
1014 * read a 48-byte header consisting of a "struct linux_usb_phdr", as
1015 * defined below, followed immediately by one of:
1017 * 8 bytes of a "struct usb_device_setup_hdr", if "setup_flag"
1018 * in the preceding "struct linux_usb_phdr" is 0;
1020 * in Linux 2.6.30 or later, 8 bytes of a "struct iso_rec", if
1021 * this is an isochronous transfer;
1023 * 8 bytes of junk, otherwise.
1025 * In Linux 2.6.31 and later, it can also use the MON_IOCX_GETX ioctl
1026 * to read a 64-byte header; that header consists of the 48 bytes
1027 * above, followed immediately by 16 bytes of a "struct linux_usb_phdr_ext",
1030 * In Linux 2.6.21 and later, there's a memory-mapped interface to
1031 * capture USB events. In that interface, the events in the memory-mapped
1032 * buffer have a 64-byte header, followed immediately by the data.
1033 * In Linux 2.6.21 through 2.6.30.x, the 64-byte header is the 48-byte
1034 * header described above, followed by 16 bytes of zeroes; in Linux
1035 * 2.6.31 and later, the 64-byte header is the 64-byte header described
1038 * See linux/Documentation/usb/usbmon.txt and libpcap/pcap/usb.h for details.
1040 * With WTAP_ENCAP_USB_LINUX, packets have the 48-byte header; with
1041 * WTAP_ENCAP_USB_LINUX_MMAPPED, they have the 64-byte header. There
1042 * is no indication of whether the header has the "struct iso_rec", or
1043 * whether the last 16 bytes of a 64-byte header are all zeros or are
1044 * a "struct linux_usb_phdr_ext".
1048 * URB transfer_type values
1050 #define URB_ISOCHRONOUS 0x0
1051 #define URB_INTERRUPT 0x1
1052 #define URB_CONTROL 0x2
1053 #define URB_BULK 0x3
1056 * Information from the URB for Isochronous transfers.
1058 * This structure is 8 bytes long.
1066 * Header prepended by Linux kernel to each USB event.
1068 * (Setup flag is '-', 'D', 'Z', or 0. Data flag is '<', '>', 'Z', or 0.)
1070 * The values are in *host* byte order.
1072 struct linux_usb_phdr {
1073 guint64 id; /* urb id, to link submission and completion events */
1074 guint8 event_type; /* Submit ('S'), Completed ('C'), Error ('E') */
1075 guint8 transfer_type; /* ISO (0), Intr, Control, Bulk (3) */
1076 guint8 endpoint_number; /* Endpoint number (0-15) and transfer direction */
1077 guint8 device_address; /* 0-127 */
1079 gint8 setup_flag; /* 0, if the urb setup header is meaningful */
1080 gint8 data_flag; /* 0, if urb data is present */
1084 guint32 urb_len; /* whole len of urb this event refers to */
1085 guint32 data_len; /* amount of urb data really present in this event */
1088 * Packet-type-dependent data.
1089 * USB setup information of setup_flag is true.
1090 * Otherwise, some isochronous transfer information.
1098 * This data is provided by Linux 2.6.31 and later kernels.
1100 * For WTAP_ENCAP_USB_LINUX, it's not in the pseudo-header, so
1101 * the pseudo-header is always 48 bytes long, including the
1102 * packet-type-dependent data.
1104 * For WTAP_ENCAP_USB_LINUX_MMAPPED, the pseudo-header is always
1105 * 64 bytes long, with the packet-type-dependent data preceding
1106 * these last 16 bytes. In pre-2.6.31 kernels, it's zero padding;
1107 * in 2.6.31 and later, it's the following data.
1109 gint32 interval; /* only for Interrupt and Isochronous events */
1110 gint32 start_frame; /* for Isochronous */
1111 guint32 xfer_flags; /* copy of URB's transfer_flags */
1112 guint32 ndesc; /* actual number of isochronous descriptors */
1115 struct linux_usb_isodesc {
1123 * USB setup header as defined in USB specification
1124 * See usb_20.pdf, Chapter 9.3 'USB Device Requests' for details.
1125 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
1127 * This structure is 8 bytes long.
1129 struct usb_device_setup_hdr {
1130 gint8 bmRequestType;
1139 * Offset of the *end* of a field within a particular structure.
1141 #define END_OFFSETOF(basep, fieldp) \
1142 (((char *)(void *)(fieldp)) - ((char *)(void *)(basep)) + \
1146 * Is that offset within the bounds of the packet?
1148 #define WITHIN_PACKET(basep, fieldp) \
1149 (packet_size >= END_OFFSETOF((basep), (fieldp)))
1151 #define CHECK_AND_SWAP16(fieldp) \
1153 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1155 PBSWAP16((guint8 *)fieldp); \
1158 #define CHECK_AND_SWAP32(fieldp) \
1160 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1162 PBSWAP32((guint8 *)fieldp); \
1165 #define CHECK_AND_SWAP64(fieldp) \
1167 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1169 PBSWAP64((guint8 *)fieldp); \
1173 pcap_byteswap_linux_usb_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd,
1174 gboolean header_len_64_bytes)
1177 struct linux_usb_phdr *usb_phdr;
1178 struct linux_usb_isodesc *pisodesc;
1179 gint32 iso_numdesc, i;
1182 * Minimum of captured and actual length (just in case the
1183 * actual length < the captured length, which Should Never
1186 packet_size = phdr->caplen;
1187 if (packet_size > phdr->len)
1188 packet_size = phdr->len;
1191 * Greasy hack, but we never directly dereference any of
1192 * the fields in *usb_phdr, we just get offsets of and
1193 * addresses of its members and byte-swap it with a
1194 * byte-at-a-time macro, so it's alignment-safe.
1196 usb_phdr = (struct linux_usb_phdr *)(void *)pd;
1198 CHECK_AND_SWAP64(&usb_phdr->id);
1199 CHECK_AND_SWAP16(&usb_phdr->bus_id);
1200 CHECK_AND_SWAP64(&usb_phdr->ts_sec);
1201 CHECK_AND_SWAP32(&usb_phdr->ts_usec);
1202 CHECK_AND_SWAP32(&usb_phdr->status);
1203 CHECK_AND_SWAP32(&usb_phdr->urb_len);
1204 CHECK_AND_SWAP32(&usb_phdr->data_len);
1206 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1207 CHECK_AND_SWAP32(&usb_phdr->s.iso.error_count);
1208 CHECK_AND_SWAP32(&usb_phdr->s.iso.numdesc);
1211 if (header_len_64_bytes) {
1213 * This is either the "version 1" header, with
1214 * 16 bytes of additional fields at the end, or
1215 * a "version 0" header from a memory-mapped
1216 * capture, with 16 bytes of zeroed-out padding
1217 * at the end. Byte swap them as if this were
1218 * a "version 1" header.
1220 * Yes, the first argument to END_OFFSETOF() should
1221 * be usb_phdr, not usb_phdr_ext; we want the offset of
1222 * the additional fields from the beginning of
1225 CHECK_AND_SWAP32(&usb_phdr->interval);
1226 CHECK_AND_SWAP32(&usb_phdr->start_frame);
1227 CHECK_AND_SWAP32(&usb_phdr->xfer_flags);
1228 CHECK_AND_SWAP32(&usb_phdr->ndesc);
1231 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1232 /* swap the values in struct linux_usb_isodesc */
1235 * See previous "Greasy hack" comment.
1237 if (header_len_64_bytes) {
1238 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 64);
1240 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 48);
1242 iso_numdesc = usb_phdr->s.iso.numdesc;
1243 for (i = 0; i < iso_numdesc; i++) {
1244 CHECK_AND_SWAP32(&pisodesc->iso_status);
1245 CHECK_AND_SWAP32(&pisodesc->iso_off);
1246 CHECK_AND_SWAP32(&pisodesc->iso_len);
1247 CHECK_AND_SWAP32(&pisodesc->_pad);
1255 guint8 nflog_family; /* address family */
1256 guint8 nflog_version; /* version */
1257 guint16 nflog_rid; /* resource ID */
1261 guint16 tlv_length; /* tlv length */
1262 guint16 tlv_type; /* tlv type */
1263 /* value follows this */
1267 pcap_byteswap_nflog_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd)
1271 struct nflog_hdr *nfhdr;
1272 struct nflog_tlv *tlv;
1276 * Minimum of captured and actual length (just in case the
1277 * actual length < the captured length, which Should Never
1280 packet_size = phdr->caplen;
1281 if (packet_size > phdr->len)
1282 packet_size = phdr->len;
1284 if (packet_size < sizeof(struct nflog_hdr)) {
1285 /* Not enough data to have any TLVs. */
1290 nfhdr = (struct nflog_hdr *)pd;
1291 if (nfhdr->nflog_version != 0) {
1292 /* Unknown NFLOG version */
1296 packet_size -= (guint)sizeof(struct nflog_hdr);
1297 p += sizeof(struct nflog_hdr);
1299 while (packet_size >= sizeof(struct nflog_tlv)) {
1300 tlv = (struct nflog_tlv *) p;
1302 /* Swap the type and length. */
1303 PBSWAP16((guint8 *)&tlv->tlv_type);
1304 PBSWAP16((guint8 *)&tlv->tlv_length);
1306 /* Get the length of the TLV. */
1307 size = tlv->tlv_length;
1309 size += 4 - size % 4;
1311 /* Is the TLV's length less than the minimum? */
1312 if (size < sizeof(struct nflog_tlv)) {
1313 /* Yes. Give up now. */
1317 /* Do we have enough data for the full TLV? */
1318 if (packet_size < size) {
1323 /* Skip over the TLV. */
1324 packet_size -= size;
1330 * Pseudo-header at the beginning of DLT_BLUETOOTH_HCI_H4_WITH_PHDR frames.
1331 * Values in network byte order.
1333 struct libpcap_bt_phdr {
1334 guint32 direction; /* Bit 0 hold the frame direction. */
1337 #define LIBPCAP_BT_PHDR_SENT 0
1338 #define LIBPCAP_BT_PHDR_RECV 1
1341 pcap_read_bt_pseudoheader(FILE_T fh,
1342 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1344 struct libpcap_bt_phdr phdr;
1346 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_phdr),
1349 pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
1354 * Pseudo-header at the beginning of DLT_BLUETOOTH_LINUX_MONITOR frames.
1355 * Values in network byte order.
1357 struct libpcap_bt_monitor_phdr {
1363 pcap_read_bt_monitor_pseudoheader(FILE_T fh,
1364 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1366 struct libpcap_bt_monitor_phdr phdr;
1368 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_monitor_phdr),
1372 pseudo_header->btmon.adapter_id = g_ntohs(phdr.adapter_id);
1373 pseudo_header->btmon.opcode = g_ntohs(phdr.opcode);
1378 pcap_read_llcp_pseudoheader(FILE_T fh,
1379 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1381 guint8 phdr[LLCP_HEADER_LEN];
1383 if (!wtap_read_bytes(fh, phdr, LLCP_HEADER_LEN, err, err_info))
1385 pseudo_header->llcp.adapter = phdr[LLCP_ADAPTER_OFFSET];
1386 pseudo_header->llcp.flags = phdr[LLCP_FLAGS_OFFSET];
1391 * Pseudo-header at the beginning of DLT_PPP_WITH_DIR frames.
1393 struct libpcap_ppp_phdr {
1397 #define LIBPCAP_PPP_PHDR_RECV 0
1398 #define LIBPCAP_PPP_PHDR_SENT 1
1401 pcap_read_ppp_pseudoheader(FILE_T fh,
1402 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1404 struct libpcap_ppp_phdr phdr;
1406 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_ppp_phdr),
1409 pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
1414 pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr,
1415 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1417 guint8 erf_hdr[sizeof(struct erf_phdr)];
1419 if (!wtap_read_bytes(fh, erf_hdr, sizeof(struct erf_phdr), err, err_info))
1421 pseudo_header->erf.phdr.ts = pletoh64(&erf_hdr[0]); /* timestamp */
1422 pseudo_header->erf.phdr.type = erf_hdr[8];
1423 pseudo_header->erf.phdr.flags = erf_hdr[9];
1424 pseudo_header->erf.phdr.rlen = pntoh16(&erf_hdr[10]);
1425 pseudo_header->erf.phdr.lctr = pntoh16(&erf_hdr[12]);
1426 pseudo_header->erf.phdr.wlen = pntoh16(&erf_hdr[14]);
1428 /* The high 32 bits of the timestamp contain the integer number of seconds
1429 * while the lower 32 bits contain the binary fraction of the second.
1430 * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */
1432 guint64 ts = pseudo_header->erf.phdr.ts;
1433 whdr->ts.secs = (guint32) (ts >> 32);
1434 ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000);
1435 ts += (ts & 0x80000000) << 1; /* rounding */
1436 whdr->ts.nsecs = ((guint32) (ts >> 32));
1437 if ( whdr->ts.nsecs >= 1000000000) {
1438 whdr->ts.nsecs -= 1000000000;
1446 * If the type of record given in the pseudo header indicate the presence of an extension
1447 * header then, read all the extension headers
1450 pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1451 int *err, gchar **err_info, guint * psize)
1453 guint8 erf_exhdr[8];
1454 guint64 erf_exhdr_sw;
1455 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1458 if (pseudo_header->erf.phdr.type & 0x80){
1460 if (!wtap_read_bytes(fh, erf_exhdr, 8, err, err_info))
1462 type = erf_exhdr[0];
1463 erf_exhdr_sw = pntoh64(erf_exhdr);
1465 memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw));
1468 } while (type & 0x80);
1474 * If the type of record given in the pseudo header indicate the precense of a subheader
1475 * then, read this optional subheader
1478 pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1479 int *err, gchar **err_info, guint * psize)
1481 guint8 erf_subhdr[sizeof(union erf_subhdr)];
1484 switch(pseudo_header->erf.phdr.type & 0x7F) {
1485 case ERF_TYPE_MC_HDLC:
1486 case ERF_TYPE_MC_RAW:
1487 case ERF_TYPE_MC_ATM:
1488 case ERF_TYPE_MC_RAW_CHANNEL:
1489 case ERF_TYPE_MC_AAL5:
1490 case ERF_TYPE_MC_AAL2:
1491 case ERF_TYPE_COLOR_MC_HDLC_POS:
1492 /* Extract the Multi Channel header to include it in the pseudo header part */
1493 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_mc_header_t), err, err_info))
1495 pseudo_header->erf.subhdr.mc_hdr = pntoh32(&erf_subhdr[0]);
1496 *psize = sizeof(erf_mc_header_t);
1499 /* Extract the AAL2 header to include it in the pseudo header part */
1500 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_aal2_header_t), err, err_info))
1502 pseudo_header->erf.subhdr.aal2_hdr = pntoh32(&erf_subhdr[0]);
1503 *psize = sizeof(erf_aal2_header_t);
1506 case ERF_TYPE_COLOR_ETH:
1507 case ERF_TYPE_DSM_COLOR_ETH:
1508 case ERF_TYPE_COLOR_HASH_ETH:
1509 /* Extract the Ethernet additional header to include it in the pseudo header part */
1510 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_eth_header_t), err, err_info))
1512 memcpy(&pseudo_header->erf.subhdr.eth_hdr, erf_subhdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
1513 *psize = sizeof(erf_eth_header_t);
1516 /* No optional pseudo header for this ERF type */
1523 pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1525 struct i2c_file_hdr i2c_hdr;
1527 if (!wtap_read_bytes(fh, &i2c_hdr, sizeof (i2c_hdr), err, err_info))
1530 pseudo_header->i2c.is_event = i2c_hdr.bus & 0x80 ? 1 : 0;
1531 pseudo_header->i2c.bus = i2c_hdr.bus & 0x7f;
1532 pseudo_header->i2c.flags = pntoh32(&i2c_hdr.flags);
1538 pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
1539 guint packet_size, gboolean check_packet_size,
1540 struct wtap_pkthdr *phdr, int *err, gchar **err_info)
1545 switch (wtap_encap) {
1547 case WTAP_ENCAP_ATM_PDUS:
1548 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1552 if (check_packet_size && packet_size < NOKIAATM_LEN) {
1554 * Uh-oh, the packet isn't big enough to even
1555 * have a pseudo-header.
1557 *err = WTAP_ERR_BAD_FILE;
1558 *err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1562 if (!pcap_read_nokiaatm_pseudoheader(fh,
1563 &phdr->pseudo_header, err, err_info))
1564 return -1; /* Read error */
1566 phdr_len = NOKIAATM_LEN;
1571 if (check_packet_size && packet_size < SUNATM_LEN) {
1573 * Uh-oh, the packet isn't big enough to even
1574 * have a pseudo-header.
1576 *err = WTAP_ERR_BAD_FILE;
1577 *err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1581 if (!pcap_read_sunatm_pseudoheader(fh,
1582 &phdr->pseudo_header, err, err_info))
1583 return -1; /* Read error */
1585 phdr_len = SUNATM_LEN;
1589 case WTAP_ENCAP_ETHERNET:
1590 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1592 * Nokia IPSO. Psuedo header has already been read, but it's not considered
1593 * part of the packet size, so reread it to store the data for later (when saving)
1595 if (!pcap_read_nokia_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1596 return -1; /* Read error */
1600 * We don't know whether there's an FCS in this frame or not.
1602 phdr->pseudo_header.eth.fcs_len = -1;
1605 case WTAP_ENCAP_IEEE_802_11:
1606 case WTAP_ENCAP_IEEE_802_11_PRISM:
1607 case WTAP_ENCAP_IEEE_802_11_RADIOTAP:
1608 case WTAP_ENCAP_IEEE_802_11_AVS:
1610 * We don't know whether there's an FCS in this frame or not,
1611 * at least in pcap files. For radiotap, that's indicated in
1612 * the radiotap header.
1614 * XXX - in pcap-ng, there *could* be a packet option
1615 * indicating the FCS length.
1617 memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11));
1618 phdr->pseudo_header.ieee_802_11.fcs_len = -1;
1619 phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
1620 phdr->pseudo_header.ieee_802_11.datapad = FALSE;
1623 case WTAP_ENCAP_IRDA:
1624 if (check_packet_size && packet_size < IRDA_SLL_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: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
1634 if (!pcap_read_irda_pseudoheader(fh, &phdr->pseudo_header,
1636 return -1; /* Read error */
1638 phdr_len = IRDA_SLL_LEN;
1641 case WTAP_ENCAP_MTP2_WITH_PHDR:
1642 if (check_packet_size && packet_size < MTP2_HDR_LEN) {
1644 * Uh-oh, the packet isn't big enough to even
1645 * have a pseudo-header.
1647 *err = WTAP_ERR_BAD_FILE;
1648 *err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
1652 if (!pcap_read_mtp2_pseudoheader(fh, &phdr->pseudo_header,
1654 return -1; /* Read error */
1656 phdr_len = MTP2_HDR_LEN;
1659 case WTAP_ENCAP_LINUX_LAPD:
1660 if (check_packet_size && packet_size < LAPD_SLL_LEN) {
1662 * Uh-oh, the packet isn't big enough to even
1663 * have a pseudo-header.
1665 *err = WTAP_ERR_BAD_FILE;
1666 *err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
1670 if (!pcap_read_lapd_pseudoheader(fh, &phdr->pseudo_header,
1672 return -1; /* Read error */
1674 phdr_len = LAPD_SLL_LEN;
1677 case WTAP_ENCAP_SITA:
1678 if (check_packet_size && packet_size < SITA_HDR_LEN) {
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: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
1688 if (!pcap_read_sita_pseudoheader(fh, &phdr->pseudo_header,
1690 return -1; /* Read error */
1692 phdr_len = SITA_HDR_LEN;
1695 case WTAP_ENCAP_BLUETOOTH_H4:
1696 /* We don't have pseudoheader, so just pretend we received everything. */
1697 phdr->pseudo_header.p2p.sent = FALSE;
1700 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1701 if (check_packet_size &&
1702 packet_size < sizeof (struct libpcap_bt_phdr)) {
1704 * Uh-oh, the packet isn't big enough to even
1705 * have a pseudo-header.
1707 *err = WTAP_ERR_BAD_FILE;
1708 *err_info = g_strdup_printf("pcap: libpcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
1712 if (!pcap_read_bt_pseudoheader(fh,
1713 &phdr->pseudo_header, err, err_info))
1714 return -1; /* Read error */
1716 phdr_len = (int)sizeof (struct libpcap_bt_phdr);
1719 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
1720 if (check_packet_size &&
1721 packet_size < sizeof (struct libpcap_bt_monitor_phdr)) {
1723 * Uh-oh, the packet isn't big enough to even
1724 * have a pseudo-header.
1726 *err = WTAP_ERR_BAD_FILE;
1727 *err_info = g_strdup_printf("pcap: libpcap bluetooth monitor file has a %u-byte packet, too small to have even a pseudo-header",
1731 if (!pcap_read_bt_monitor_pseudoheader(fh,
1732 &phdr->pseudo_header, err, err_info))
1733 return -1; /* Read error */
1735 phdr_len = (int)sizeof (struct libpcap_bt_monitor_phdr);
1738 case WTAP_ENCAP_NFC_LLCP:
1739 if (check_packet_size && packet_size < LLCP_HEADER_LEN) {
1740 *err = WTAP_ERR_BAD_FILE;
1741 *err_info = g_strdup("pcap: libpcap llcp file too short");
1744 if (!pcap_read_llcp_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1745 return -1; /* Read error */
1746 phdr_len = LLCP_HEADER_LEN;
1749 case WTAP_ENCAP_PPP_WITH_PHDR:
1750 if (check_packet_size &&
1751 packet_size < sizeof (struct libpcap_ppp_phdr)) {
1753 * Uh-oh, the packet isn't big enough to even
1754 * have a pseudo-header.
1756 *err = WTAP_ERR_BAD_FILE;
1757 *err_info = g_strdup_printf("pcap: libpcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
1761 if (!pcap_read_ppp_pseudoheader(fh,
1762 &phdr->pseudo_header, err, err_info))
1763 return -1; /* Read error */
1765 phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
1768 case WTAP_ENCAP_ERF:
1769 if (check_packet_size &&
1770 packet_size < sizeof(struct erf_phdr) ) {
1772 * Uh-oh, the packet isn't big enough to even
1773 * have a pseudo-header.
1775 *err = WTAP_ERR_BAD_FILE;
1776 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
1781 if (!pcap_read_erf_pseudoheader(fh, phdr, &phdr->pseudo_header,
1783 return -1; /* Read error */
1785 phdr_len = (int)sizeof(struct erf_phdr);
1787 /* check the optional Extension header */
1788 if (!pcap_read_erf_exheader(fh, &phdr->pseudo_header, err, err_info,
1790 return -1; /* Read error */
1794 /* check the optional Multi Channel header */
1795 if (!pcap_read_erf_subheader(fh, &phdr->pseudo_header, err, err_info,
1797 return -1; /* Read error */
1801 if (check_packet_size &&
1802 packet_size < (guint)phdr_len) {
1804 * Uh-oh, the packet isn't big enough for the pseudo-
1807 *err = WTAP_ERR_BAD_FILE;
1808 *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)",
1809 packet_size, phdr_len);
1814 case WTAP_ENCAP_I2C:
1815 if (check_packet_size &&
1816 packet_size < sizeof (struct i2c_file_hdr)) {
1818 * Uh-oh, the packet isn't big enough to even
1819 * have a pseudo-header.
1821 *err = WTAP_ERR_BAD_FILE;
1822 *err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
1826 if (!pcap_read_i2c_pseudoheader(fh, &phdr->pseudo_header,
1828 return -1; /* Read error */
1831 * Don't count the pseudo-header as part of the packet.
1833 phdr_len = (int)sizeof (struct i2c_file_hdr);
1841 pcap_read_post_process(int file_type, int wtap_encap,
1842 struct wtap_pkthdr *phdr, guint8 *pd, gboolean bytes_swapped, int fcs_len)
1844 switch (wtap_encap) {
1846 case WTAP_ENCAP_ATM_PDUS:
1847 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1851 * Guess the traffic type based on the packet
1854 atm_guess_traffic_type(phdr, pd);
1859 * If this is ATM LANE traffic, try to guess what
1860 * type of LANE traffic it is based on the packet
1863 if (phdr->pseudo_header.atm.type == TRAF_LANE)
1864 atm_guess_lane_type(phdr, pd);
1868 case WTAP_ENCAP_ETHERNET:
1869 phdr->pseudo_header.eth.fcs_len = fcs_len;
1872 case WTAP_ENCAP_USB_LINUX:
1874 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, FALSE);
1877 case WTAP_ENCAP_USB_LINUX_MMAPPED:
1879 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, TRUE);
1882 case WTAP_ENCAP_NETANALYZER:
1884 * Not strictly necessary, as the netANALYZER
1885 * dissector calls the "Ethernet with FCS"
1886 * dissector, but we might as well set it.
1888 phdr->pseudo_header.eth.fcs_len = 4;
1891 case WTAP_ENCAP_NFLOG:
1893 pcap_byteswap_nflog_pseudoheader(phdr, pd);
1895 case WTAP_ENCAP_ERF:
1897 * Update packet size to account for ERF padding and snapping.
1898 * Captured length is minimum of wlen and previously calculated
1899 * caplen (which would have included padding but not phdr).
1901 phdr->len = phdr->pseudo_header.erf.phdr.wlen;
1902 phdr->caplen = MIN(phdr->len, phdr->caplen);
1911 pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
1917 case WTAP_ENCAP_ATM_PDUS:
1918 hdrsize = SUNATM_LEN;
1921 case WTAP_ENCAP_IRDA:
1922 hdrsize = IRDA_SLL_LEN;
1925 case WTAP_ENCAP_MTP2_WITH_PHDR:
1926 hdrsize = MTP2_HDR_LEN;
1929 case WTAP_ENCAP_LINUX_LAPD:
1930 hdrsize = LAPD_SLL_LEN;
1933 case WTAP_ENCAP_SITA:
1934 hdrsize = SITA_HDR_LEN;
1937 case WTAP_ENCAP_ERF:
1938 hdrsize = (int)sizeof (struct erf_phdr);
1939 switch (pseudo_header->erf.phdr.type & 0x7F) {
1941 case ERF_TYPE_MC_HDLC:
1942 case ERF_TYPE_MC_RAW:
1943 case ERF_TYPE_MC_ATM:
1944 case ERF_TYPE_MC_RAW_CHANNEL:
1945 case ERF_TYPE_MC_AAL5:
1946 case ERF_TYPE_MC_AAL2:
1947 case ERF_TYPE_COLOR_MC_HDLC_POS:
1948 hdrsize += (int)sizeof(struct erf_mc_hdr);
1951 hdrsize += (int)sizeof(struct erf_aal2_hdr);
1955 case ERF_TYPE_COLOR_ETH:
1956 case ERF_TYPE_DSM_COLOR_ETH:
1957 case ERF_TYPE_COLOR_HASH_ETH:
1958 hdrsize += (int)sizeof(struct erf_eth_hdr);
1966 * Add in the lengths of the extension headers.
1968 if (pseudo_header->erf.phdr.type & 0x80) {
1969 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1970 guint8 erf_exhdr[8];
1974 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
1975 type = erf_exhdr[0];
1978 } while (type & 0x80 && i < max);
1982 case WTAP_ENCAP_I2C:
1983 hdrsize = (int)sizeof (struct i2c_file_hdr);
1986 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1987 hdrsize = (int)sizeof (struct libpcap_bt_phdr);
1990 case WTAP_ENCAP_PPP_WITH_PHDR:
1991 hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
1994 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
1995 hdrsize = (int)sizeof (struct libpcap_bt_monitor_phdr);
2007 pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header,
2010 guint8 atm_hdr[SUNATM_LEN];
2011 guint8 irda_hdr[IRDA_SLL_LEN];
2012 guint8 lapd_hdr[LAPD_SLL_LEN];
2013 guint8 mtp2_hdr[MTP2_HDR_LEN];
2014 guint8 sita_hdr[SITA_HDR_LEN];
2015 guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
2016 guint8 erf_subhdr[sizeof(union erf_subhdr)];
2017 struct i2c_file_hdr i2c_hdr;
2018 struct libpcap_bt_phdr bt_hdr;
2019 struct libpcap_bt_monitor_phdr bt_monitor_hdr;
2020 struct libpcap_ppp_phdr ppp_hdr;
2022 size_t subhdr_size = 0;
2026 case WTAP_ENCAP_ATM_PDUS:
2028 * Write the ATM header.
2030 atm_hdr[SUNATM_FLAGS] =
2031 (pseudo_header->atm.channel == 0) ? 0x80 : 0x00;
2032 switch (pseudo_header->atm.aal) {
2034 case AAL_SIGNALLING:
2036 atm_hdr[SUNATM_FLAGS] |= 0x06;
2040 switch (pseudo_header->atm.type) {
2044 atm_hdr[SUNATM_FLAGS] |= 0x01;
2048 /* RFC 1483 LLC multiplexed traffic */
2049 atm_hdr[SUNATM_FLAGS] |= 0x02;
2054 atm_hdr[SUNATM_FLAGS] |= 0x05;
2059 atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi;
2060 phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci);
2061 if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err))
2063 wdh->bytes_dumped += sizeof(atm_hdr);
2066 case WTAP_ENCAP_IRDA:
2068 * Write the IrDA header.
2070 memset(irda_hdr, 0, sizeof(irda_hdr));
2071 phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET],
2072 pseudo_header->irda.pkttype);
2073 phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017);
2074 if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err))
2076 wdh->bytes_dumped += sizeof(irda_hdr);
2079 case WTAP_ENCAP_MTP2_WITH_PHDR:
2081 * Write the MTP2 header.
2083 memset(&mtp2_hdr, 0, sizeof(mtp2_hdr));
2084 mtp2_hdr[MTP2_SENT_OFFSET] = pseudo_header->mtp2.sent;
2085 mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET] = pseudo_header->mtp2.annex_a_used;
2086 phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET],
2087 pseudo_header->mtp2.link_number);
2088 if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err))
2090 wdh->bytes_dumped += sizeof(mtp2_hdr);
2093 case WTAP_ENCAP_LINUX_LAPD:
2095 * Write the LAPD header.
2097 memset(&lapd_hdr, 0, sizeof(lapd_hdr));
2098 phtons(&lapd_hdr[LAPD_SLL_PKTTYPE_OFFSET],
2099 pseudo_header->lapd.pkttype);
2100 phtons(&lapd_hdr[LAPD_SLL_PROTOCOL_OFFSET], ETH_P_LAPD);
2101 lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] =
2102 pseudo_header->lapd.we_network?0x01:0x00;
2103 if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err))
2105 wdh->bytes_dumped += sizeof(lapd_hdr);
2108 case WTAP_ENCAP_SITA:
2110 * Write the SITA header.
2112 memset(&sita_hdr, 0, sizeof(sita_hdr));
2113 sita_hdr[SITA_FLAGS_OFFSET] = pseudo_header->sita.sita_flags;
2114 sita_hdr[SITA_SIGNALS_OFFSET] = pseudo_header->sita.sita_signals;
2115 sita_hdr[SITA_ERRORS1_OFFSET] = pseudo_header->sita.sita_errors1;
2116 sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.sita_errors2;
2117 sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.sita_proto;
2118 if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err))
2120 wdh->bytes_dumped += sizeof(sita_hdr);
2123 case WTAP_ENCAP_ERF:
2125 * Write the ERF header.
2127 memset(&erf_hdr, 0, sizeof(erf_hdr));
2128 phtolell(&erf_hdr[0], pseudo_header->erf.phdr.ts);
2129 erf_hdr[8] = pseudo_header->erf.phdr.type;
2130 erf_hdr[9] = pseudo_header->erf.phdr.flags;
2133 * Recalculate rlen as padding (and maybe extension headers)
2134 * have been stripped from caplen.
2136 * XXX: Since we don't have phdr->caplen here, assume caplen was
2137 * calculated correctly and recalculate from wlen.
2139 phtons(&erf_hdr[10],
2140 MIN(pseudo_header->erf.phdr.rlen, pseudo_header->erf.phdr.wlen + pcap_get_phdr_size(WTAP_ENCAP_ERF, pseudo_header)));
2142 phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr);
2143 phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen);
2144 size = sizeof(struct erf_phdr);
2146 switch(pseudo_header->erf.phdr.type & 0x7F) {
2147 case ERF_TYPE_MC_HDLC:
2148 case ERF_TYPE_MC_RAW:
2149 case ERF_TYPE_MC_ATM:
2150 case ERF_TYPE_MC_RAW_CHANNEL:
2151 case ERF_TYPE_MC_AAL5:
2152 case ERF_TYPE_MC_AAL2:
2153 case ERF_TYPE_COLOR_MC_HDLC_POS:
2154 phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.mc_hdr);
2155 subhdr_size += (int)sizeof(struct erf_mc_hdr);
2158 phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.aal2_hdr);
2159 subhdr_size += (int)sizeof(struct erf_aal2_hdr);
2162 case ERF_TYPE_COLOR_ETH:
2163 case ERF_TYPE_DSM_COLOR_ETH:
2164 case ERF_TYPE_COLOR_HASH_ETH:
2165 memcpy(&erf_subhdr[0], &pseudo_header->erf.subhdr.eth_hdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
2166 subhdr_size += (int)sizeof(struct erf_eth_hdr);
2171 if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
2173 wdh->bytes_dumped += size;
2176 * Now write out the extension headers.
2178 if (pseudo_header->erf.phdr.type & 0x80) {
2179 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
2180 guint8 erf_exhdr[8];
2184 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
2185 type = erf_exhdr[0];
2186 /* Clear more extension headers bit if > 8 */
2188 erf_exhdr[0] = erf_exhdr[0] & 0x7F;
2190 if (!wtap_dump_file_write(wdh, erf_exhdr, 8, err))
2192 wdh->bytes_dumped += 8;
2194 } while (type & 0x80 && i < max);
2198 * Now write out the subheader.
2200 if(!wtap_dump_file_write(wdh, erf_subhdr, subhdr_size, err))
2202 wdh->bytes_dumped += subhdr_size;
2205 case WTAP_ENCAP_I2C:
2207 * Write the I2C header.
2209 memset(&i2c_hdr, 0, sizeof(i2c_hdr));
2210 i2c_hdr.bus = pseudo_header->i2c.bus |
2211 (pseudo_header->i2c.is_event ? 0x80 : 0x00);
2212 phtonl((guint8 *)&i2c_hdr.flags, pseudo_header->i2c.flags);
2213 if (!wtap_dump_file_write(wdh, &i2c_hdr, sizeof(i2c_hdr), err))
2215 wdh->bytes_dumped += sizeof(i2c_hdr);
2218 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
2219 bt_hdr.direction = GUINT32_TO_BE(pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV);
2220 if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err))
2222 wdh->bytes_dumped += sizeof bt_hdr;
2225 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
2226 bt_monitor_hdr.adapter_id = GUINT16_TO_BE(pseudo_header->btmon.adapter_id);
2227 bt_monitor_hdr.opcode = GUINT16_TO_BE(pseudo_header->btmon.opcode);
2229 if (!wtap_dump_file_write(wdh, &bt_monitor_hdr, sizeof bt_monitor_hdr, err))
2231 wdh->bytes_dumped += sizeof bt_monitor_hdr;
2234 case WTAP_ENCAP_PPP_WITH_PHDR:
2235 ppp_hdr.direction = (pseudo_header->p2p.sent ? LIBPCAP_PPP_PHDR_SENT : LIBPCAP_PPP_PHDR_RECV);
2236 if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err))
2238 wdh->bytes_dumped += sizeof ppp_hdr;
2245 * Editor modelines - http://www.wireshark.org/tools/modelines.html
2250 * indent-tabs-mode: t
2253 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
2254 * :indentSize=8:tabSize=8:noTabs=false: