2 * Code common to libpcap and pcap-NG file formats
5 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
7 * File format support for pcap-ng file format
8 * Copyright (c) 2007 by Ulf Lamping <ulf.lamping@web.de>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include "file_wrappers.h"
34 #include "pcap-encap.h"
35 #include "pcap-common.h"
38 * Map link-layer header types (LINKTYPE_ values) to Wiretap encapsulations.
40 * Either LBL NRG wasn't an adequate central registry (e.g., because of
41 * the slow rate of releases from them), or nobody bothered using them
42 * as a central registry, as many different groups have patched libpcap
43 * (and BPF, on the BSDs) to add new encapsulation types, and have ended
44 * up using the same DLT_ values for different encapsulation types.
46 * The Tcpdump Group now maintains the list of link-layer header types;
47 * they introduced a separate namespace of LINKTYPE_ values for the
48 * values to be used in capture files, and have libpcap map between
49 * those values in capture file headers and the DLT_ values that the
50 * pcap_datalink() and pcap_open_dead() APIs use. See
51 * http://www.tcpdump.org/linktypes.html for a list of LINKTYPE_ values.
53 * In most cases, the corresponding LINKTYPE_ and DLT_ values are the
54 * same. In the cases where the same link-layer header type was given
55 * different values in different OSes, a new LINKTYPE_ value was defined,
56 * different from all of the existing DLT_ values.
58 * This table maps LINKTYPE_ values to the corresponding Wiretap
59 * encapsulation. For cases where multiple DLT_ values were in use,
60 * it also checks what <pcap.h> defineds to determine how to interpret
61 * them, so that if a file was written by a version of libpcap prior
62 * to the introduction of the LINKTYPE_ values, and has a DLT_ value
63 * from the OS on which it was written rather than a LINKTYPE_ value
64 * as its linktype value in the file header, we map the numerical
65 * DLT_ value, as interpreted by the libpcap with which we're building
66 * Wireshark/Wiretap interprets them (which, if it doesn't support
67 * them at all, means we don't support them either - any capture files
68 * using them are foreign, and we don't hazard a guess as to which
69 * platform they came from; we could, I guess, choose the most likely
70 * platform), to the corresponding Wiretap encapsulation.
72 * Note: if you need a new encapsulation type for libpcap files, do
73 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
74 * add a new encapsulation type by changing an existing entry;
75 * leave the existing entries alone.
77 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking for
78 * a new LINKTYPE_/DLT_ value, and specifying the purpose of the new
79 * value. When you get the new LINKTYPE_/DLT_ value, use that numerical
80 * value in the "linktype_value" field of "pcap_to_wtap_map[]".
86 } pcap_to_wtap_map[] = {
88 * These are the values that are almost certainly the same
89 * in all libpcaps (I've yet to find one where the values
90 * in question are used for some purpose other than the
91 * one below, but...), and thus assigned as LINKTYPE_ values,
92 * and that Wiretap and Wireshark currently support.
94 { 0, WTAP_ENCAP_NULL }, /* null encapsulation */
95 { 1, WTAP_ENCAP_ETHERNET },
96 { 3, WTAP_ENCAP_AX25 },
97 { 6, WTAP_ENCAP_TOKEN_RING }, /* IEEE 802 Networks - assume token ring */
98 { 7, WTAP_ENCAP_ARCNET },
99 { 8, WTAP_ENCAP_SLIP },
100 { 9, WTAP_ENCAP_PPP },
101 #ifdef BIT_SWAPPED_MAC_ADDRS
102 { 10, WTAP_ENCAP_FDDI_BITSWAPPED },
104 { 10, WTAP_ENCAP_FDDI },
107 { 32, WTAP_ENCAP_REDBACK },
110 * 50 is DLT_PPP_SERIAL in NetBSD; it appears that DLT_PPP
111 * on BSD (at least according to standard tcpdump) has, as
112 * the first octet, an indication of whether the packet was
113 * transmitted or received (rather than having the standard
114 * PPP address value of 0xff), but that DLT_PPP_SERIAL puts
115 * a real live PPP header there, or perhaps a Cisco PPP header
116 * as per section 4.3.1 of RFC 1547 (implementations of this
117 * exist in various BSDs in "sys/net/if_spppsubr.c", and
118 * I think also exist either in standard Linux or in
119 * various Linux patches; the implementations show how to handle
120 * Cisco keepalive packets).
122 * However, I don't see any obvious place in FreeBSD "if_ppp.c"
123 * where anything other than the standard PPP header would be
124 * passed up. I see some stuff that sets the first octet
125 * to 0 for incoming and 1 for outgoing packets before applying
126 * a BPF filter to see whether to drop packets whose protocol
127 * field has the 0x8000 bit set, i.e. network control protocols -
128 * those are handed up to userland - but that code puts the
129 * address field back before passing the packet up.
131 * I also don't see anything immediately obvious that munges
132 * the address field for sync PPP, either.
134 * Wireshark currently assumes that if the first octet of a
135 * PPP frame is 0xFF, it's the address field and is followed
136 * by a control field and a 2-byte protocol, otherwise the
137 * address and control fields are absent and the frame begins
138 * with a protocol field. If we ever see a BSD/OS PPP
139 * capture, we'll have to handle it differently, and we may
140 * have to handle standard BSD captures differently if, in fact,
141 * they don't have 0xff 0x03 as the first two bytes - but, as per
142 * the two paragraphs preceding this, it's not clear that
143 * the address field *is* munged into an incoming/outgoing
144 * field when the packet is handed to the BPF device.
146 * For now, we just map DLT_PPP_SERIAL to WTAP_ENCAP_PPP, as
147 * we treat WTAP_ENCAP_PPP packets as if those beginning with
148 * 0xff have the standard RFC 1662 "PPP in HDLC-like Framing"
149 * 0xff 0x03 address/control header, and DLT_PPP_SERIAL frames
150 * appear to contain that unless they're Cisco frames (if we
151 * ever see a capture with them, we'd need to implement the
152 * RFC 1547 stuff, and the keepalive protocol stuff).
154 * We may have to distinguish between "PPP where if it doesn't
155 * begin with 0xff there's no HDLC encapsulation and the frame
156 * begins with the protocol field" (which is how we handle
157 * WTAP_ENCAP_PPP now) and "PPP where there's either HDLC
158 * encapsulation or Cisco PPP" (which is what DLT_PPP_SERIAL
161 * XXX - NetBSD has DLT_HDLC, which appears to be used for
162 * Cisco HDLC. Ideally, they should use DLT_PPP_SERIAL
163 * only for real live HDLC-encapsulated PPP, not for Cisco
166 { 50, WTAP_ENCAP_PPP },
169 * Used by NetBSD and OpenBSD pppoe(4).
171 { 51, WTAP_ENCAP_PPP_ETHER },
174 * Apparently used by the Axent Raptor firewall (now Symantec
175 * Enterprise Firewall).
176 * Thanks, Axent, for not reserving that type with tcpdump.org
177 * and not telling anybody about it.
179 { 99, WTAP_ENCAP_SYMANTEC },
182 * These are the values that libpcap 0.5 and later use in
183 * capture file headers, in an attempt to work around the
184 * confusion decried above, and that Wiretap and Wireshark
185 * currently support. I.e., they're the LINKTYPE_ values
186 * for RFC 1483 ATM and "raw IP", respectively, not the
187 * DLT_ values for them on all platforms.
189 { 100, WTAP_ENCAP_ATM_RFC1483 },
190 { 101, WTAP_ENCAP_RAW_IP },
193 * More values used by libpcap 0.5 as DLT_ values and used by the
194 * current CVS version of libpcap in capture file headers.
195 * They are not yet handled in Wireshark.
196 * If we get a capture that contains them, we'll implement them.
198 { 102, WTAP_ENCAP_SLIP_BSDOS },
199 { 103, WTAP_ENCAP_PPP_BSDOS },
203 * These ones are handled in Wireshark, though.
205 { 104, WTAP_ENCAP_CHDLC }, /* Cisco HDLC */
206 { 105, WTAP_ENCAP_IEEE_802_11 }, /* IEEE 802.11 */
207 { 106, WTAP_ENCAP_LINUX_ATM_CLIP },
208 { 107, WTAP_ENCAP_FRELAY }, /* Frame Relay */
209 { 108, WTAP_ENCAP_LOOP }, /* OpenBSD loopback */
210 { 109, WTAP_ENCAP_ENC }, /* OpenBSD IPSEC enc */
212 { 110, WTAP_ENCAP_LANE_802_3 },/* ATM LANE 802.3 */
213 { 111, WTAP_ENCAP_HIPPI }, /* NetBSD HIPPI */
215 { 112, WTAP_ENCAP_CHDLC }, /* NetBSD HDLC framing */
218 * Linux "cooked mode" captures, used by the current CVS version
221 * it could be a packet in Cisco's ERSPAN encapsulation which uses
222 * this number as well (why can't people stick to protocols when it
223 * comes to allocating/using DLT types).
225 { 113, WTAP_ENCAP_SLL }, /* Linux cooked capture */
227 { 114, WTAP_ENCAP_LOCALTALK }, /* Localtalk */
230 * The tcpdump.org version of libpcap uses 117, rather than 17,
231 * for OpenBSD packet filter logging, so as to avoid conflicting
232 * with DLT_LANE8023 in SuSE 6.3 libpcap.
234 { 117, WTAP_ENCAP_PFLOG },
236 { 118, WTAP_ENCAP_CISCO_IOS },
237 { 119, WTAP_ENCAP_IEEE_802_11_PRISM }, /* 802.11 plus Prism monitor mode radio header */
238 { 121, WTAP_ENCAP_HHDLC }, /* HiPath HDLC */
239 { 122, WTAP_ENCAP_IP_OVER_FC }, /* RFC 2625 IP-over-FC */
240 { 123, WTAP_ENCAP_ATM_PDUS }, /* SunATM */
241 { 127, WTAP_ENCAP_IEEE_802_11_RADIOTAP }, /* 802.11 plus radiotap radio header */
242 { 128, WTAP_ENCAP_TZSP }, /* Tazmen Sniffer Protocol */
243 { 129, WTAP_ENCAP_ARCNET_LINUX },
244 { 130, WTAP_ENCAP_JUNIPER_MLPPP }, /* Juniper MLPPP on ML-, LS-, AS- PICs */
245 { 131, WTAP_ENCAP_JUNIPER_MLFR }, /* Juniper MLFR (FRF.15) on ML-, LS-, AS- PICs */
246 { 133, WTAP_ENCAP_JUNIPER_GGSN},
248 * Values 132 and 134 not listed here are reserved for use
249 * in Juniper hardware.
251 { 135, WTAP_ENCAP_JUNIPER_ATM2 }, /* various encapsulations captured on the ATM2 PIC */
252 { 136, WTAP_ENCAP_JUNIPER_SVCS }, /* various encapsulations captured on the services PIC */
253 { 137, WTAP_ENCAP_JUNIPER_ATM1 }, /* various encapsulations captured on the ATM1 PIC */
255 { 138, WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 },
256 /* Apple IP-over-IEEE 1394 */
258 { 139, WTAP_ENCAP_MTP2_WITH_PHDR },
259 { 140, WTAP_ENCAP_MTP2 },
260 { 141, WTAP_ENCAP_MTP3 },
261 { 142, WTAP_ENCAP_SCCP },
262 { 143, WTAP_ENCAP_DOCSIS },
263 { 144, WTAP_ENCAP_IRDA }, /* IrDA capture */
265 /* Reserved for private use. */
266 { 147, WTAP_ENCAP_USER0 },
267 { 148, WTAP_ENCAP_USER1 },
268 { 149, WTAP_ENCAP_USER2 },
269 { 150, WTAP_ENCAP_USER3 },
270 { 151, WTAP_ENCAP_USER4 },
271 { 152, WTAP_ENCAP_USER5 },
272 { 153, WTAP_ENCAP_USER6 },
273 { 154, WTAP_ENCAP_USER7 },
274 { 155, WTAP_ENCAP_USER8 },
275 { 156, WTAP_ENCAP_USER9 },
276 { 157, WTAP_ENCAP_USER10 },
277 { 158, WTAP_ENCAP_USER11 },
278 { 159, WTAP_ENCAP_USER12 },
279 { 160, WTAP_ENCAP_USER13 },
280 { 161, WTAP_ENCAP_USER14 },
281 { 162, WTAP_ENCAP_USER15 },
283 { 163, WTAP_ENCAP_IEEE_802_11_AVS }, /* 802.11 plus AVS radio header */
286 * 164 is reserved for Juniper-private chassis-internal
287 * meta-information such as QoS profiles, etc..
290 { 165, WTAP_ENCAP_BACNET_MS_TP },
293 * 166 is reserved for a PPP variant in which the first byte
294 * of the 0xff03 header, the 0xff, is replaced by a direction
295 * byte. I don't know whether any captures look like that,
296 * but it is used for some Linux IP filtering (ipfilter?).
299 /* Ethernet PPPoE frames captured on a service PIC */
300 { 167, WTAP_ENCAP_JUNIPER_PPPOE },
303 * 168 is reserved for more Juniper private-chassis-
304 * internal meta-information.
307 { 169, WTAP_ENCAP_GPRS_LLC },
309 /* ITU-T G.7041/Y.1303 Generic Framing Procedure. */
310 { 170, WTAP_ENCAP_GFP_T },
311 { 171, WTAP_ENCAP_GFP_F },
313 /* Registered by Gcom, Inc. */
314 { 172, WTAP_ENCAP_GCOM_TIE1 },
315 { 173, WTAP_ENCAP_GCOM_SERIAL },
317 { 177, WTAP_ENCAP_LINUX_LAPD },
319 /* Ethernet frames prepended with meta-information */
320 { 178, WTAP_ENCAP_JUNIPER_ETHER },
321 /* PPP frames prepended with meta-information */
322 { 179, WTAP_ENCAP_JUNIPER_PPP },
323 /* Frame-Relay frames prepended with meta-information */
324 { 180, WTAP_ENCAP_JUNIPER_FRELAY },
325 /* C-HDLC frames prepended with meta-information */
326 { 181, WTAP_ENCAP_JUNIPER_CHDLC },
327 /* VOIP Frames prepended with meta-information */
328 { 183, WTAP_ENCAP_JUNIPER_VP },
329 /* Virtual Network Frames prepended with meta-information */
330 { 184, WTAP_ENCAP_JUNIPER_VN },
331 /* USB packets from FreeBSD's USB BPF tap */
332 { 186, WTAP_ENCAP_USB_FREEBSD },
333 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
334 { 187, WTAP_ENCAP_BLUETOOTH_H4 },
335 /* IEEE 802.16 MAC Common Part Sublayer */
336 { 188, WTAP_ENCAP_IEEE802_16_MAC_CPS },
337 /* USB packets with Linux-specified header */
338 { 189, WTAP_ENCAP_USB_LINUX },
340 { 190, WTAP_ENCAP_CAN20B },
341 /* Per-Packet Information header */
342 { 192, WTAP_ENCAP_PPI },
343 /* IEEE 802.15.4 Wireless PAN */
344 { 195, WTAP_ENCAP_IEEE802_15_4 },
345 /* SITA File Encapsulation */
346 { 196, WTAP_ENCAP_SITA },
347 /* Endace Record File Encapsulation */
348 { 197, WTAP_ENCAP_ERF },
350 { 199, WTAP_ENCAP_IPMB },
351 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
352 { 201, WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR },
353 /* AX.25 packet with a 1-byte KISS header */
354 { 202, WTAP_ENCAP_AX25_KISS },
356 { 203, WTAP_ENCAP_LAPD },
357 /* PPP with pseudoheader */
358 { 204, WTAP_ENCAP_PPP_WITH_PHDR },
360 { 209, WTAP_ENCAP_I2C },
362 { 210, WTAP_ENCAP_FLEXRAY },
364 { 211, WTAP_ENCAP_MOST },
366 { 212, WTAP_ENCAP_LIN },
367 /* X2E Xoraya serial frame */
368 { 213, WTAP_ENCAP_X2E_SERIAL },
369 /* X2E Xoraya frame */
370 { 214, WTAP_ENCAP_X2E_XORAYA },
371 /* IEEE 802.15.4 Wireless PAN non-ASK PHY */
372 { 215, WTAP_ENCAP_IEEE802_15_4_NONASK_PHY },
373 /* USB packets with padded Linux-specified header */
374 { 220, WTAP_ENCAP_USB_LINUX_MMAPPED },
375 /* Fibre Channel FC-2 frame */
376 { 224, WTAP_ENCAP_FIBRE_CHANNEL_FC2 },
377 /* Fibre Channel FC-2 frame with Delimiter */
378 { 225, WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS },
380 { 226, WTAP_ENCAP_IPNET },
381 /* SocketCAN frame */
382 { 227, WTAP_ENCAP_SOCKETCAN },
384 { 228, WTAP_ENCAP_RAW_IP4 },
386 { 229, WTAP_ENCAP_RAW_IP6 },
387 /* IEEE 802.15.4 Wireless PAN no fcs */
388 { 230, WTAP_ENCAP_IEEE802_15_4_NOFCS },
390 { 231, WTAP_ENCAP_DBUS },
391 /* DVB-CI (Common Interface) */
392 { 235, WTAP_ENCAP_DVBCI },
394 { 236, WTAP_ENCAP_MUX27010 },
395 /* STANAG 5066 - DTS(Data Transfer Sublayer) PDU */
396 { 237, WTAP_ENCAP_STANAG_5066_D_PDU },
398 { 239, WTAP_ENCAP_NFLOG },
399 /* netANALYZER pseudo-header followed by Ethernet with CRC */
400 { 240, WTAP_ENCAP_NETANALYZER },
401 /* netANALYZER pseudo-header in transparent mode */
402 { 241, WTAP_ENCAP_NETANALYZER_TRANSPARENT },
403 /* IP-over-Infiniband, as specified by RFC 4391 section 6 */
404 { 242, WTAP_ENCAP_IP_OVER_IB_PCAP },
405 /* ISO/IEC 13818-1 MPEG2-TS packets */
406 { 243, WTAP_ENCAP_MPEG_2_TS },
408 { 245, WTAP_ENCAP_NFC_LLCP },
410 { 248, WTAP_ENCAP_SCTP},
412 { 249, WTAP_ENCAP_USBPCAP},
414 { 250, WTAP_ENCAP_RTAC_SERIAL},
415 /* Bluetooth Low Energy Link Layer */
416 { 251, WTAP_ENCAP_BLUETOOTH_LE_LL},
417 /* Wireshark Upper PDU export */
418 { 252, WTAP_ENCAP_WIRESHARK_UPPER_PDU},
419 /* Netlink Protocol (nlmon devices) */
420 { 253, WTAP_ENCAP_NETLINK },
421 /* Bluetooth Linux Monitor */
422 { 254, WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR },
423 /* Bluetooth BR/EDR Baseband RF captures */
424 { 255, WTAP_ENCAP_BLUETOOTH_BREDR_BB },
425 /* Bluetooth Low Energy Link Layer RF captures */
426 { 256, WTAP_ENCAP_BLUETOOTH_LE_LL_WITH_PHDR },
429 { 258, WTAP_ENCAP_PKTAP },
431 /* Ethernet Passive Optical Network */
432 { 259, WTAP_ENCAP_EPON },
434 /* IPMI Trace Data Collection */
435 { 260, WTAP_ENCAP_IPMI_TRACE },
437 /* ISO14443 contactless smartcard standards */
438 { 264, WTAP_ENCAP_ISO14443 },
443 * If you need a new encapsulation type for libpcap files, do
444 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
445 * add a new encapsulation type by changing an existing entry;
446 * leave the existing entries alone.
448 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
449 * for a new DLT_ value, and specifying the purpose of the new value.
450 * When you get the new DLT_ value, use that numerical value in
451 * the "linktype_value" field of "pcap_to_wtap_map[]".
455 * The following are entries for libpcap type values that have
456 * different meanings on different OSes. I.e., these are DLT_
457 * values that are different on different OSes, and that have
458 * a separate LINKTYPE_ value assigned to them.
460 * We put these *after* the entries for the LINKTYPE_ values for
461 * those Wiretap encapsulation types, so that, when writing a
462 * pcap or pcap-ng file, Wireshark writes the LINKTYPE_ value,
463 * not the OS's DLT_ value, as the file's link-layer header type
464 * for pcap or the interface's link-layer header type.
468 * 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
469 * seen that define anything other than DLT_ATM_RFC1483 as 11 are
470 * the BSD/OS one, which defines DLT_FR as 11. We handle it as
471 * Frame Relay on BSD/OS and LLC-encapsulated ATM on all other
474 #if defined(__bsdi__) /* BSD/OS */
475 { 11, WTAP_ENCAP_FRELAY },
477 { 11, WTAP_ENCAP_ATM_RFC1483 },
481 * 12 is DLT_RAW on most platforms, but it's DLT_C_HDLC on
482 * BSD/OS, and DLT_LOOP on OpenBSD.
484 * We don't yet handle DLT_C_HDLC, but we can handle DLT_LOOP
485 * (it's just like DLT_NULL, only with the AF_ value in network
486 * rather than host byte order - Wireshark figures out the
487 * byte order from the data, so we don't care what byte order
488 * it's in), so, on OpenBSD, interpret 12 as WTAP_ENCAP_LOOP,
489 * otherwise, if we're not on BSD/OS, interpret it as
492 #if defined(__OpenBSD__)
493 { 12, WTAP_ENCAP_LOOP },
494 #elif defined(__bsdi__) /* BSD/OS */
496 * Put entry for Cisco HDLC here.
497 * XXX - is this just WTAP_ENCAP_CHDLC, i.e. does the frame
498 * start with a 4-byte Cisco HDLC header?
501 { 12, WTAP_ENCAP_RAW_IP },
505 * 13 is DLT_SLIP_BSDOS on FreeBSD and NetBSD, but those OSes
506 * don't actually generate it. I infer that BSD/OS translates
507 * DLT_SLIP from the kernel BPF code to DLT_SLIP_BSDOS in
508 * libpcap, as the BSD/OS link-layer header is different;
509 * however, in BSD/OS, DLT_SLIP_BSDOS is 15.
511 * From this, I infer that there's no point in handling 13
514 * 13 is DLT_ATM_RFC1483 on BSD/OS.
516 * 13 is DLT_ENC in OpenBSD, which is, I suspect, some kind
517 * of decrypted IPsec traffic.
519 * We treat 13 as WTAP_ENCAP_ENC on all systems except those
520 * that define DLT_ATM_RFC1483 as 13 - presumably only
521 * BSD/OS does so - so that, on BSD/OS systems, we still
522 * treate 13 as WTAP_ENCAP_ATM_RFC1483, but, on all other
523 * systems, we can read OpenBSD DLT_ENC captures.
525 #if defined(__bsdi__) /* BSD/OS */
526 { 13, WTAP_ENCAP_ATM_RFC1483 },
528 { 13, WTAP_ENCAP_ENC },
532 * 14 is DLT_PPP_BSDOS on FreeBSD and NetBSD, but those OSes
533 * don't actually generate it. I infer that BSD/OS translates
534 * DLT_PPP from the kernel BPF code to DLT_PPP_BSDOS in
535 * libpcap, as the BSD/OS link-layer header is different;
536 * however, in BSD/OS, DLT_PPP_BSDOS is 16.
538 * From this, I infer that there's no point in handling 14
541 * 14 is DLT_RAW on BSD/OS and OpenBSD.
543 { 14, WTAP_ENCAP_RAW_IP },
548 * DLT_SLIP_BSDOS on BSD/OS;
550 * DLT_HIPPI on NetBSD;
552 * DLT_LANE8023 with Alexey Kuznetzov's patches for
555 * DLT_I4L_RAWIP with the ISDN4Linux patches for libpcap
558 * but we don't currently handle any of those.
564 * DLT_PPP_BSDOS on BSD/OS;
566 * DLT_HDLC on NetBSD (Cisco HDLC);
568 * DLT_CIP with Alexey Kuznetzov's patches for
569 * Linux libpcap - this is WTAP_ENCAP_LINUX_ATM_CLIP;
571 * DLT_I4L_IP with the ISDN4Linux patches for libpcap
574 #if defined(__NetBSD__)
575 { 16, WTAP_ENCAP_CHDLC },
576 #elif !defined(__bsdi__)
578 * If you care about the two different Linux interpretations
579 * of 16, fix it yourself.
581 { 16, WTAP_ENCAP_LINUX_ATM_CLIP },
585 * 17 is DLT_LANE8023 in SuSE 6.3 libpcap; we don't currently
587 * It is also used as the PF (Packet Filter) logging format beginning
588 * with OpenBSD 3.0; we use 17 for PF logs on OpenBSD and don't
591 #if defined(__OpenBSD__)
592 { 17, WTAP_ENCAP_OLD_PFLOG },
596 * 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
597 * DLT_CIP of 16 that the Alexey Kuznetzov patches for
598 * libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
599 * I've not found any libpcap that uses it for any other purpose -
600 * hopefully nobody will do so in the future.
602 { 18, WTAP_ENCAP_LINUX_ATM_CLIP },
605 * 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
606 * recent versions I've seen of the Linux ATM distribution;
607 * I've not yet found any libpcap that uses it for any other
608 * purpose - hopefully nobody will do so in the future.
610 { 19, WTAP_ENCAP_LINUX_ATM_CLIP },
615 * If you need a new encapsulation type for libpcap files, do
616 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
617 * add a new encapsulation type by changing an existing entry;
618 * leave the existing entries alone.
620 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
621 * for a new DLT_ value, and specifying the purpose of the new value.
622 * When you get the new DLT_ value, use that numerical value in
623 * the "linktype_value" field of "pcap_to_wtap_map[]".
626 #define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0])
629 wtap_pcap_encap_to_wtap_encap(int encap)
633 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
634 if (pcap_to_wtap_map[i].linktype_value == encap)
635 return pcap_to_wtap_map[i].wtap_encap_value;
637 return WTAP_ENCAP_UNKNOWN;
641 wtap_wtap_encap_to_pcap_encap(int encap)
647 case WTAP_ENCAP_FDDI:
648 case WTAP_ENCAP_FDDI_BITSWAPPED:
650 * Special-case WTAP_ENCAP_FDDI and
651 * WTAP_ENCAP_FDDI_BITSWAPPED; both of them get mapped
652 * to DLT_FDDI (even though that may mean that the bit
653 * order in the FDDI MAC addresses is wrong; so it goes
654 * - libpcap format doesn't record the byte order,
655 * so that's not fixable).
657 * The pcap_to_wtap_map[] table will only have an
658 * entry for one of the above, which is why we have
659 * to special-case them.
661 return 10; /* that's DLT_FDDI */
663 case WTAP_ENCAP_NETTL_FDDI:
665 * This will discard the nettl information, as that's
666 * in the pseudo-header.
668 * XXX - what about Ethernet and Token Ring?
670 return 10; /* that's DLT_FDDI */
672 case WTAP_ENCAP_FRELAY_WITH_PHDR:
674 * This will discard the pseudo-header information.
678 case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
680 * Map this to DLT_IEEE802_11, for now, even though
681 * that means the radio information will be lost.
682 * We should try to map those values to radiotap
683 * values and write this out as a radiotap file,
689 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
690 if (pcap_to_wtap_map[i].wtap_encap_value == encap)
691 return pcap_to_wtap_map[i].linktype_value;
697 wtap_encap_requires_phdr(int wtap_encap)
699 switch (wtap_encap) {
701 case WTAP_ENCAP_ATM_PDUS:
702 case WTAP_ENCAP_IRDA:
703 case WTAP_ENCAP_MTP2_WITH_PHDR:
704 case WTAP_ENCAP_LINUX_LAPD:
705 case WTAP_ENCAP_SITA:
706 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
707 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
708 case WTAP_ENCAP_NFC_LLCP:
709 case WTAP_ENCAP_PPP_WITH_PHDR:
719 * Various pseudo-headers that appear at the beginning of packet data.
721 * We represent them as sets of offsets, as they might not be aligned on
722 * an appropriate structure boundary in the buffer, and as that makes them
723 * independent of the way the compiler might align fields.
727 * The link-layer header on SunATM packets.
729 #define SUNATM_FLAGS 0 /* destination and traffic type - 1 byte */
730 #define SUNATM_VPI 1 /* VPI - 1 byte */
731 #define SUNATM_VCI 2 /* VCI - 2 bytes */
732 #define SUNATM_LEN 4 /* length of the header */
735 * The link-layer header on Nokia IPSO ATM packets.
737 #define NOKIAATM_FLAGS 0 /* destination - 1 byte */
738 #define NOKIAATM_VPI 1 /* VPI - 1 byte */
739 #define NOKIAATM_VCI 2 /* VCI - 2 bytes */
740 #define NOKIAATM_LEN 4 /* length of the header */
743 * The link-layer header on Nokia IPSO packets.
745 #define NOKIA_LEN 4 /* length of the header */
748 * The fake link-layer header of IrDA packets as introduced by Jean Tourrilhes
751 #define IRDA_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
752 /* 12 unused bytes */
753 #define IRDA_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
754 #define IRDA_SLL_LEN 16 /* length of the header */
757 * A header containing additional MTP information.
759 #define MTP2_SENT_OFFSET 0 /* 1 byte */
760 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
761 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
762 #define MTP2_HDR_LEN 4 /* length of the header */
765 * A header containing additional SITA WAN information.
767 #define SITA_FLAGS_OFFSET 0 /* 1 byte */
768 #define SITA_SIGNALS_OFFSET 1 /* 1 byte */
769 #define SITA_ERRORS1_OFFSET 2 /* 1 byte */
770 #define SITA_ERRORS2_OFFSET 3 /* 1 byte */
771 #define SITA_PROTO_OFFSET 4 /* 1 byte */
772 #define SITA_HDR_LEN 5 /* length of the header */
775 * The fake link-layer header of LAPD packets.
778 #define ETH_P_LAPD 0x0030
781 #define LAPD_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
782 #define LAPD_SLL_HATYPE_OFFSET 2 /* hardware address type - 2 bytes */
783 #define LAPD_SLL_HALEN_OFFSET 4 /* hardware address length - 2 bytes */
784 #define LAPD_SLL_ADDR_OFFSET 6 /* address - 8 bytes */
785 #define LAPD_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
786 #define LAPD_SLL_LEN 16 /* length of the header */
789 * The NFC LLCP per-packet header.
791 #define LLCP_ADAPTER_OFFSET 0
792 #define LLCP_FLAGS_OFFSET 1
793 #define LLCP_HEADER_LEN 2
796 * I2C link-layer on-disk format
798 struct i2c_file_hdr {
804 pcap_read_sunatm_pseudoheader(FILE_T fh,
805 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
807 guint8 atm_phdr[SUNATM_LEN];
811 if (!wtap_read_bytes(fh, atm_phdr, SUNATM_LEN, err, err_info))
814 vpi = atm_phdr[SUNATM_VPI];
815 vci = pntoh16(&atm_phdr[SUNATM_VCI]);
817 switch (atm_phdr[SUNATM_FLAGS] & 0x0F) {
819 case 0x01: /* LANE */
820 pseudo_header->atm.aal = AAL_5;
821 pseudo_header->atm.type = TRAF_LANE;
824 case 0x02: /* RFC 1483 LLC multiplexed traffic */
825 pseudo_header->atm.aal = AAL_5;
826 pseudo_header->atm.type = TRAF_LLCMX;
829 case 0x05: /* ILMI */
830 pseudo_header->atm.aal = AAL_5;
831 pseudo_header->atm.type = TRAF_ILMI;
834 case 0x06: /* Q.2931 */
835 pseudo_header->atm.aal = AAL_SIGNALLING;
836 pseudo_header->atm.type = TRAF_UNKNOWN;
839 case 0x03: /* MARS (RFC 2022) */
840 pseudo_header->atm.aal = AAL_5;
841 pseudo_header->atm.type = TRAF_UNKNOWN;
844 case 0x04: /* IFMP (Ipsilon Flow Management Protocol; see RFC 1954) */
845 pseudo_header->atm.aal = AAL_5;
846 pseudo_header->atm.type = TRAF_UNKNOWN; /* XXX - TRAF_IPSILON? */
851 * Assume it's AAL5, unless it's VPI 0 and VCI 5, in which
852 * case assume it's AAL_SIGNALLING; we know nothing more
855 * XXX - is this necessary? Or are we guaranteed that
856 * all signalling traffic has a type of 0x06?
858 * XXX - is this guaranteed to be AAL5? Or, if the type is
859 * 0x00 ("raw"), might it be non-AAL5 traffic?
861 if (vpi == 0 && vci == 5)
862 pseudo_header->atm.aal = AAL_SIGNALLING;
864 pseudo_header->atm.aal = AAL_5;
865 pseudo_header->atm.type = TRAF_UNKNOWN;
868 pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
870 pseudo_header->atm.vpi = vpi;
871 pseudo_header->atm.vci = vci;
872 pseudo_header->atm.channel = (atm_phdr[SUNATM_FLAGS] & 0x80) ? 0 : 1;
874 /* We don't have this information */
875 pseudo_header->atm.flags = 0;
876 pseudo_header->atm.cells = 0;
877 pseudo_header->atm.aal5t_u2u = 0;
878 pseudo_header->atm.aal5t_len = 0;
879 pseudo_header->atm.aal5t_chksum = 0;
885 pcap_read_nokiaatm_pseudoheader(FILE_T fh,
886 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
888 guint8 atm_phdr[NOKIAATM_LEN];
892 if (!wtap_read_bytes(fh, atm_phdr, NOKIAATM_LEN, err, err_info))
895 vpi = atm_phdr[NOKIAATM_VPI];
896 vci = pntoh16(&atm_phdr[NOKIAATM_VCI]);
898 pseudo_header->atm.vpi = vpi;
899 pseudo_header->atm.vci = vci;
900 pseudo_header->atm.channel = (atm_phdr[NOKIAATM_FLAGS] & 0x80) ? 0 : 1;
902 /* We don't have this information */
903 pseudo_header->atm.flags = 0;
904 pseudo_header->atm.cells = 0;
905 pseudo_header->atm.aal5t_u2u = 0;
906 pseudo_header->atm.aal5t_len = 0;
907 pseudo_header->atm.aal5t_chksum = 0;
913 pcap_read_nokia_pseudoheader(FILE_T fh,
914 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
916 guint8 phdr[NOKIA_LEN];
919 /* backtrack to read the 4 mysterious bytes that aren't considered
920 * part of the packet size
922 if (file_seek(fh, -NOKIA_LEN, SEEK_CUR, err) == -1)
924 *err = file_error(fh, err_info);
926 *err = WTAP_ERR_SHORT_READ;
930 if (!wtap_read_bytes(fh, phdr, NOKIA_LEN, err, err_info))
933 memcpy(pseudo_header->nokia.stuff, phdr, NOKIA_LEN);
939 pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
940 int *err, gchar **err_info)
942 guint8 irda_phdr[IRDA_SLL_LEN];
944 if (!wtap_read_bytes(fh, irda_phdr, IRDA_SLL_LEN, err, err_info))
947 if (pntoh16(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
948 *err = WTAP_ERR_BAD_FILE;
949 if (err_info != NULL)
950 *err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
954 pseudo_header->irda.pkttype = pntoh16(&irda_phdr[IRDA_SLL_PKTTYPE_OFFSET]);
960 pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
962 guint8 mtp2_hdr[MTP2_HDR_LEN];
964 if (!wtap_read_bytes(fh, mtp2_hdr, MTP2_HDR_LEN, err, err_info))
967 pseudo_header->mtp2.sent = mtp2_hdr[MTP2_SENT_OFFSET];
968 pseudo_header->mtp2.annex_a_used = mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET];
969 pseudo_header->mtp2.link_number = pntoh16(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET]);
975 pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
976 int *err, gchar **err_info)
978 guint8 lapd_phdr[LAPD_SLL_LEN];
980 if (!wtap_read_bytes(fh, lapd_phdr, LAPD_SLL_LEN, err, err_info))
983 if (pntoh16(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
984 *err = WTAP_ERR_BAD_FILE;
985 if (err_info != NULL)
986 *err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
990 pseudo_header->lapd.pkttype = pntoh16(&lapd_phdr[LAPD_SLL_PKTTYPE_OFFSET]);
991 pseudo_header->lapd.we_network = !!lapd_phdr[LAPD_SLL_ADDR_OFFSET+0];
997 pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
999 guint8 sita_phdr[SITA_HDR_LEN];
1001 if (!wtap_read_bytes(fh, sita_phdr, SITA_HDR_LEN, err, err_info))
1004 pseudo_header->sita.sita_flags = sita_phdr[SITA_FLAGS_OFFSET];
1005 pseudo_header->sita.sita_signals = sita_phdr[SITA_SIGNALS_OFFSET];
1006 pseudo_header->sita.sita_errors1 = sita_phdr[SITA_ERRORS1_OFFSET];
1007 pseudo_header->sita.sita_errors2 = sita_phdr[SITA_ERRORS2_OFFSET];
1008 pseudo_header->sita.sita_proto = sita_phdr[SITA_PROTO_OFFSET];
1014 * When not using the memory-mapped interface to capture USB events,
1015 * code that reads those events can use the MON_IOCX_GET ioctl to
1016 * read a 48-byte header consisting of a "struct linux_usb_phdr", as
1017 * defined below, followed immediately by one of:
1019 * 8 bytes of a "struct usb_device_setup_hdr", if "setup_flag"
1020 * in the preceding "struct linux_usb_phdr" is 0;
1022 * in Linux 2.6.30 or later, 8 bytes of a "struct iso_rec", if
1023 * this is an isochronous transfer;
1025 * 8 bytes of junk, otherwise.
1027 * In Linux 2.6.31 and later, it can also use the MON_IOCX_GETX ioctl
1028 * to read a 64-byte header; that header consists of the 48 bytes
1029 * above, followed immediately by 16 bytes of a "struct linux_usb_phdr_ext",
1032 * In Linux 2.6.21 and later, there's a memory-mapped interface to
1033 * capture USB events. In that interface, the events in the memory-mapped
1034 * buffer have a 64-byte header, followed immediately by the data.
1035 * In Linux 2.6.21 through 2.6.30.x, the 64-byte header is the 48-byte
1036 * header described above, followed by 16 bytes of zeroes; in Linux
1037 * 2.6.31 and later, the 64-byte header is the 64-byte header described
1040 * See linux/Documentation/usb/usbmon.txt and libpcap/pcap/usb.h for details.
1042 * With WTAP_ENCAP_USB_LINUX, packets have the 48-byte header; with
1043 * WTAP_ENCAP_USB_LINUX_MMAPPED, they have the 64-byte header. There
1044 * is no indication of whether the header has the "struct iso_rec", or
1045 * whether the last 16 bytes of a 64-byte header are all zeros or are
1046 * a "struct linux_usb_phdr_ext".
1050 * URB transfer_type values
1052 #define URB_ISOCHRONOUS 0x0
1053 #define URB_INTERRUPT 0x1
1054 #define URB_CONTROL 0x2
1055 #define URB_BULK 0x3
1058 * Information from the URB for Isochronous transfers.
1060 * This structure is 8 bytes long.
1068 * Header prepended by Linux kernel to each USB event.
1070 * (Setup flag is '-', 'D', 'Z', or 0. Data flag is '<', '>', 'Z', or 0.)
1072 * The values are in *host* byte order.
1074 struct linux_usb_phdr {
1075 guint64 id; /* urb id, to link submission and completion events */
1076 guint8 event_type; /* Submit ('S'), Completed ('C'), Error ('E') */
1077 guint8 transfer_type; /* ISO (0), Intr, Control, Bulk (3) */
1078 guint8 endpoint_number; /* Endpoint number (0-15) and transfer direction */
1079 guint8 device_address; /* 0-127 */
1081 gint8 setup_flag; /* 0, if the urb setup header is meaningful */
1082 gint8 data_flag; /* 0, if urb data is present */
1086 guint32 urb_len; /* whole len of urb this event refers to */
1087 guint32 data_len; /* amount of urb data really present in this event */
1090 * Packet-type-dependent data.
1091 * USB setup information of setup_flag is true.
1092 * Otherwise, some isochronous transfer information.
1100 * This data is provided by Linux 2.6.31 and later kernels.
1102 * For WTAP_ENCAP_USB_LINUX, it's not in the pseudo-header, so
1103 * the pseudo-header is always 48 bytes long, including the
1104 * packet-type-dependent data.
1106 * For WTAP_ENCAP_USB_LINUX_MMAPPED, the pseudo-header is always
1107 * 64 bytes long, with the packet-type-dependent data preceding
1108 * these last 16 bytes. In pre-2.6.31 kernels, it's zero padding;
1109 * in 2.6.31 and later, it's the following data.
1111 gint32 interval; /* only for Interrupt and Isochronous events */
1112 gint32 start_frame; /* for Isochronous */
1113 guint32 xfer_flags; /* copy of URB's transfer_flags */
1114 guint32 ndesc; /* actual number of isochronous descriptors */
1117 struct linux_usb_isodesc {
1125 * USB setup header as defined in USB specification
1126 * See usb_20.pdf, Chapter 9.3 'USB Device Requests' for details.
1127 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
1129 * This structure is 8 bytes long.
1131 struct usb_device_setup_hdr {
1132 gint8 bmRequestType;
1141 * Offset of the *end* of a field within a particular structure.
1143 #define END_OFFSETOF(basep, fieldp) \
1144 (((char *)(void *)(fieldp)) - ((char *)(void *)(basep)) + \
1148 * Is that offset within the bounds of the packet?
1150 #define WITHIN_PACKET(basep, fieldp) \
1151 (packet_size >= END_OFFSETOF((basep), (fieldp)))
1153 #define CHECK_AND_SWAP16(fieldp) \
1155 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1157 PBSWAP16((guint8 *)fieldp); \
1160 #define CHECK_AND_SWAP32(fieldp) \
1162 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1164 PBSWAP32((guint8 *)fieldp); \
1167 #define CHECK_AND_SWAP64(fieldp) \
1169 if (!WITHIN_PACKET(usb_phdr, fieldp)) \
1171 PBSWAP64((guint8 *)fieldp); \
1175 pcap_byteswap_linux_usb_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd,
1176 gboolean header_len_64_bytes)
1179 struct linux_usb_phdr *usb_phdr;
1180 struct linux_usb_isodesc *pisodesc;
1181 gint32 iso_numdesc, i;
1184 * Minimum of captured and actual length (just in case the
1185 * actual length < the captured length, which Should Never
1188 packet_size = phdr->caplen;
1189 if (packet_size > phdr->len)
1190 packet_size = phdr->len;
1193 * Greasy hack, but we never directly dereference any of
1194 * the fields in *usb_phdr, we just get offsets of and
1195 * addresses of its members and byte-swap it with a
1196 * byte-at-a-time macro, so it's alignment-safe.
1198 usb_phdr = (struct linux_usb_phdr *)(void *)pd;
1200 CHECK_AND_SWAP64(&usb_phdr->id);
1201 CHECK_AND_SWAP16(&usb_phdr->bus_id);
1202 CHECK_AND_SWAP64(&usb_phdr->ts_sec);
1203 CHECK_AND_SWAP32(&usb_phdr->ts_usec);
1204 CHECK_AND_SWAP32(&usb_phdr->status);
1205 CHECK_AND_SWAP32(&usb_phdr->urb_len);
1206 CHECK_AND_SWAP32(&usb_phdr->data_len);
1208 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1209 CHECK_AND_SWAP32(&usb_phdr->s.iso.error_count);
1210 CHECK_AND_SWAP32(&usb_phdr->s.iso.numdesc);
1213 if (header_len_64_bytes) {
1215 * This is either the "version 1" header, with
1216 * 16 bytes of additional fields at the end, or
1217 * a "version 0" header from a memory-mapped
1218 * capture, with 16 bytes of zeroed-out padding
1219 * at the end. Byte swap them as if this were
1220 * a "version 1" header.
1222 * Yes, the first argument to END_OFFSETOF() should
1223 * be usb_phdr, not usb_phdr_ext; we want the offset of
1224 * the additional fields from the beginning of
1227 CHECK_AND_SWAP32(&usb_phdr->interval);
1228 CHECK_AND_SWAP32(&usb_phdr->start_frame);
1229 CHECK_AND_SWAP32(&usb_phdr->xfer_flags);
1230 CHECK_AND_SWAP32(&usb_phdr->ndesc);
1233 if (usb_phdr->transfer_type == URB_ISOCHRONOUS) {
1234 /* swap the values in struct linux_usb_isodesc */
1237 * See previous "Greasy hack" comment.
1239 if (header_len_64_bytes) {
1240 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 64);
1242 pisodesc = (struct linux_usb_isodesc*)(void *)(pd + 48);
1244 iso_numdesc = usb_phdr->s.iso.numdesc;
1245 for (i = 0; i < iso_numdesc; i++) {
1246 CHECK_AND_SWAP32(&pisodesc->iso_status);
1247 CHECK_AND_SWAP32(&pisodesc->iso_off);
1248 CHECK_AND_SWAP32(&pisodesc->iso_len);
1249 CHECK_AND_SWAP32(&pisodesc->_pad);
1257 guint8 nflog_family; /* address family */
1258 guint8 nflog_version; /* version */
1259 guint16 nflog_rid; /* resource ID */
1263 guint16 tlv_length; /* tlv length */
1264 guint16 tlv_type; /* tlv type */
1265 /* value follows this */
1269 pcap_byteswap_nflog_pseudoheader(struct wtap_pkthdr *phdr, guint8 *pd)
1273 struct nflog_hdr *nfhdr;
1274 struct nflog_tlv *tlv;
1278 * Minimum of captured and actual length (just in case the
1279 * actual length < the captured length, which Should Never
1282 packet_size = phdr->caplen;
1283 if (packet_size > phdr->len)
1284 packet_size = phdr->len;
1286 if (packet_size < sizeof(struct nflog_hdr)) {
1287 /* Not enough data to have any TLVs. */
1292 nfhdr = (struct nflog_hdr *)pd;
1293 if (nfhdr->nflog_version != 0) {
1294 /* Unknown NFLOG version */
1298 packet_size -= (guint)sizeof(struct nflog_hdr);
1299 p += sizeof(struct nflog_hdr);
1301 while (packet_size >= sizeof(struct nflog_tlv)) {
1302 tlv = (struct nflog_tlv *) p;
1304 /* Swap the type and length. */
1305 PBSWAP16((guint8 *)&tlv->tlv_type);
1306 PBSWAP16((guint8 *)&tlv->tlv_length);
1308 /* Get the length of the TLV. */
1309 size = tlv->tlv_length;
1311 size += 4 - size % 4;
1313 /* Is the TLV's length less than the minimum? */
1314 if (size < sizeof(struct nflog_tlv)) {
1315 /* Yes. Give up now. */
1319 /* Do we have enough data for the full TLV? */
1320 if (packet_size < size) {
1325 /* Skip over the TLV. */
1326 packet_size -= size;
1332 * Pseudo-header at the beginning of DLT_BLUETOOTH_HCI_H4_WITH_PHDR frames.
1333 * Values in network byte order.
1335 struct libpcap_bt_phdr {
1336 guint32 direction; /* Bit 0 hold the frame direction. */
1339 #define LIBPCAP_BT_PHDR_SENT 0
1340 #define LIBPCAP_BT_PHDR_RECV 1
1343 pcap_read_bt_pseudoheader(FILE_T fh,
1344 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1346 struct libpcap_bt_phdr phdr;
1348 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_phdr),
1351 pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
1356 * Pseudo-header at the beginning of DLT_BLUETOOTH_LINUX_MONITOR frames.
1357 * Values in network byte order.
1359 struct libpcap_bt_monitor_phdr {
1365 pcap_read_bt_monitor_pseudoheader(FILE_T fh,
1366 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1368 struct libpcap_bt_monitor_phdr phdr;
1370 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_monitor_phdr),
1374 pseudo_header->btmon.adapter_id = g_ntohs(phdr.adapter_id);
1375 pseudo_header->btmon.opcode = g_ntohs(phdr.opcode);
1380 pcap_read_llcp_pseudoheader(FILE_T fh,
1381 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1383 guint8 phdr[LLCP_HEADER_LEN];
1385 if (!wtap_read_bytes(fh, phdr, LLCP_HEADER_LEN, err, err_info))
1387 pseudo_header->llcp.adapter = phdr[LLCP_ADAPTER_OFFSET];
1388 pseudo_header->llcp.flags = phdr[LLCP_FLAGS_OFFSET];
1393 * Pseudo-header at the beginning of DLT_PPP_WITH_DIR frames.
1395 struct libpcap_ppp_phdr {
1399 #define LIBPCAP_PPP_PHDR_RECV 0
1400 #define LIBPCAP_PPP_PHDR_SENT 1
1403 pcap_read_ppp_pseudoheader(FILE_T fh,
1404 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1406 struct libpcap_ppp_phdr phdr;
1408 if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_ppp_phdr),
1411 pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
1416 pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr,
1417 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1419 guint8 erf_hdr[sizeof(struct erf_phdr)];
1421 if (!wtap_read_bytes(fh, erf_hdr, sizeof(struct erf_phdr), err, err_info))
1423 pseudo_header->erf.phdr.ts = pletoh64(&erf_hdr[0]); /* timestamp */
1424 pseudo_header->erf.phdr.type = erf_hdr[8];
1425 pseudo_header->erf.phdr.flags = erf_hdr[9];
1426 pseudo_header->erf.phdr.rlen = pntoh16(&erf_hdr[10]);
1427 pseudo_header->erf.phdr.lctr = pntoh16(&erf_hdr[12]);
1428 pseudo_header->erf.phdr.wlen = pntoh16(&erf_hdr[14]);
1430 /* The high 32 bits of the timestamp contain the integer number of seconds
1431 * while the lower 32 bits contain the binary fraction of the second.
1432 * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */
1434 guint64 ts = pseudo_header->erf.phdr.ts;
1435 whdr->ts.secs = (guint32) (ts >> 32);
1436 ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000);
1437 ts += (ts & 0x80000000) << 1; /* rounding */
1438 whdr->ts.nsecs = ((guint32) (ts >> 32));
1439 if ( whdr->ts.nsecs >= 1000000000) {
1440 whdr->ts.nsecs -= 1000000000;
1448 * If the type of record given in the pseudo header indicate the presence of an extension
1449 * header then, read all the extension headers
1452 pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1453 int *err, gchar **err_info, guint * psize)
1455 guint8 erf_exhdr[8];
1456 guint64 erf_exhdr_sw;
1457 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1460 if (pseudo_header->erf.phdr.type & 0x80){
1462 if (!wtap_read_bytes(fh, erf_exhdr, 8, err, err_info))
1464 type = erf_exhdr[0];
1465 erf_exhdr_sw = pntoh64(erf_exhdr);
1467 memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw));
1470 } while (type & 0x80);
1476 * If the type of record given in the pseudo header indicate the precense of a subheader
1477 * then, read this optional subheader
1480 pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1481 int *err, gchar **err_info, guint * psize)
1483 guint8 erf_subhdr[sizeof(union erf_subhdr)];
1486 switch(pseudo_header->erf.phdr.type & 0x7F) {
1487 case ERF_TYPE_MC_HDLC:
1488 case ERF_TYPE_MC_RAW:
1489 case ERF_TYPE_MC_ATM:
1490 case ERF_TYPE_MC_RAW_CHANNEL:
1491 case ERF_TYPE_MC_AAL5:
1492 case ERF_TYPE_MC_AAL2:
1493 case ERF_TYPE_COLOR_MC_HDLC_POS:
1494 /* Extract the Multi Channel header to include it in the pseudo header part */
1495 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_mc_header_t), err, err_info))
1497 pseudo_header->erf.subhdr.mc_hdr = pntoh32(&erf_subhdr[0]);
1498 *psize = sizeof(erf_mc_header_t);
1501 /* Extract the AAL2 header to include it in the pseudo header part */
1502 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_aal2_header_t), err, err_info))
1504 pseudo_header->erf.subhdr.aal2_hdr = pntoh32(&erf_subhdr[0]);
1505 *psize = sizeof(erf_aal2_header_t);
1508 case ERF_TYPE_COLOR_ETH:
1509 case ERF_TYPE_DSM_COLOR_ETH:
1510 case ERF_TYPE_COLOR_HASH_ETH:
1511 /* Extract the Ethernet additional header to include it in the pseudo header part */
1512 if (!wtap_read_bytes(fh, erf_subhdr, sizeof(erf_eth_header_t), err, err_info))
1514 memcpy(&pseudo_header->erf.subhdr.eth_hdr, erf_subhdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
1515 *psize = sizeof(erf_eth_header_t);
1518 /* No optional pseudo header for this ERF type */
1525 pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1527 struct i2c_file_hdr i2c_hdr;
1529 if (!wtap_read_bytes(fh, &i2c_hdr, sizeof (i2c_hdr), err, err_info))
1532 pseudo_header->i2c.is_event = i2c_hdr.bus & 0x80 ? 1 : 0;
1533 pseudo_header->i2c.bus = i2c_hdr.bus & 0x7f;
1534 pseudo_header->i2c.flags = pntoh32(&i2c_hdr.flags);
1540 pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
1541 guint packet_size, gboolean check_packet_size,
1542 struct wtap_pkthdr *phdr, int *err, gchar **err_info)
1547 switch (wtap_encap) {
1549 case WTAP_ENCAP_ATM_PDUS:
1550 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1554 if (check_packet_size && packet_size < NOKIAATM_LEN) {
1556 * Uh-oh, the packet isn't big enough to even
1557 * have a pseudo-header.
1559 *err = WTAP_ERR_BAD_FILE;
1560 *err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1564 if (!pcap_read_nokiaatm_pseudoheader(fh,
1565 &phdr->pseudo_header, err, err_info))
1566 return -1; /* Read error */
1568 phdr_len = NOKIAATM_LEN;
1573 if (check_packet_size && packet_size < SUNATM_LEN) {
1575 * Uh-oh, the packet isn't big enough to even
1576 * have a pseudo-header.
1578 *err = WTAP_ERR_BAD_FILE;
1579 *err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1583 if (!pcap_read_sunatm_pseudoheader(fh,
1584 &phdr->pseudo_header, err, err_info))
1585 return -1; /* Read error */
1587 phdr_len = SUNATM_LEN;
1591 case WTAP_ENCAP_ETHERNET:
1592 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1594 * Nokia IPSO. Psuedo header has already been read, but it's not considered
1595 * part of the packet size, so reread it to store the data for later (when saving)
1597 if (!pcap_read_nokia_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1598 return -1; /* Read error */
1602 * We don't know whether there's an FCS in this frame or not.
1604 phdr->pseudo_header.eth.fcs_len = -1;
1607 case WTAP_ENCAP_IEEE_802_11:
1608 case WTAP_ENCAP_IEEE_802_11_PRISM:
1609 case WTAP_ENCAP_IEEE_802_11_RADIOTAP:
1610 case WTAP_ENCAP_IEEE_802_11_AVS:
1612 * We don't know whether there's an FCS in this frame or not,
1613 * at least in pcap files. For radiotap, that's indicated in
1614 * the radiotap header.
1616 * XXX - in pcap-ng, there *could* be a packet option
1617 * indicating the FCS length.
1619 memset(&phdr->pseudo_header.ieee_802_11, 0, sizeof(phdr->pseudo_header.ieee_802_11));
1620 phdr->pseudo_header.ieee_802_11.fcs_len = -1;
1621 phdr->pseudo_header.ieee_802_11.decrypted = FALSE;
1622 phdr->pseudo_header.ieee_802_11.datapad = FALSE;
1625 case WTAP_ENCAP_IRDA:
1626 if (check_packet_size && packet_size < IRDA_SLL_LEN) {
1628 * Uh-oh, the packet isn't big enough to even
1629 * have a pseudo-header.
1631 *err = WTAP_ERR_BAD_FILE;
1632 *err_info = g_strdup_printf("pcap: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
1636 if (!pcap_read_irda_pseudoheader(fh, &phdr->pseudo_header,
1638 return -1; /* Read error */
1640 phdr_len = IRDA_SLL_LEN;
1643 case WTAP_ENCAP_MTP2_WITH_PHDR:
1644 if (check_packet_size && packet_size < MTP2_HDR_LEN) {
1646 * Uh-oh, the packet isn't big enough to even
1647 * have a pseudo-header.
1649 *err = WTAP_ERR_BAD_FILE;
1650 *err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
1654 if (!pcap_read_mtp2_pseudoheader(fh, &phdr->pseudo_header,
1656 return -1; /* Read error */
1658 phdr_len = MTP2_HDR_LEN;
1661 case WTAP_ENCAP_LINUX_LAPD:
1662 if (check_packet_size && packet_size < LAPD_SLL_LEN) {
1664 * Uh-oh, the packet isn't big enough to even
1665 * have a pseudo-header.
1667 *err = WTAP_ERR_BAD_FILE;
1668 *err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
1672 if (!pcap_read_lapd_pseudoheader(fh, &phdr->pseudo_header,
1674 return -1; /* Read error */
1676 phdr_len = LAPD_SLL_LEN;
1679 case WTAP_ENCAP_SITA:
1680 if (check_packet_size && packet_size < SITA_HDR_LEN) {
1682 * Uh-oh, the packet isn't big enough to even
1683 * have a pseudo-header.
1685 *err = WTAP_ERR_BAD_FILE;
1686 *err_info = g_strdup_printf("pcap: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
1690 if (!pcap_read_sita_pseudoheader(fh, &phdr->pseudo_header,
1692 return -1; /* Read error */
1694 phdr_len = SITA_HDR_LEN;
1697 case WTAP_ENCAP_BLUETOOTH_H4:
1698 /* We don't have pseudoheader, so just pretend we received everything. */
1699 phdr->pseudo_header.p2p.sent = FALSE;
1702 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1703 if (check_packet_size &&
1704 packet_size < sizeof (struct libpcap_bt_phdr)) {
1706 * Uh-oh, the packet isn't big enough to even
1707 * have a pseudo-header.
1709 *err = WTAP_ERR_BAD_FILE;
1710 *err_info = g_strdup_printf("pcap: libpcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
1714 if (!pcap_read_bt_pseudoheader(fh,
1715 &phdr->pseudo_header, err, err_info))
1716 return -1; /* Read error */
1718 phdr_len = (int)sizeof (struct libpcap_bt_phdr);
1721 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
1722 if (check_packet_size &&
1723 packet_size < sizeof (struct libpcap_bt_monitor_phdr)) {
1725 * Uh-oh, the packet isn't big enough to even
1726 * have a pseudo-header.
1728 *err = WTAP_ERR_BAD_FILE;
1729 *err_info = g_strdup_printf("pcap: libpcap bluetooth monitor file has a %u-byte packet, too small to have even a pseudo-header",
1733 if (!pcap_read_bt_monitor_pseudoheader(fh,
1734 &phdr->pseudo_header, err, err_info))
1735 return -1; /* Read error */
1737 phdr_len = (int)sizeof (struct libpcap_bt_monitor_phdr);
1740 case WTAP_ENCAP_NFC_LLCP:
1741 if (check_packet_size && packet_size < LLCP_HEADER_LEN) {
1742 *err = WTAP_ERR_BAD_FILE;
1743 *err_info = g_strdup("pcap: libpcap llcp file too short");
1746 if (!pcap_read_llcp_pseudoheader(fh, &phdr->pseudo_header, err, err_info))
1747 return -1; /* Read error */
1748 phdr_len = LLCP_HEADER_LEN;
1751 case WTAP_ENCAP_PPP_WITH_PHDR:
1752 if (check_packet_size &&
1753 packet_size < sizeof (struct libpcap_ppp_phdr)) {
1755 * Uh-oh, the packet isn't big enough to even
1756 * have a pseudo-header.
1758 *err = WTAP_ERR_BAD_FILE;
1759 *err_info = g_strdup_printf("pcap: libpcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
1763 if (!pcap_read_ppp_pseudoheader(fh,
1764 &phdr->pseudo_header, err, err_info))
1765 return -1; /* Read error */
1767 phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
1770 case WTAP_ENCAP_ERF:
1771 if (check_packet_size &&
1772 packet_size < sizeof(struct erf_phdr) ) {
1774 * Uh-oh, the packet isn't big enough to even
1775 * have a pseudo-header.
1777 *err = WTAP_ERR_BAD_FILE;
1778 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
1783 if (!pcap_read_erf_pseudoheader(fh, phdr, &phdr->pseudo_header,
1785 return -1; /* Read error */
1787 phdr_len = (int)sizeof(struct erf_phdr);
1789 /* check the optional Extension header */
1790 if (!pcap_read_erf_exheader(fh, &phdr->pseudo_header, err, err_info,
1792 return -1; /* Read error */
1796 /* check the optional Multi Channel header */
1797 if (!pcap_read_erf_subheader(fh, &phdr->pseudo_header, err, err_info,
1799 return -1; /* Read error */
1803 if (check_packet_size &&
1804 packet_size < (guint)phdr_len) {
1806 * Uh-oh, the packet isn't big enough for the pseudo-
1809 *err = WTAP_ERR_BAD_FILE;
1810 *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)",
1811 packet_size, phdr_len);
1816 case WTAP_ENCAP_I2C:
1817 if (check_packet_size &&
1818 packet_size < sizeof (struct i2c_file_hdr)) {
1820 * Uh-oh, the packet isn't big enough to even
1821 * have a pseudo-header.
1823 *err = WTAP_ERR_BAD_FILE;
1824 *err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
1828 if (!pcap_read_i2c_pseudoheader(fh, &phdr->pseudo_header,
1830 return -1; /* Read error */
1833 * Don't count the pseudo-header as part of the packet.
1835 phdr_len = (int)sizeof (struct i2c_file_hdr);
1843 pcap_read_post_process(int file_type, int wtap_encap,
1844 struct wtap_pkthdr *phdr, guint8 *pd, gboolean bytes_swapped, int fcs_len)
1846 switch (wtap_encap) {
1848 case WTAP_ENCAP_ATM_PDUS:
1849 if (file_type == WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA) {
1853 * Guess the traffic type based on the packet
1856 atm_guess_traffic_type(phdr, pd);
1861 * If this is ATM LANE traffic, try to guess what
1862 * type of LANE traffic it is based on the packet
1865 if (phdr->pseudo_header.atm.type == TRAF_LANE)
1866 atm_guess_lane_type(phdr, pd);
1870 case WTAP_ENCAP_ETHERNET:
1871 phdr->pseudo_header.eth.fcs_len = fcs_len;
1874 case WTAP_ENCAP_USB_LINUX:
1876 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, FALSE);
1879 case WTAP_ENCAP_USB_LINUX_MMAPPED:
1881 pcap_byteswap_linux_usb_pseudoheader(phdr, pd, TRUE);
1884 case WTAP_ENCAP_NETANALYZER:
1886 * Not strictly necessary, as the netANALYZER
1887 * dissector calls the "Ethernet with FCS"
1888 * dissector, but we might as well set it.
1890 phdr->pseudo_header.eth.fcs_len = 4;
1893 case WTAP_ENCAP_NFLOG:
1895 pcap_byteswap_nflog_pseudoheader(phdr, pd);
1897 case WTAP_ENCAP_ERF:
1899 * Update packet size to account for ERF padding and snapping.
1900 * Captured length is minimum of wlen and previously calculated
1901 * caplen (which would have included padding but not phdr).
1903 phdr->len = phdr->pseudo_header.erf.phdr.wlen;
1904 phdr->caplen = MIN(phdr->len, phdr->caplen);
1913 pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
1919 case WTAP_ENCAP_ATM_PDUS:
1920 hdrsize = SUNATM_LEN;
1923 case WTAP_ENCAP_IRDA:
1924 hdrsize = IRDA_SLL_LEN;
1927 case WTAP_ENCAP_MTP2_WITH_PHDR:
1928 hdrsize = MTP2_HDR_LEN;
1931 case WTAP_ENCAP_LINUX_LAPD:
1932 hdrsize = LAPD_SLL_LEN;
1935 case WTAP_ENCAP_SITA:
1936 hdrsize = SITA_HDR_LEN;
1939 case WTAP_ENCAP_ERF:
1940 hdrsize = (int)sizeof (struct erf_phdr);
1941 switch (pseudo_header->erf.phdr.type & 0x7F) {
1943 case ERF_TYPE_MC_HDLC:
1944 case ERF_TYPE_MC_RAW:
1945 case ERF_TYPE_MC_ATM:
1946 case ERF_TYPE_MC_RAW_CHANNEL:
1947 case ERF_TYPE_MC_AAL5:
1948 case ERF_TYPE_MC_AAL2:
1949 case ERF_TYPE_COLOR_MC_HDLC_POS:
1950 hdrsize += (int)sizeof(struct erf_mc_hdr);
1953 hdrsize += (int)sizeof(struct erf_aal2_hdr);
1957 case ERF_TYPE_COLOR_ETH:
1958 case ERF_TYPE_DSM_COLOR_ETH:
1959 case ERF_TYPE_COLOR_HASH_ETH:
1960 hdrsize += (int)sizeof(struct erf_eth_hdr);
1968 * Add in the lengths of the extension headers.
1970 if (pseudo_header->erf.phdr.type & 0x80) {
1971 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1972 guint8 erf_exhdr[8];
1976 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
1977 type = erf_exhdr[0];
1980 } while (type & 0x80 && i < max);
1984 case WTAP_ENCAP_I2C:
1985 hdrsize = (int)sizeof (struct i2c_file_hdr);
1988 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1989 hdrsize = (int)sizeof (struct libpcap_bt_phdr);
1992 case WTAP_ENCAP_PPP_WITH_PHDR:
1993 hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
1996 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
1997 hdrsize = (int)sizeof (struct libpcap_bt_monitor_phdr);
2009 pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header,
2012 guint8 atm_hdr[SUNATM_LEN];
2013 guint8 irda_hdr[IRDA_SLL_LEN];
2014 guint8 lapd_hdr[LAPD_SLL_LEN];
2015 guint8 mtp2_hdr[MTP2_HDR_LEN];
2016 guint8 sita_hdr[SITA_HDR_LEN];
2017 guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
2018 guint8 erf_subhdr[sizeof(union erf_subhdr)];
2019 struct i2c_file_hdr i2c_hdr;
2020 struct libpcap_bt_phdr bt_hdr;
2021 struct libpcap_bt_monitor_phdr bt_monitor_hdr;
2022 struct libpcap_ppp_phdr ppp_hdr;
2024 size_t subhdr_size = 0;
2028 case WTAP_ENCAP_ATM_PDUS:
2030 * Write the ATM header.
2032 atm_hdr[SUNATM_FLAGS] =
2033 (pseudo_header->atm.channel == 0) ? 0x80 : 0x00;
2034 switch (pseudo_header->atm.aal) {
2036 case AAL_SIGNALLING:
2038 atm_hdr[SUNATM_FLAGS] |= 0x06;
2042 switch (pseudo_header->atm.type) {
2046 atm_hdr[SUNATM_FLAGS] |= 0x01;
2050 /* RFC 1483 LLC multiplexed traffic */
2051 atm_hdr[SUNATM_FLAGS] |= 0x02;
2056 atm_hdr[SUNATM_FLAGS] |= 0x05;
2061 atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi;
2062 phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci);
2063 if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err))
2065 wdh->bytes_dumped += sizeof(atm_hdr);
2068 case WTAP_ENCAP_IRDA:
2070 * Write the IrDA header.
2072 memset(irda_hdr, 0, sizeof(irda_hdr));
2073 phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET],
2074 pseudo_header->irda.pkttype);
2075 phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017);
2076 if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err))
2078 wdh->bytes_dumped += sizeof(irda_hdr);
2081 case WTAP_ENCAP_MTP2_WITH_PHDR:
2083 * Write the MTP2 header.
2085 memset(&mtp2_hdr, 0, sizeof(mtp2_hdr));
2086 mtp2_hdr[MTP2_SENT_OFFSET] = pseudo_header->mtp2.sent;
2087 mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET] = pseudo_header->mtp2.annex_a_used;
2088 phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET],
2089 pseudo_header->mtp2.link_number);
2090 if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err))
2092 wdh->bytes_dumped += sizeof(mtp2_hdr);
2095 case WTAP_ENCAP_LINUX_LAPD:
2097 * Write the LAPD header.
2099 memset(&lapd_hdr, 0, sizeof(lapd_hdr));
2100 phtons(&lapd_hdr[LAPD_SLL_PKTTYPE_OFFSET],
2101 pseudo_header->lapd.pkttype);
2102 phtons(&lapd_hdr[LAPD_SLL_PROTOCOL_OFFSET], ETH_P_LAPD);
2103 lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] =
2104 pseudo_header->lapd.we_network?0x01:0x00;
2105 if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err))
2107 wdh->bytes_dumped += sizeof(lapd_hdr);
2110 case WTAP_ENCAP_SITA:
2112 * Write the SITA header.
2114 memset(&sita_hdr, 0, sizeof(sita_hdr));
2115 sita_hdr[SITA_FLAGS_OFFSET] = pseudo_header->sita.sita_flags;
2116 sita_hdr[SITA_SIGNALS_OFFSET] = pseudo_header->sita.sita_signals;
2117 sita_hdr[SITA_ERRORS1_OFFSET] = pseudo_header->sita.sita_errors1;
2118 sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.sita_errors2;
2119 sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.sita_proto;
2120 if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err))
2122 wdh->bytes_dumped += sizeof(sita_hdr);
2125 case WTAP_ENCAP_ERF:
2127 * Write the ERF header.
2129 memset(&erf_hdr, 0, sizeof(erf_hdr));
2130 phtolell(&erf_hdr[0], pseudo_header->erf.phdr.ts);
2131 erf_hdr[8] = pseudo_header->erf.phdr.type;
2132 erf_hdr[9] = pseudo_header->erf.phdr.flags;
2135 * Recalculate rlen as padding (and maybe extension headers)
2136 * have been stripped from caplen.
2138 * XXX: Since we don't have phdr->caplen here, assume caplen was
2139 * calculated correctly and recalculate from wlen.
2141 phtons(&erf_hdr[10],
2142 MIN(pseudo_header->erf.phdr.rlen, pseudo_header->erf.phdr.wlen + pcap_get_phdr_size(WTAP_ENCAP_ERF, pseudo_header)));
2144 phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr);
2145 phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen);
2146 size = sizeof(struct erf_phdr);
2148 switch(pseudo_header->erf.phdr.type & 0x7F) {
2149 case ERF_TYPE_MC_HDLC:
2150 case ERF_TYPE_MC_RAW:
2151 case ERF_TYPE_MC_ATM:
2152 case ERF_TYPE_MC_RAW_CHANNEL:
2153 case ERF_TYPE_MC_AAL5:
2154 case ERF_TYPE_MC_AAL2:
2155 case ERF_TYPE_COLOR_MC_HDLC_POS:
2156 phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.mc_hdr);
2157 subhdr_size += (int)sizeof(struct erf_mc_hdr);
2160 phtonl(&erf_subhdr[0], pseudo_header->erf.subhdr.aal2_hdr);
2161 subhdr_size += (int)sizeof(struct erf_aal2_hdr);
2164 case ERF_TYPE_COLOR_ETH:
2165 case ERF_TYPE_DSM_COLOR_ETH:
2166 case ERF_TYPE_COLOR_HASH_ETH:
2167 memcpy(&erf_subhdr[0], &pseudo_header->erf.subhdr.eth_hdr, sizeof pseudo_header->erf.subhdr.eth_hdr);
2168 subhdr_size += (int)sizeof(struct erf_eth_hdr);
2173 if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
2175 wdh->bytes_dumped += size;
2178 * Now write out the extension headers.
2180 if (pseudo_header->erf.phdr.type & 0x80) {
2181 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
2182 guint8 erf_exhdr[8];
2186 phtonll(erf_exhdr, pseudo_header->erf.ehdr_list[i].ehdr);
2187 type = erf_exhdr[0];
2188 /* Clear more extension headers bit if > 8 */
2190 erf_exhdr[0] = erf_exhdr[0] & 0x7F;
2192 if (!wtap_dump_file_write(wdh, erf_exhdr, 8, err))
2194 wdh->bytes_dumped += 8;
2196 } while (type & 0x80 && i < max);
2200 * Now write out the subheader.
2202 if(!wtap_dump_file_write(wdh, erf_subhdr, subhdr_size, err))
2204 wdh->bytes_dumped += subhdr_size;
2207 case WTAP_ENCAP_I2C:
2209 * Write the I2C header.
2211 memset(&i2c_hdr, 0, sizeof(i2c_hdr));
2212 i2c_hdr.bus = pseudo_header->i2c.bus |
2213 (pseudo_header->i2c.is_event ? 0x80 : 0x00);
2214 phtonl((guint8 *)&i2c_hdr.flags, pseudo_header->i2c.flags);
2215 if (!wtap_dump_file_write(wdh, &i2c_hdr, sizeof(i2c_hdr), err))
2217 wdh->bytes_dumped += sizeof(i2c_hdr);
2220 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
2221 bt_hdr.direction = GUINT32_TO_BE(pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV);
2222 if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err))
2224 wdh->bytes_dumped += sizeof bt_hdr;
2227 case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
2228 bt_monitor_hdr.adapter_id = GUINT16_TO_BE(pseudo_header->btmon.adapter_id);
2229 bt_monitor_hdr.opcode = GUINT16_TO_BE(pseudo_header->btmon.opcode);
2231 if (!wtap_dump_file_write(wdh, &bt_monitor_hdr, sizeof bt_monitor_hdr, err))
2233 wdh->bytes_dumped += sizeof bt_monitor_hdr;
2236 case WTAP_ENCAP_PPP_WITH_PHDR:
2237 ppp_hdr.direction = (pseudo_header->p2p.sent ? LIBPCAP_PPP_PHDR_SENT : LIBPCAP_PPP_PHDR_RECV);
2238 if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err))
2240 wdh->bytes_dumped += sizeof ppp_hdr;
2247 * Editor modelines - http://www.wireshark.org/tools/modelines.html
2252 * indent-tabs-mode: t
2255 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
2256 * :indentSize=8:tabSize=8:noTabs=false: