2 * Code common to libpcap and pcap-NG file formats
7 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
9 * File format support for pcap-ng file format
10 * Copyright (c) 2007 by Ulf Lamping <ulf.lamping@web.de>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #include "file_wrappers.h"
37 #include "pcap-encap.h"
38 #include "pcap-common.h"
41 * Map link-layer types (LINKTYPE_ values) to Wiretap encapsulations.
44 * Either LBL NRG wasn't an adequate central registry (e.g., because of
45 * the slow rate of releases from them), or nobody bothered using them
46 * as a central registry, as many different groups have patched libpcap
47 * (and BPF, on the BSDs) to add new encapsulation types, and have ended
48 * up using the same DLT_ values for different encapsulation types.
50 * For those numerical encapsulation type values that everybody uses for
51 * the same encapsulation type (which inclues those that some platforms
52 * specify different DLT_ names for but don't appear to use), we map
53 * those values to the appropriate Wiretap values.
55 * For those numerical encapsulation type values that different libpcap
56 * variants use for different encapsulation types, we check what
57 * <pcap.h> defined to determine how to interpret them, so that we
58 * interpret them the way the libpcap with which we're building
59 * Wireshark/Wiretap interprets them (which, if it doesn't support
60 * them at all, means we don't support them either - any capture files
61 * using them are foreign, and we don't hazard a guess as to which
62 * platform they came from; we could, I guess, choose the most likely
65 * Note: if you need a new encapsulation type for libpcap files, do
66 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
67 * add a new encapsulation type by changing an existing entry;
68 * leave the existing entries alone.
70 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking for
71 * a new DLT_ value, and specifying the purpose of the new value. When
72 * you get the new DLT_ value, use that numerical value in the "dlt_value"
73 * field of "pcap_to_wtap_map[]".
79 } pcap_to_wtap_map[] = {
81 * These are the values that are almost certainly the same
82 * in all libpcaps (I've yet to find one where the values
83 * in question are used for some purpose other than the
84 * one below, but...), and that Wiretap and Wireshark
87 { 0, WTAP_ENCAP_NULL }, /* null encapsulation */
88 { 1, WTAP_ENCAP_ETHERNET },
89 { 6, WTAP_ENCAP_TOKEN_RING }, /* IEEE 802 Networks - assume token ring */
90 { 7, WTAP_ENCAP_ARCNET },
91 { 8, WTAP_ENCAP_SLIP },
92 { 9, WTAP_ENCAP_PPP },
93 #ifdef BIT_SWAPPED_MAC_ADDRS
94 { 10, WTAP_ENCAP_FDDI_BITSWAPPED },
96 { 10, WTAP_ENCAP_FDDI },
99 { 32, WTAP_ENCAP_REDBACK },
102 * 50 is DLT_PPP_SERIAL in NetBSD; it appears that DLT_PPP
103 * on BSD (at least according to standard tcpdump) has, as
104 * the first octet, an indication of whether the packet was
105 * transmitted or received (rather than having the standard
106 * PPP address value of 0xff), but that DLT_PPP_SERIAL puts
107 * a real live PPP header there, or perhaps a Cisco PPP header
108 * as per section 4.3.1 of RFC 1547 (implementations of this
109 * exist in various BSDs in "sys/net/if_spppsubr.c", and
110 * I think also exist either in standard Linux or in
111 * various Linux patches; the implementations show how to handle
112 * Cisco keepalive packets).
114 * However, I don't see any obvious place in FreeBSD "if_ppp.c"
115 * where anything other than the standard PPP header would be
116 * passed up. I see some stuff that sets the first octet
117 * to 0 for incoming and 1 for outgoing packets before applying
118 * a BPF filter to see whether to drop packets whose protocol
119 * field has the 0x8000 bit set, i.e. network control protocols -
120 * those are handed up to userland - but that code puts the
121 * address field back before passing the packet up.
123 * I also don't see anything immediately obvious that munges
124 * the address field for sync PPP, either.
126 * Wireshark currently assumes that if the first octet of a
127 * PPP frame is 0xFF, it's the address field and is followed
128 * by a control field and a 2-byte protocol, otherwise the
129 * address and control fields are absent and the frame begins
130 * with a protocol field. If we ever see a BSD/OS PPP
131 * capture, we'll have to handle it differently, and we may
132 * have to handle standard BSD captures differently if, in fact,
133 * they don't have 0xff 0x03 as the first two bytes - but, as per
134 * the two paragraphs preceding this, it's not clear that
135 * the address field *is* munged into an incoming/outgoing
136 * field when the packet is handed to the BPF device.
138 * For now, we just map DLT_PPP_SERIAL to WTAP_ENCAP_PPP, as
139 * we treat WTAP_ENCAP_PPP packets as if those beginning with
140 * 0xff have the standard RFC 1662 "PPP in HDLC-like Framing"
141 * 0xff 0x03 address/control header, and DLT_PPP_SERIAL frames
142 * appear to contain that unless they're Cisco frames (if we
143 * ever see a capture with them, we'd need to implement the
144 * RFC 1547 stuff, and the keepalive protocol stuff).
146 * We may have to distinguish between "PPP where if it doesn't
147 * begin with 0xff there's no HDLC encapsulation and the frame
148 * begins with the protocol field" (which is how we handle
149 * WTAP_ENCAP_PPP now) and "PPP where there's either HDLC
150 * encapsulation or Cisco PPP" (which is what DLT_PPP_SERIAL
153 * XXX - NetBSD has DLT_HDLC, which appears to be used for
154 * Cisco HDLC. Ideally, they should use DLT_PPP_SERIAL
155 * only for real live HDLC-encapsulated PPP, not for Cisco
158 { 50, WTAP_ENCAP_PPP },
161 * Apparently used by the Axent Raptor firewall (now Symantec
162 * Enterprise Firewall).
163 * Thanks, Axent, for not reserving that type with tcpdump.org
164 * and not telling anybody about it.
166 { 99, WTAP_ENCAP_SYMANTEC },
169 * These are the values that libpcap 0.5 and later use in
170 * capture file headers, in an attempt to work around the
171 * confusion decried above, and that Wiretap and Wireshark
174 { 100, WTAP_ENCAP_ATM_RFC1483 },
175 { 101, WTAP_ENCAP_RAW_IP },
178 * More values used by libpcap 0.5 as DLT_ values and used by the
179 * current CVS version of libpcap in capture file headers.
180 * They are not yet handled in Wireshark.
181 * If we get a capture that contains them, we'll implement them.
183 { 102, WTAP_ENCAP_SLIP_BSDOS },
184 { 103, WTAP_ENCAP_PPP_BSDOS },
188 * These ones are handled in Wireshark, though.
190 { 104, WTAP_ENCAP_CHDLC }, /* Cisco HDLC */
191 { 105, WTAP_ENCAP_IEEE_802_11 }, /* IEEE 802.11 */
192 { 106, WTAP_ENCAP_LINUX_ATM_CLIP },
193 { 107, WTAP_ENCAP_FRELAY }, /* Frame Relay */
194 { 108, WTAP_ENCAP_NULL }, /* OpenBSD loopback */
195 { 109, WTAP_ENCAP_ENC }, /* OpenBSD IPSEC enc */
197 { 110, WTAP_ENCAP_LANE_802_3 },/* ATM LANE 802.3 */
198 { 111, WTAP_ENCAP_HIPPI }, /* NetBSD HIPPI */
200 { 112, WTAP_ENCAP_CHDLC }, /* NetBSD HDLC framing */
203 * Linux "cooked mode" captures, used by the current CVS version
206 * it could be a packet in Cisco's ERSPAN encapsulation which uses
207 * this number as well (why can't people stick to protocols when it
208 * comes to allocating/using DLT types).
210 { 113, WTAP_ENCAP_SLL }, /* Linux cooked capture */
212 { 114, WTAP_ENCAP_LOCALTALK }, /* Localtalk */
215 * The tcpdump.org version of libpcap uses 117, rather than 17,
216 * for OpenBSD packet filter logging, so as to avoid conflicting
217 * with DLT_LANE8023 in SuSE 6.3 libpcap.
219 { 117, WTAP_ENCAP_PFLOG },
221 { 118, WTAP_ENCAP_CISCO_IOS },
222 { 119, WTAP_ENCAP_PRISM_HEADER }, /* Prism monitor mode hdr */
223 { 121, WTAP_ENCAP_HHDLC }, /* HiPath HDLC */
224 { 122, WTAP_ENCAP_IP_OVER_FC }, /* RFC 2625 IP-over-FC */
225 { 123, WTAP_ENCAP_ATM_PDUS }, /* SunATM */
226 { 127, WTAP_ENCAP_IEEE_802_11_WLAN_RADIOTAP }, /* 802.11 plus radiotap WLAN header */
227 { 128, WTAP_ENCAP_TZSP }, /* Tazmen Sniffer Protocol */
228 { 129, WTAP_ENCAP_ARCNET_LINUX },
229 { 130, WTAP_ENCAP_JUNIPER_MLPPP }, /* Juniper MLPPP on ML-, LS-, AS- PICs */
230 { 131, WTAP_ENCAP_JUNIPER_MLFR }, /* Juniper MLFR (FRF.15) on ML-, LS-, AS- PICs */
231 { 133, WTAP_ENCAP_JUNIPER_GGSN},
233 * Values 132-134, 136 not listed here are reserved for use
234 * in Juniper hardware.
236 { 135, WTAP_ENCAP_JUNIPER_ATM2 }, /* various encapsulations captured on the ATM2 PIC */
237 { 137, WTAP_ENCAP_JUNIPER_ATM1 }, /* various encapsulations captured on the ATM1 PIC */
239 { 138, WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 },
240 /* Apple IP-over-IEEE 1394 */
242 { 139, WTAP_ENCAP_MTP2_WITH_PHDR },
243 { 140, WTAP_ENCAP_MTP2 },
244 { 141, WTAP_ENCAP_MTP3 },
245 { 142, WTAP_ENCAP_SCCP },
246 { 143, WTAP_ENCAP_DOCSIS },
247 { 144, WTAP_ENCAP_IRDA }, /* IrDA capture */
249 /* Reserved for private use. */
250 { 147, WTAP_ENCAP_USER0 },
251 { 148, WTAP_ENCAP_USER1 },
252 { 149, WTAP_ENCAP_USER2 },
253 { 150, WTAP_ENCAP_USER3 },
254 { 151, WTAP_ENCAP_USER4 },
255 { 152, WTAP_ENCAP_USER5 },
256 { 153, WTAP_ENCAP_USER6 },
257 { 154, WTAP_ENCAP_USER7 },
258 { 155, WTAP_ENCAP_USER8 },
259 { 156, WTAP_ENCAP_USER9 },
260 { 157, WTAP_ENCAP_USER10 },
261 { 158, WTAP_ENCAP_USER11 },
262 { 159, WTAP_ENCAP_USER12 },
263 { 160, WTAP_ENCAP_USER13 },
264 { 161, WTAP_ENCAP_USER14 },
265 { 162, WTAP_ENCAP_USER15 },
267 { 163, WTAP_ENCAP_IEEE_802_11_WLAN_AVS }, /* 802.11 plus AVS WLAN header */
270 * 164 is reserved for Juniper-private chassis-internal
271 * meta-information such as QoS profiles, etc..
274 { 165, WTAP_ENCAP_BACNET_MS_TP },
277 * 166 is reserved for a PPP variant in which the first byte
278 * of the 0xff03 header, the 0xff, is replaced by a direction
279 * byte. I don't know whether any captures look like that,
280 * but it is used for some Linux IP filtering (ipfilter?).
283 /* Ethernet PPPoE frames captured on a service PIC */
284 { 167, WTAP_ENCAP_JUNIPER_PPPOE },
287 * 168 is reserved for more Juniper private-chassis-
288 * internal meta-information.
291 { 169, WTAP_ENCAP_GPRS_LLC },
294 * 170 and 171 are reserved for ITU-T G.7041/Y.1303 Generic
298 /* Registered by Gcom, Inc. */
299 { 172, WTAP_ENCAP_GCOM_TIE1 },
300 { 173, WTAP_ENCAP_GCOM_SERIAL },
302 { 177, WTAP_ENCAP_LINUX_LAPD },
304 /* Ethernet frames prepended with meta-information */
305 { 178, WTAP_ENCAP_JUNIPER_ETHER },
306 /* PPP frames prepended with meta-information */
307 { 179, WTAP_ENCAP_JUNIPER_PPP },
308 /* Frame-Relay frames prepended with meta-information */
309 { 180, WTAP_ENCAP_JUNIPER_FRELAY },
310 /* C-HDLC frames prepended with meta-information */
311 { 181, WTAP_ENCAP_JUNIPER_CHDLC },
312 /* VOIP Frames prepended with meta-information */
313 { 183, WTAP_ENCAP_JUNIPER_VP },
314 /* raw USB packets */
315 { 186, WTAP_ENCAP_USB },
316 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
317 { 187, WTAP_ENCAP_BLUETOOTH_H4 },
318 /* IEEE 802.16 MAC Common Part Sublayer */
319 { 188, WTAP_ENCAP_IEEE802_16_MAC_CPS },
320 /* USB packets with Linux-specified header */
321 { 189, WTAP_ENCAP_USB_LINUX },
323 { 190, WTAP_ENCAP_CAN20B },
324 /* Per-Packet Information header */
325 { 192, WTAP_ENCAP_PPI },
326 /* IEEE 802.15.4 Wireless PAN */
327 { 195, WTAP_ENCAP_IEEE802_15_4 },
328 /* SITA File Encapsulation */
329 { 196, WTAP_ENCAP_SITA },
330 /* Endace Record File Encapsulation */
331 { 197, WTAP_ENCAP_ERF },
333 { 199, WTAP_ENCAP_IPMB },
334 /* Bluetooth HCI UART transport (part H:4) frames, like hcidump */
335 { 201, WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR },
336 { 204, WTAP_ENCAP_PPP_WITH_PHDR },
338 { 209, WTAP_ENCAP_I2C },
340 { 210, WTAP_ENCAP_FLEXRAY },
342 { 211, WTAP_ENCAP_MOST },
344 { 212, WTAP_ENCAP_LIN },
345 /* X2E Xoraya serial frame */
346 { 213, WTAP_ENCAP_X2E_SERIAL },
347 /* X2E Xoraya frame */
348 { 214, WTAP_ENCAP_X2E_XORAYA },
349 /* IEEE 802.15.4 Wireless PAN non-ASK PHY */
350 { 215, WTAP_ENCAP_IEEE802_15_4_NONASK_PHY },
351 /* USB packets with padded Linux-specified header */
352 { 220, WTAP_ENCAP_USB_LINUX_MMAPPED },
353 /* Fibre Channel FC-2 frame */
354 { 224, WTAP_ENCAP_FIBRE_CHANNEL_FC2 },
355 /* Fibre Channel FC-2 frame with Delimiter */
356 { 225, WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS },
358 { 226, WTAP_ENCAP_IPNET },
360 /* SocketCAN frame */
361 { 227, WTAP_ENCAP_SOCKETCAN },
366 * If you need a new encapsulation type for libpcap files, do
367 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
368 * add a new encapsulation type by changing an existing entry;
369 * leave the existing entries alone.
371 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
372 * for a new DLT_ value, and specifying the purpose of the new value.
373 * When you get the new DLT_ value, use that numerical value in
374 * the "dlt_value" field of "pcap_to_wtap_map[]".
378 * The following are entries for libpcap type values that have
379 * different meanings on different OSes.
381 * We put these *after* the entries for the platform-independent
382 * libpcap type values for those Wiretap encapsulation types, so
383 * that Wireshark chooses the platform-independent libpcap type
384 * value for those encapsulatioin types, not the platform-dependent
389 * 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
390 * seen that define anything other than DLT_ATM_RFC1483 as 11 are
391 * the BSD/OS one, which defines DLT_FR as 11, and libpcap 0.5,
392 * which define it as 100, mapping the kernel's value to 100, in
393 * an attempt to hide the different values used on different
396 * If this is a platform where DLT_FR is defined as 11, we
397 * don't handle 11 at all; otherwise, we handle it as
398 * DLT_ATM_RFC1483 (this means we'd misinterpret Frame Relay
399 * captures from BSD/OS if running on platforms other than BSD/OS,
402 * 1) we don't yet support DLT_FR
406 * 2) nothing short of a heuristic would let us interpret
409 #if defined(DLT_FR) && (DLT_FR == 11)
410 { 11, WTAP_ENCAP_FRELAY },
412 { 11, WTAP_ENCAP_ATM_RFC1483 },
416 * 12 is DLT_RAW on most platforms, but it's DLT_C_HDLC on
417 * BSD/OS, and DLT_LOOP on OpenBSD.
419 * We don't yet handle DLT_C_HDLC, but we can handle DLT_LOOP
420 * (it's just like DLT_NULL, only with the AF_ value in network
421 * rather than host byte order - Wireshark figures out the
422 * byte order from the data, so we don't care what byte order
423 * it's in), so if DLT_LOOP is defined as 12, interpret 12
424 * as WTAP_ENCAP_NULL, otherwise, unless DLT_C_HDLC is defined
425 * as 12, interpret it as WTAP_ENCAP_RAW_IP.
427 #if defined(DLT_LOOP) && (DLT_LOOP == 12)
428 { 12, WTAP_ENCAP_NULL },
429 #elif defined(DLT_C_HDLC) && (DLT_C_HDLC == 12)
431 * Put entry for Cisco HDLC here.
432 * XXX - is this just WTAP_ENCAP_CHDLC, i.e. does the frame
433 * start with a 4-byte Cisco HDLC header?
436 { 12, WTAP_ENCAP_RAW_IP },
440 * 13 is DLT_SLIP_BSDOS on FreeBSD and NetBSD, but those OSes
441 * don't actually generate it. I infer that BSD/OS translates
442 * DLT_SLIP from the kernel BPF code to DLT_SLIP_BSDOS in
443 * libpcap, as the BSD/OS link-layer header is different;
444 * however, in BSD/OS, DLT_SLIP_BSDOS is 15.
446 * From this, I infer that there's no point in handling 13
449 * 13 is DLT_ATM_RFC1483 on BSD/OS.
451 * 13 is DLT_ENC in OpenBSD, which is, I suspect, some kind
452 * of decrypted IPsec traffic.
454 * We treat 13 as WTAP_ENCAP_ENC on all systems except those
455 * that define DLT_ATM_RFC1483 as 13 - presumably only
456 * BSD/OS does so - so that, on BSD/OS systems, we still
457 * treate 13 as WTAP_ENCAP_ATM_RFC1483, but, on all other
458 * systems, we can read OpenBSD DLT_ENC captures.
460 #if defined(DLT_ATM_RFC1483) && (DLT_ATM_RFC1483 == 13)
461 { 13, WTAP_ENCAP_ATM_RFC1483 },
463 { 13, WTAP_ENCAP_ENC },
467 * 14 is DLT_PPP_BSDOS on FreeBSD and NetBSD, but those OSes
468 * don't actually generate it. I infer that BSD/OS translates
469 * DLT_PPP from the kernel BPF code to DLT_PPP_BSDOS in
470 * libpcap, as the BSD/OS link-layer header is different;
471 * however, in BSD/OS, DLT_PPP_BSDOS is 16.
473 * From this, I infer that there's no point in handling 14
476 * 14 is DLT_RAW on BSD/OS and OpenBSD.
478 { 14, WTAP_ENCAP_RAW_IP },
483 * DLT_SLIP_BSDOS on BSD/OS;
485 * DLT_HIPPI on NetBSD;
487 * DLT_LANE8023 with Alexey Kuznetzov's patches for
490 * DLT_I4L_RAWIP with the ISDN4Linux patches for libpcap
493 * but we don't currently handle any of those.
499 * DLT_PPP_BSDOS on BSD/OS;
501 * DLT_HDLC on NetBSD (Cisco HDLC);
503 * DLT_CIP with Alexey Kuznetzov's patches for
504 * Linux libpcap - this is WTAP_ENCAP_LINUX_ATM_CLIP;
506 * DLT_I4L_IP with the ISDN4Linux patches for libpcap
509 #if defined(DLT_CIP) && (DLT_CIP == 16)
510 { 16, WTAP_ENCAP_LINUX_ATM_CLIP },
512 #if defined(DLT_HDLC) && (DLT_HDLC == 16)
513 { 16, WTAP_ENCAP_CHDLC },
517 * 17 is DLT_LANE8023 in SuSE 6.3 libpcap; we don't currently
519 * It is also used as the PF (Packet Filter) logging format beginning
520 * with OpenBSD 3.0; we use 17 for PF logs unless DLT_LANE8023 is
521 * defined with the value 17.
523 #if !defined(DLT_LANE8023) || (DLT_LANE8023 != 17)
524 { 17, WTAP_ENCAP_OLD_PFLOG },
528 * 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
529 * DLT_CIP of 16 that the Alexey Kuznetzov patches for
530 * libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
531 * I've not found any libpcap that uses it for any other purpose -
532 * hopefully nobody will do so in the future.
534 { 18, WTAP_ENCAP_LINUX_ATM_CLIP },
537 * 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
538 * recent versions I've seen of the Linux ATM distribution;
539 * I've not yet found any libpcap that uses it for any other
540 * purpose - hopefully nobody will do so in the future.
542 { 19, WTAP_ENCAP_LINUX_ATM_CLIP },
547 * If you need a new encapsulation type for libpcap files, do
548 * *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
549 * add a new encapsulation type by changing an existing entry;
550 * leave the existing entries alone.
552 * Instead, send mail to tcpdump-workers@lists.tcpdump.org, asking
553 * for a new DLT_ value, and specifying the purpose of the new value.
554 * When you get the new DLT_ value, use that numerical value in
555 * the "dlt_value" field of "pcap_to_wtap_map[]".
558 #define NUM_PCAP_ENCAPS (sizeof pcap_to_wtap_map / sizeof pcap_to_wtap_map[0])
561 wtap_pcap_encap_to_wtap_encap(int encap)
565 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
566 if (pcap_to_wtap_map[i].dlt_value == encap)
567 return pcap_to_wtap_map[i].wtap_encap_value;
569 return WTAP_ENCAP_UNKNOWN;
573 wtap_wtap_encap_to_pcap_encap(int encap)
579 case WTAP_ENCAP_FDDI:
580 case WTAP_ENCAP_FDDI_BITSWAPPED:
581 case WTAP_ENCAP_NETTL_FDDI:
583 * Special-case WTAP_ENCAP_FDDI and
584 * WTAP_ENCAP_FDDI_BITSWAPPED; both of them get mapped
585 * to DLT_FDDI (even though that may mean that the bit
586 * order in the FDDI MAC addresses is wrong; so it goes
587 * - libpcap format doesn't record the byte order,
588 * so that's not fixable).
590 return 10; /* that's DLT_FDDI */
592 case WTAP_ENCAP_FRELAY_WITH_PHDR:
594 * Do the same with Frame Relay.
598 case WTAP_ENCAP_IEEE_802_11_WITH_RADIO:
600 * Map this to DLT_IEEE802_11, for now, even though
601 * that means the radio information will be lost.
602 * Once tcpdump support for the BSD radiotap header
603 * is sufficiently widespread, we should probably
604 * use that, instead - although we should probably
605 * ultimately just have WTAP_ENCAP_IEEE_802_11
606 * as the only Wiretap encapsulation for 802.11,
607 * and have the pseudo-header include a radiotap-style
608 * list of attributes. If we do that, though, we
609 * should probably bypass the regular Wiretap code
610 * when writing out packets during a capture, and just
611 * do the equivalent of a libpcap write (unfortunately,
612 * libpcap doesn't have an "open dump by file descriptor"
613 * function, so we can't just use "pcap_dump()"), so
614 * that we don't spend cycles mapping from libpcap to
615 * Wiretap and then back to libpcap. (There are other
616 * reasons to do that, e.g. to handle AIX libpcap better.)
621 for (i = 0; i < NUM_PCAP_ENCAPS; i++) {
622 if (pcap_to_wtap_map[i].wtap_encap_value == encap)
623 return pcap_to_wtap_map[i].dlt_value;
629 * Various pseudo-headers that appear at the beginning of packet data.
631 * We represent them as sets of offsets, as they might not be aligned on
632 * an appropriate structure boundary in the buffer, and as that makes them
633 * independent of the way the compiler might align fields.
637 * The link-layer header on SunATM packets.
639 #define SUNATM_FLAGS 0 /* destination and traffic type - 1 byte */
640 #define SUNATM_VPI 1 /* VPI - 1 byte */
641 #define SUNATM_VCI 2 /* VCI - 2 bytes */
642 #define SUNATM_LEN 4 /* length of the header */
645 * The link-layer header on Nokia IPSO ATM packets.
647 #define NOKIAATM_FLAGS 0 /* destination - 1 byte */
648 #define NOKIAATM_VPI 1 /* VPI - 1 byte */
649 #define NOKIAATM_VCI 2 /* VCI - 2 bytes */
650 #define NOKIAATM_LEN 4 /* length of the header */
653 * The fake link-layer header of IrDA packets as introduced by Jean Tourrilhes
656 #define IRDA_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
657 /* 12 unused bytes */
658 #define IRDA_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
659 #define IRDA_SLL_LEN 16 /* length of the header */
662 * A header containing additional MTP information.
664 #define MTP2_SENT_OFFSET 0 /* 1 byte */
665 #define MTP2_ANNEX_A_USED_OFFSET 1 /* 1 byte */
666 #define MTP2_LINK_NUMBER_OFFSET 2 /* 2 bytes */
667 #define MTP2_HDR_LEN 4 /* length of the header */
670 * A header containing additional SITA WAN information.
672 #define SITA_FLAGS_OFFSET 0 /* 1 byte */
673 #define SITA_SIGNALS_OFFSET 1 /* 1 byte */
674 #define SITA_ERRORS1_OFFSET 2 /* 1 byte */
675 #define SITA_ERRORS2_OFFSET 3 /* 1 byte */
676 #define SITA_PROTO_OFFSET 4 /* 1 byte */
677 #define SITA_HDR_LEN 5 /* length of the header */
680 * The fake link-layer header of LAPD packets.
683 #define ETH_P_LAPD 0x0030
686 #define LAPD_SLL_PKTTYPE_OFFSET 0 /* packet type - 2 bytes */
687 #define LAPD_SLL_HATYPE_OFFSET 2 /* hardware address type - 2 bytes */
688 #define LAPD_SLL_HALEN_OFFSET 4 /* hardware address length - 2 bytes */
689 #define LAPD_SLL_ADDR_OFFSET 6 /* address - 8 bytes */
690 #define LAPD_SLL_PROTOCOL_OFFSET 14 /* protocol, should be ETH_P_LAPD - 2 bytes */
691 #define LAPD_SLL_LEN 16 /* length of the header */
694 * I2C link-layer on-disk format
696 struct i2c_file_hdr {
702 pcap_read_sunatm_pseudoheader(FILE_T fh,
703 union wtap_pseudo_header *pseudo_header, int *err)
705 guint8 atm_phdr[SUNATM_LEN];
710 errno = WTAP_ERR_CANT_READ;
711 bytes_read = file_read(atm_phdr, 1, SUNATM_LEN, fh);
712 if (bytes_read != SUNATM_LEN) {
713 *err = file_error(fh);
715 *err = WTAP_ERR_SHORT_READ;
719 vpi = atm_phdr[SUNATM_VPI];
720 vci = pntohs(&atm_phdr[SUNATM_VCI]);
722 switch (atm_phdr[SUNATM_FLAGS] & 0x0F) {
724 case 0x01: /* LANE */
725 pseudo_header->atm.aal = AAL_5;
726 pseudo_header->atm.type = TRAF_LANE;
729 case 0x02: /* RFC 1483 LLC multiplexed traffic */
730 pseudo_header->atm.aal = AAL_5;
731 pseudo_header->atm.type = TRAF_LLCMX;
734 case 0x05: /* ILMI */
735 pseudo_header->atm.aal = AAL_5;
736 pseudo_header->atm.type = TRAF_ILMI;
739 case 0x06: /* Q.2931 */
740 pseudo_header->atm.aal = AAL_SIGNALLING;
741 pseudo_header->atm.type = TRAF_UNKNOWN;
744 case 0x03: /* MARS (RFC 2022) */
745 pseudo_header->atm.aal = AAL_5;
746 pseudo_header->atm.type = TRAF_UNKNOWN;
749 case 0x04: /* IFMP (Ipsilon Flow Management Protocol; see RFC 1954) */
750 pseudo_header->atm.aal = AAL_5;
751 pseudo_header->atm.type = TRAF_UNKNOWN; /* XXX - TRAF_IPSILON? */
756 * Assume it's AAL5, unless it's VPI 0 and VCI 5, in which
757 * case assume it's AAL_SIGNALLING; we know nothing more
760 * XXX - is this necessary? Or are we guaranteed that
761 * all signalling traffic has a type of 0x06?
763 * XXX - is this guaranteed to be AAL5? Or, if the type is
764 * 0x00 ("raw"), might it be non-AAL5 traffic?
766 if (vpi == 0 && vci == 5)
767 pseudo_header->atm.aal = AAL_SIGNALLING;
769 pseudo_header->atm.aal = AAL_5;
770 pseudo_header->atm.type = TRAF_UNKNOWN;
773 pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
775 pseudo_header->atm.vpi = vpi;
776 pseudo_header->atm.vci = vci;
777 pseudo_header->atm.channel = (atm_phdr[SUNATM_FLAGS] & 0x80) ? 0 : 1;
779 /* We don't have this information */
780 pseudo_header->atm.flags = 0;
781 pseudo_header->atm.cells = 0;
782 pseudo_header->atm.aal5t_u2u = 0;
783 pseudo_header->atm.aal5t_len = 0;
784 pseudo_header->atm.aal5t_chksum = 0;
790 pcap_read_nokiaatm_pseudoheader(FILE_T fh,
791 union wtap_pseudo_header *pseudo_header, int *err)
793 guint8 atm_phdr[NOKIAATM_LEN];
798 errno = WTAP_ERR_CANT_READ;
799 bytes_read = file_read(atm_phdr, 1, NOKIAATM_LEN, fh);
800 if (bytes_read != NOKIAATM_LEN) {
801 *err = file_error(fh);
803 *err = WTAP_ERR_SHORT_READ;
807 vpi = atm_phdr[NOKIAATM_VPI];
808 vci = pntohs(&atm_phdr[NOKIAATM_VCI]);
810 pseudo_header->atm.vpi = vpi;
811 pseudo_header->atm.vci = vci;
812 pseudo_header->atm.channel = (atm_phdr[NOKIAATM_FLAGS] & 0x80) ? 0 : 1;
814 /* We don't have this information */
815 pseudo_header->atm.flags = 0;
816 pseudo_header->atm.cells = 0;
817 pseudo_header->atm.aal5t_u2u = 0;
818 pseudo_header->atm.aal5t_len = 0;
819 pseudo_header->atm.aal5t_chksum = 0;
825 pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
826 int *err, gchar **err_info)
828 guint8 irda_phdr[IRDA_SLL_LEN];
831 errno = WTAP_ERR_CANT_READ;
832 bytes_read = file_read(irda_phdr, 1, IRDA_SLL_LEN, fh);
833 if (bytes_read != IRDA_SLL_LEN) {
834 *err = file_error(fh);
836 *err = WTAP_ERR_SHORT_READ;
840 if (pntohs(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
841 *err = WTAP_ERR_BAD_RECORD;
842 if (err_info != NULL)
843 *err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
847 pseudo_header->irda.pkttype = pntohs(&irda_phdr[IRDA_SLL_PKTTYPE_OFFSET]);
853 pcap_read_mtp2_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_)
855 guint8 mtp2_hdr[MTP2_HDR_LEN];
858 errno = WTAP_ERR_CANT_READ;
859 bytes_read = file_read(mtp2_hdr, 1, MTP2_HDR_LEN, fh);
860 if (bytes_read != MTP2_HDR_LEN) {
861 *err = file_error(fh);
863 *err = WTAP_ERR_SHORT_READ;
867 pseudo_header->mtp2.sent = mtp2_hdr[MTP2_SENT_OFFSET];
868 pseudo_header->mtp2.annex_a_used = mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET];
869 pseudo_header->mtp2.link_number = pntohs(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET]);
875 pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
876 int *err, gchar **err_info)
878 guint8 lapd_phdr[LAPD_SLL_LEN];
881 errno = WTAP_ERR_CANT_READ;
882 bytes_read = file_read(lapd_phdr, 1, LAPD_SLL_LEN, fh);
883 if (bytes_read != LAPD_SLL_LEN) {
884 *err = file_error(fh);
886 *err = WTAP_ERR_SHORT_READ;
890 if (pntohs(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
891 *err = WTAP_ERR_BAD_RECORD;
892 if (err_info != NULL)
893 *err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
897 pseudo_header->lapd.pkttype = pntohs(&lapd_phdr[LAPD_SLL_PKTTYPE_OFFSET]);
898 pseudo_header->lapd.we_network = !!lapd_phdr[LAPD_SLL_ADDR_OFFSET+0];
904 pcap_read_sita_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_)
906 guint8 sita_phdr[SITA_HDR_LEN];
909 errno = WTAP_ERR_CANT_READ;
910 bytes_read = file_read(sita_phdr, 1, SITA_HDR_LEN, fh);
911 if (bytes_read != SITA_HDR_LEN) {
912 *err = file_error(fh);
914 *err = WTAP_ERR_SHORT_READ;
918 pseudo_header->sita.flags = sita_phdr[SITA_FLAGS_OFFSET];
919 pseudo_header->sita.signals = sita_phdr[SITA_SIGNALS_OFFSET];
920 pseudo_header->sita.errors1 = sita_phdr[SITA_ERRORS1_OFFSET];
921 pseudo_header->sita.errors2 = sita_phdr[SITA_ERRORS2_OFFSET];
922 pseudo_header->sita.proto = sita_phdr[SITA_PROTO_OFFSET];
928 * When not using the memory-mapped interface to capture USB events,
929 * code that reads those events can use the MON_IOCX_GET ioctl to
930 * read a 48-byte header consisting of a "struct linux_usb_phdr", as
931 * defined below, followed immediately by one of:
933 * 8 bytes of a "struct usb_device_setup_hdr", if "setup_flag"
934 * in the preceding "struct linux_usb_phdr" is 0;
936 * in Linux 2.6.30 or later, 8 bytes of a "struct iso_rec", if
937 * this is an isochronous transfer;
939 * 8 bytes of junk, otherwise.
941 * In Linux 2.6.31 and later, it can also use the MON_IOCX_GETX ioctl
942 * to read a 64-byte header; that header consists of the 48 bytes
943 * above, followed immediately by 16 bytes of a "struct linux_usb_phdr_ext",
946 * In Linux 2.6.21 and later, there's a memory-mapped interface to
947 * capture USB events. In that interface, the events in the memory-mapped
948 * buffer have a 64-byte header, followed immediately by the data.
949 * In Linux 2.6.21 through 2.6.30.x, the 64-byte header is the 48-byte
950 * header described above, followed by 16 bytes of zeroes; in Linux
951 * 2.6.31 and later, the 64-byte header is the 64-byte header described
954 * See linux/Documentation/usb/usbmon.txt and libpcap/pcap/usb.h for details.
956 * With WTAP_ENCAP_USB_LINUX, packets have the 48-byte header; with
957 * WTAP_ENCAP_USB_LINUX_MMAPPED, they have the 64-byte header. There
958 * is no indication of whether the header has the "struct iso_rec", or
959 * whether the last 16 bytes of a 64-byte header are all zeros or are
960 * a "struct linux_usb_phdr_ext".
964 * Header prepended by Linux kernel to each USB event.
966 * (Setup flag is '-', 'D', 'Z', or 0. Data flag is '<', '>', 'Z', or 0.)
968 * The values are in *host* byte order.
970 struct linux_usb_phdr {
971 guint64 id; /* urb id, to link submission and completion events */
972 guint8 event_type; /* Submit ('S'), Completed ('C'), Error ('E') */
973 guint8 transfer_type; /* ISO (0), Intr, Control, Bulk (3) */
974 guint8 endpoint_number; /* Endpoint number (0-15) and transfer direction */
975 guint8 device_address; /* 0-127 */
977 gint8 setup_flag; /* 0, if the urb setup header is meaningful */
978 gint8 data_flag; /* 0, if urb data is present */
982 guint32 urb_len; /* whole len of urb this event refers to */
983 guint32 data_len; /* amount of urb data really present in this event */
986 * Packet-type-dependent data.
987 * USB setup information of setup_flag is true.
988 * Otherwise, some isochronous transfer information.
993 * This data is provided by Linux 2.6.31 and later kernels.
995 * For WTAP_ENCAP_USB_LINUX, it's not in the pseudo-header, so
996 * the pseudo-header is always 48 bytes long, including the
997 * packet-type-dependent data.
999 * For WTAP_ENCAP_USB_LINUX_MMAPPED, the pseudo-header is always
1000 * 64 bytes long, with the packet-type-dependent data preceding
1001 * these last 16 bytes. In pre-2.6.31 kernels, it's zero padding;
1002 * in 2.6.31 and later, it's the following data.
1004 gint32 interval; /* only for Interrupt and Isochronous events */
1005 gint32 start_frame; /* for Isochronous */
1006 guint32 xfer_flags; /* copy of URB's transfer_flags */
1007 guint32 ndesc; /* actual number of isochronous descriptors */
1011 * USB setup header as defined in USB specification
1012 * See usb_20.pdf, Chapter 9.3 'USB Device Requests' for details.
1013 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
1015 * This structure is 8 bytes long.
1017 struct usb_device_setup_hdr {
1018 gint8 bmRequestType;
1026 * Information from the URB for Isochronous transfers.
1028 * This structure is 8 bytes long.
1036 * Offset of the *end* of a field within a particular structure.
1038 #define END_OFFSETOF(basep, fieldp) \
1039 (((char *)(void *)(fieldp)) - ((char *)(void *)(basep)) + \
1043 pcap_process_linux_usb_pseudoheader(guint packet_size, gboolean byte_swapped,
1044 gboolean header_len_64_bytes, guint8 *pd)
1046 struct linux_usb_phdr *phdr;
1049 phdr = (struct linux_usb_phdr *)pd;
1051 if (packet_size < END_OFFSETOF(phdr, &phdr->id))
1053 PBSWAP64((guint8 *)&phdr->id);
1054 if (packet_size < END_OFFSETOF(phdr, &phdr->bus_id))
1056 PBSWAP16((guint8 *)&phdr->bus_id);
1057 if (packet_size < END_OFFSETOF(phdr, &phdr->ts_sec))
1059 PBSWAP64((guint8 *)&phdr->ts_sec);
1060 if (packet_size < END_OFFSETOF(phdr, &phdr->ts_usec))
1062 PBSWAP32((guint8 *)&phdr->ts_usec);
1063 if (packet_size < END_OFFSETOF(phdr, &phdr->status))
1065 PBSWAP32((guint8 *)&phdr->status);
1066 if (packet_size < END_OFFSETOF(phdr, &phdr->urb_len))
1068 PBSWAP32((guint8 *)&phdr->urb_len);
1069 if (packet_size < END_OFFSETOF(phdr, &phdr->data_len))
1071 PBSWAP32((guint8 *)&phdr->data_len);
1073 if (header_len_64_bytes) {
1075 * This is either the "version 1" header, with
1076 * 16 bytes of additional fields at the end, or
1077 * a "version 0" header from a memory-mapped
1078 * capture, with 16 bytes of zeroed-out padding
1079 * at the end. Byte swap them as if this were
1080 * a "version 1" header.
1082 * Yes, the first argument to END_OFFSETOF() should
1083 * be phdr, not phdr_ext; we want the offset of
1084 * the additional fields from the beginning of
1087 if (packet_size < END_OFFSETOF(phdr, &phdr->interval))
1089 PBSWAP32((guint8 *)&phdr->interval);
1090 if (packet_size < END_OFFSETOF(phdr, &phdr->start_frame))
1092 PBSWAP32((guint8 *)&phdr->start_frame);
1093 if (packet_size < END_OFFSETOF(phdr, &phdr->xfer_flags))
1095 PBSWAP32((guint8 *)&phdr->xfer_flags);
1096 if (packet_size < END_OFFSETOF(phdr, &phdr->ndesc))
1098 PBSWAP32((guint8 *)&phdr->ndesc);
1104 pcap_read_bt_pseudoheader(FILE_T fh,
1105 union wtap_pseudo_header *pseudo_header, int *err)
1108 struct libpcap_bt_phdr phdr;
1110 errno = WTAP_ERR_CANT_READ;
1111 bytes_read = file_read(&phdr, 1,
1112 sizeof (struct libpcap_bt_phdr), fh);
1113 if (bytes_read != sizeof (struct libpcap_bt_phdr)) {
1114 *err = file_error(fh);
1116 *err = WTAP_ERR_SHORT_READ;
1119 pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
1124 pcap_read_ppp_pseudoheader(FILE_T fh,
1125 union wtap_pseudo_header *pseudo_header, int *err)
1128 struct libpcap_ppp_phdr phdr;
1130 errno = WTAP_ERR_CANT_READ;
1131 bytes_read = file_read(&phdr, 1,
1132 sizeof (struct libpcap_ppp_phdr), fh);
1133 if (bytes_read != sizeof (struct libpcap_ppp_phdr)) {
1134 *err = file_error(fh);
1136 *err = WTAP_ERR_SHORT_READ;
1139 pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
1144 pcap_read_erf_pseudoheader(FILE_T fh, struct wtap_pkthdr *whdr,
1145 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_)
1147 guint8 erf_hdr[sizeof(struct erf_phdr)];
1150 errno = WTAP_ERR_CANT_READ;
1151 bytes_read = file_read(erf_hdr, 1, sizeof(struct erf_phdr), fh);
1152 if (bytes_read != sizeof(struct erf_phdr)) {
1153 *err = file_error(fh);
1155 *err = WTAP_ERR_SHORT_READ;
1158 pseudo_header->erf.phdr.ts = pletohll(&erf_hdr[0]); /* timestamp */
1159 pseudo_header->erf.phdr.type = erf_hdr[8];
1160 pseudo_header->erf.phdr.flags = erf_hdr[9];
1161 pseudo_header->erf.phdr.rlen = pntohs(&erf_hdr[10]);
1162 pseudo_header->erf.phdr.lctr = pntohs(&erf_hdr[12]);
1163 pseudo_header->erf.phdr.wlen = pntohs(&erf_hdr[14]);
1165 /* The high 32 bits of the timestamp contain the integer number of seconds
1166 * while the lower 32 bits contain the binary fraction of the second.
1167 * This allows an ultimate resolution of 1/(2^32) seconds, or approximately 233 picoseconds */
1169 guint64 ts = pseudo_header->erf.phdr.ts;
1170 whdr->ts.secs = (guint32) (ts >> 32);
1171 ts = ((ts & 0xffffffff) * 1000 * 1000 * 1000);
1172 ts += (ts & 0x80000000) << 1; /* rounding */
1173 whdr->ts.nsecs = ((guint32) (ts >> 32));
1174 if ( whdr->ts.nsecs >= 1000000000) {
1175 whdr->ts.nsecs -= 1000000000;
1183 * If the type of record given in the pseudo header indicate the presence of an extension
1184 * header then, read all the extension headers
1187 pcap_read_erf_exheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1188 int *err, gchar **err_info _U_, guint * psize)
1191 guint8 erf_exhdr[8];
1192 guint64 erf_exhdr_sw;
1193 int i = 0, max = sizeof(pseudo_header->erf.ehdr_list)/sizeof(struct erf_ehdr);
1194 guint8 type = pseudo_header->erf.phdr.type;
1196 if (pseudo_header->erf.phdr.type & 0x80){
1198 errno = WTAP_ERR_CANT_READ;
1199 bytes_read = file_read(erf_exhdr, 1, 8, fh);
1200 if (bytes_read != 8 ) {
1201 *err = file_error(fh);
1203 *err = WTAP_ERR_SHORT_READ;
1206 type = erf_exhdr[0];
1207 erf_exhdr_sw = pntohll((guint64*) &(erf_exhdr[0]));
1209 memcpy(&pseudo_header->erf.ehdr_list[i].ehdr, &erf_exhdr_sw, sizeof(erf_exhdr_sw));
1212 } while (type & 0x80);
1218 * If the type of record given in the pseudo header indicate the precense of a subheader
1219 * then, read this optional subheader
1222 pcap_read_erf_subheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
1223 int *err, gchar **err_info _U_, guint * psize)
1225 guint8 erf_subhdr[sizeof(union erf_subhdr)];
1229 switch(pseudo_header->erf.phdr.type & 0x7F) {
1230 case ERF_TYPE_MC_HDLC:
1231 case ERF_TYPE_MC_RAW:
1232 case ERF_TYPE_MC_ATM:
1233 case ERF_TYPE_MC_RAW_CHANNEL:
1234 case ERF_TYPE_MC_AAL5:
1235 case ERF_TYPE_MC_AAL2:
1236 case ERF_TYPE_COLOR_MC_HDLC_POS:
1237 /* Extract the Multi Channel header to include it in the pseudo header part */
1238 errno = WTAP_ERR_CANT_READ;
1239 bytes_read = file_read(erf_subhdr, 1, sizeof(erf_mc_header_t), fh);
1240 if (bytes_read != sizeof(erf_mc_header_t) ) {
1241 *err = file_error(fh);
1243 *err = WTAP_ERR_SHORT_READ;
1246 pseudo_header->erf.subhdr.mc_hdr = pntohl(&erf_subhdr[0]);
1247 *psize = sizeof(erf_mc_header_t);
1250 case ERF_TYPE_COLOR_ETH:
1251 case ERF_TYPE_DSM_COLOR_ETH:
1252 /* Extract the Ethernet additional header to include it in the pseudo header part */
1253 errno = WTAP_ERR_CANT_READ;
1254 bytes_read = file_read(erf_subhdr, 1, sizeof(erf_eth_header_t), fh);
1255 if (bytes_read != sizeof(erf_eth_header_t) ) {
1256 *err = file_error(fh);
1258 *err = WTAP_ERR_SHORT_READ;
1261 pseudo_header->erf.subhdr.eth_hdr = pntohs(&erf_subhdr[0]);
1262 *psize = sizeof(erf_eth_header_t);
1265 /* No optional pseudo header for this ERF type */
1272 pcap_read_i2c_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info _U_)
1274 struct i2c_file_hdr i2c_hdr;
1277 errno = WTAP_ERR_CANT_READ;
1278 bytes_read = file_read(&i2c_hdr, 1, sizeof (i2c_hdr), fh);
1279 if (bytes_read != sizeof (i2c_hdr)) {
1280 *err = file_error(fh);
1282 *err = WTAP_ERR_SHORT_READ;
1286 pseudo_header->i2c.is_event = i2c_hdr.bus & 0x80 ? 1 : 0;
1287 pseudo_header->i2c.bus = i2c_hdr.bus & 0x7f;
1288 pseudo_header->i2c.flags = pntohl(&i2c_hdr.flags);
1294 pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
1295 guint packet_size, gboolean check_packet_size, struct wtap_pkthdr *phdr,
1296 union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
1301 switch (wtap_encap) {
1303 case WTAP_ENCAP_ATM_PDUS:
1304 if (file_type == WTAP_FILE_PCAP_NOKIA) {
1308 if (check_packet_size && packet_size < NOKIAATM_LEN) {
1310 * Uh-oh, the packet isn't big enough to even
1311 * have a pseudo-header.
1313 *err = WTAP_ERR_BAD_RECORD;
1314 *err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1318 if (!pcap_read_nokiaatm_pseudoheader(fh,
1319 pseudo_header, err))
1320 return -1; /* Read error */
1322 phdr_len = NOKIAATM_LEN;
1327 if (check_packet_size && packet_size < SUNATM_LEN) {
1329 * Uh-oh, the packet isn't big enough to even
1330 * have a pseudo-header.
1332 *err = WTAP_ERR_BAD_RECORD;
1333 *err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
1337 if (!pcap_read_sunatm_pseudoheader(fh,
1338 pseudo_header, err))
1339 return -1; /* Read error */
1341 phdr_len = SUNATM_LEN;
1345 case WTAP_ENCAP_ETHERNET:
1347 * We don't know whether there's an FCS in this frame or not.
1349 pseudo_header->eth.fcs_len = -1;
1352 case WTAP_ENCAP_IEEE_802_11:
1353 case WTAP_ENCAP_PRISM_HEADER:
1354 case WTAP_ENCAP_IEEE_802_11_WLAN_RADIOTAP:
1355 case WTAP_ENCAP_IEEE_802_11_WLAN_AVS:
1357 * We don't know whether there's an FCS in this frame or not.
1358 * XXX - are there any OSes where the capture mechanism
1361 pseudo_header->ieee_802_11.fcs_len = -1;
1362 pseudo_header->ieee_802_11.channel = 0;
1363 pseudo_header->ieee_802_11.data_rate = 0;
1364 pseudo_header->ieee_802_11.signal_level = 0;
1367 case WTAP_ENCAP_IRDA:
1368 if (check_packet_size && packet_size < IRDA_SLL_LEN) {
1370 * Uh-oh, the packet isn't big enough to even
1371 * have a pseudo-header.
1373 *err = WTAP_ERR_BAD_RECORD;
1374 *err_info = g_strdup_printf("pcap: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
1378 if (!pcap_read_irda_pseudoheader(fh, pseudo_header,
1380 return -1; /* Read error */
1382 phdr_len = IRDA_SLL_LEN;
1385 case WTAP_ENCAP_MTP2_WITH_PHDR:
1386 if (check_packet_size && packet_size < MTP2_HDR_LEN) {
1388 * Uh-oh, the packet isn't big enough to even
1389 * have a pseudo-header.
1391 *err = WTAP_ERR_BAD_RECORD;
1392 *err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
1396 if (!pcap_read_mtp2_pseudoheader(fh, pseudo_header,
1398 return -1; /* Read error */
1400 phdr_len = MTP2_HDR_LEN;
1403 case WTAP_ENCAP_LINUX_LAPD:
1404 if (check_packet_size && packet_size < LAPD_SLL_LEN) {
1406 * Uh-oh, the packet isn't big enough to even
1407 * have a pseudo-header.
1409 *err = WTAP_ERR_BAD_RECORD;
1410 *err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
1414 if (!pcap_read_lapd_pseudoheader(fh, pseudo_header,
1416 return -1; /* Read error */
1418 phdr_len = LAPD_SLL_LEN;
1421 case WTAP_ENCAP_SITA:
1422 if (check_packet_size && packet_size < SITA_HDR_LEN) {
1424 * Uh-oh, the packet isn't big enough to even
1425 * have a pseudo-header.
1427 *err = WTAP_ERR_BAD_RECORD;
1428 *err_info = g_strdup_printf("pcap: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
1432 if (!pcap_read_sita_pseudoheader(fh, pseudo_header,
1434 return -1; /* Read error */
1436 phdr_len = SITA_HDR_LEN;
1439 case WTAP_ENCAP_BLUETOOTH_H4:
1440 /* We don't have pseudoheader, so just pretend we received everything. */
1441 pseudo_header->p2p.sent = FALSE;
1444 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1445 if (check_packet_size &&
1446 packet_size < sizeof (struct libpcap_bt_phdr)) {
1448 * Uh-oh, the packet isn't big enough to even
1449 * have a pseudo-header.
1451 *err = WTAP_ERR_BAD_RECORD;
1452 *err_info = g_strdup_printf("pcap: lipcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
1456 if (!pcap_read_bt_pseudoheader(fh,
1457 pseudo_header, err))
1458 return -1; /* Read error */
1460 phdr_len = (int)sizeof (struct libpcap_bt_phdr);
1463 case WTAP_ENCAP_PPP_WITH_PHDR:
1464 if (check_packet_size &&
1465 packet_size < sizeof (struct libpcap_ppp_phdr)) {
1467 * Uh-oh, the packet isn't big enough to even
1468 * have a pseudo-header.
1470 *err = WTAP_ERR_BAD_RECORD;
1471 *err_info = g_strdup_printf("pcap: lipcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
1475 if (!pcap_read_ppp_pseudoheader(fh,
1476 pseudo_header, err))
1477 return -1; /* Read error */
1479 phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
1482 case WTAP_ENCAP_ERF:
1483 if (check_packet_size &&
1484 packet_size < sizeof(struct erf_phdr) ) {
1486 * Uh-oh, the packet isn't big enough to even
1487 * have a pseudo-header.
1489 *err = WTAP_ERR_BAD_RECORD;
1490 *err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
1495 if (!pcap_read_erf_pseudoheader(fh, phdr, pseudo_header,
1497 return -1; /* Read error */
1499 phdr_len = (int)sizeof(struct erf_phdr);
1501 /* check the optional Extension header */
1502 if (!pcap_read_erf_exheader(fh, pseudo_header, err, err_info,
1504 return -1; /* Read error */
1508 /* check the optional Multi Channel header */
1509 if (!pcap_read_erf_subheader(fh, pseudo_header, err, err_info,
1511 return -1; /* Read error */
1516 case WTAP_ENCAP_I2C:
1517 if (check_packet_size &&
1518 packet_size < sizeof (struct i2c_file_hdr)) {
1520 * Uh-oh, the packet isn't big enough to even
1521 * have a pseudo-header.
1523 *err = WTAP_ERR_BAD_RECORD;
1524 *err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
1528 if (!pcap_read_i2c_pseudoheader(fh, pseudo_header,
1530 return -1; /* Read error */
1533 * Don't count the pseudo-header as part of the packet.
1535 phdr_len = (int)sizeof (struct i2c_file_hdr);
1543 pcap_read_post_process(int wtap_encap, guint packet_size,
1544 gboolean bytes_swapped, guchar *pd)
1546 switch (wtap_encap) {
1548 case WTAP_ENCAP_USB_LINUX:
1549 pcap_process_linux_usb_pseudoheader(packet_size,
1550 bytes_swapped, FALSE, pd);
1553 case WTAP_ENCAP_USB_LINUX_MMAPPED:
1554 pcap_process_linux_usb_pseudoheader(packet_size,
1555 bytes_swapped, TRUE, pd);
1564 pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
1570 case WTAP_ENCAP_ATM_PDUS:
1571 hdrsize = SUNATM_LEN;
1574 case WTAP_ENCAP_IRDA:
1575 hdrsize = IRDA_SLL_LEN;
1578 case WTAP_ENCAP_MTP2_WITH_PHDR:
1579 hdrsize = MTP2_HDR_LEN;
1582 case WTAP_ENCAP_LINUX_LAPD:
1583 hdrsize = LAPD_SLL_LEN;
1586 case WTAP_ENCAP_SITA:
1587 hdrsize = SITA_HDR_LEN;
1590 case WTAP_ENCAP_ERF:
1591 hdrsize = (int)sizeof (struct erf_phdr);
1592 if (pseudo_header->erf.phdr.type & 0x80)
1594 switch (pseudo_header->erf.phdr.type & 0x7F) {
1596 case ERF_TYPE_MC_HDLC:
1597 case ERF_TYPE_MC_RAW:
1598 case ERF_TYPE_MC_ATM:
1599 case ERF_TYPE_MC_RAW_CHANNEL:
1600 case ERF_TYPE_MC_AAL5:
1601 case ERF_TYPE_MC_AAL2:
1602 case ERF_TYPE_COLOR_MC_HDLC_POS:
1603 hdrsize += (int)sizeof(struct erf_mc_hdr);
1607 case ERF_TYPE_COLOR_ETH:
1608 case ERF_TYPE_DSM_COLOR_ETH:
1609 hdrsize += (int)sizeof(struct erf_eth_hdr);
1617 case WTAP_ENCAP_I2C:
1618 hdrsize = (int)sizeof (struct i2c_file_hdr);
1621 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1622 hdrsize = (int)sizeof (struct libpcap_bt_phdr);
1625 case WTAP_ENCAP_PPP_WITH_PHDR:
1626 hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
1638 pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pseudo_header,
1641 guint8 atm_hdr[SUNATM_LEN];
1642 guint8 irda_hdr[IRDA_SLL_LEN];
1643 guint8 lapd_hdr[LAPD_SLL_LEN];
1644 guint8 mtp2_hdr[MTP2_HDR_LEN];
1645 guint8 sita_hdr[SITA_HDR_LEN];
1646 guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
1647 struct i2c_file_hdr i2c_hdr;
1648 struct libpcap_bt_phdr bt_hdr;
1649 struct libpcap_ppp_phdr ppp_hdr;
1654 case WTAP_ENCAP_ATM_PDUS:
1656 * Write the ATM header.
1658 atm_hdr[SUNATM_FLAGS] =
1659 (pseudo_header->atm.channel == 0) ? 0x80 : 0x00;
1660 switch (pseudo_header->atm.aal) {
1662 case AAL_SIGNALLING:
1664 atm_hdr[SUNATM_FLAGS] |= 0x06;
1668 switch (pseudo_header->atm.type) {
1672 atm_hdr[SUNATM_FLAGS] |= 0x01;
1676 /* RFC 1483 LLC multiplexed traffic */
1677 atm_hdr[SUNATM_FLAGS] |= 0x02;
1682 atm_hdr[SUNATM_FLAGS] |= 0x05;
1687 atm_hdr[SUNATM_VPI] = (guint8)pseudo_header->atm.vpi;
1688 phtons(&atm_hdr[SUNATM_VCI], pseudo_header->atm.vci);
1689 if (!wtap_dump_file_write(wdh, atm_hdr, sizeof(atm_hdr), err))
1691 wdh->bytes_dumped += sizeof(atm_hdr);
1694 case WTAP_ENCAP_IRDA:
1696 * Write the IrDA header.
1698 memset(irda_hdr, 0, sizeof(irda_hdr));
1699 phtons(&irda_hdr[IRDA_SLL_PKTTYPE_OFFSET],
1700 pseudo_header->irda.pkttype);
1701 phtons(&irda_hdr[IRDA_SLL_PROTOCOL_OFFSET], 0x0017);
1702 if (!wtap_dump_file_write(wdh, irda_hdr, sizeof(irda_hdr), err))
1704 wdh->bytes_dumped += sizeof(irda_hdr);
1707 case WTAP_ENCAP_MTP2_WITH_PHDR:
1709 * Write the MTP2 header.
1711 memset(&mtp2_hdr, 0, sizeof(mtp2_hdr));
1712 mtp2_hdr[MTP2_SENT_OFFSET] = pseudo_header->mtp2.sent;
1713 mtp2_hdr[MTP2_ANNEX_A_USED_OFFSET] = pseudo_header->mtp2.annex_a_used;
1714 phtons(&mtp2_hdr[MTP2_LINK_NUMBER_OFFSET],
1715 pseudo_header->mtp2.link_number);
1716 if (!wtap_dump_file_write(wdh, mtp2_hdr, sizeof(mtp2_hdr), err))
1718 wdh->bytes_dumped += sizeof(mtp2_hdr);
1721 case WTAP_ENCAP_LINUX_LAPD:
1723 * Write the LAPD header.
1725 memset(&lapd_hdr, 0, sizeof(lapd_hdr));
1726 phtons(&lapd_hdr[LAPD_SLL_PKTTYPE_OFFSET],
1727 pseudo_header->lapd.pkttype);
1728 phtons(&lapd_hdr[LAPD_SLL_PROTOCOL_OFFSET], ETH_P_LAPD);
1729 lapd_hdr[LAPD_SLL_ADDR_OFFSET + 0] =
1730 pseudo_header->lapd.we_network?0x01:0x00;
1731 if (!wtap_dump_file_write(wdh, lapd_hdr, sizeof(lapd_hdr), err))
1733 wdh->bytes_dumped += sizeof(lapd_hdr);
1736 case WTAP_ENCAP_SITA:
1738 * Write the SITA header.
1740 memset(&sita_hdr, 0, sizeof(sita_hdr));
1741 sita_hdr[SITA_FLAGS_OFFSET] = pseudo_header->sita.flags;
1742 sita_hdr[SITA_SIGNALS_OFFSET] = pseudo_header->sita.signals;
1743 sita_hdr[SITA_ERRORS1_OFFSET] = pseudo_header->sita.errors1;
1744 sita_hdr[SITA_ERRORS2_OFFSET] = pseudo_header->sita.errors2;
1745 sita_hdr[SITA_PROTO_OFFSET] = pseudo_header->sita.proto;
1746 if (!wtap_dump_file_write(wdh, sita_hdr, sizeof(sita_hdr), err))
1748 wdh->bytes_dumped += sizeof(sita_hdr);
1751 case WTAP_ENCAP_ERF:
1753 * Write the ERF header.
1755 memset(&erf_hdr, 0, sizeof(erf_hdr));
1756 pletonll(&erf_hdr[0], pseudo_header->erf.phdr.ts);
1757 erf_hdr[8] = pseudo_header->erf.phdr.type;
1758 erf_hdr[9] = pseudo_header->erf.phdr.flags;
1759 phtons(&erf_hdr[10], pseudo_header->erf.phdr.rlen);
1760 phtons(&erf_hdr[12], pseudo_header->erf.phdr.lctr);
1761 phtons(&erf_hdr[14], pseudo_header->erf.phdr.wlen);
1762 size = sizeof(struct erf_phdr);
1764 switch(pseudo_header->erf.phdr.type & 0x7F) {
1765 case ERF_TYPE_MC_HDLC:
1766 case ERF_TYPE_MC_RAW:
1767 case ERF_TYPE_MC_ATM:
1768 case ERF_TYPE_MC_RAW_CHANNEL:
1769 case ERF_TYPE_MC_AAL5:
1770 case ERF_TYPE_MC_AAL2:
1771 case ERF_TYPE_COLOR_MC_HDLC_POS:
1772 phtonl(&erf_hdr[16], pseudo_header->erf.subhdr.mc_hdr);
1773 size += (int)sizeof(struct erf_mc_hdr);
1776 case ERF_TYPE_COLOR_ETH:
1777 case ERF_TYPE_DSM_COLOR_ETH:
1778 phtons(&erf_hdr[16], pseudo_header->erf.subhdr.eth_hdr);
1779 size += (int)sizeof(struct erf_eth_hdr);
1784 if (!wtap_dump_file_write(wdh, erf_hdr, size, err))
1786 wdh->bytes_dumped += size;
1789 case WTAP_ENCAP_I2C:
1791 * Write the I2C header.
1793 memset(&i2c_hdr, 0, sizeof(i2c_hdr));
1794 i2c_hdr.bus = pseudo_header->i2c.bus |
1795 (pseudo_header->i2c.is_event ? 0x80 : 0x00);
1796 phtonl((guint8 *)&i2c_hdr.flags, pseudo_header->i2c.flags);
1797 if (!wtap_dump_file_write(wdh, &i2c_hdr, sizeof(i2c_hdr), err))
1799 wdh->bytes_dumped += sizeof(i2c_hdr);
1802 case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
1803 bt_hdr.direction = GUINT32_TO_BE(pseudo_header->p2p.sent ? LIBPCAP_BT_PHDR_SENT : LIBPCAP_BT_PHDR_RECV);
1804 if (!wtap_dump_file_write(wdh, &bt_hdr, sizeof bt_hdr, err))
1806 wdh->bytes_dumped += sizeof bt_hdr;
1809 case WTAP_ENCAP_PPP_WITH_PHDR:
1810 ppp_hdr.direction = (pseudo_header->p2p.sent ? LIBPCAP_PPP_PHDR_SENT : LIBPCAP_PPP_PHDR_RECV);
1811 if (!wtap_dump_file_write(wdh, &ppp_hdr, sizeof ppp_hdr, err))
1813 wdh->bytes_dumped += sizeof ppp_hdr;