diff options
author | Xin LI <delphij@FreeBSD.org> | 2012-05-14 05:12:56 +0000 |
---|---|---|
committer | Xin LI <delphij@FreeBSD.org> | 2012-05-14 05:12:56 +0000 |
commit | d1e8733132ce92d068898e4b3fe25ce17d634590 (patch) | |
tree | 158e6045ed438c41ac8de6cb27ac3c73cdc6643a /contrib/libpcap/pcap-common.c | |
parent | 47db53c31a5ec643382c4b08c3f68dd4ccdf79d9 (diff) | |
parent | 5a0615f5c40ce036a7e13cfffe00927f845ad563 (diff) | |
download | src-d1e8733132ce92d068898e4b3fe25ce17d634590.tar.gz src-d1e8733132ce92d068898e4b3fe25ce17d634590.zip |
Merge from vendor branch: update libpcap to 1.2.1.
MFC after: 2 weeks
Notes
Notes:
svn path=/head/; revision=235426
Diffstat (limited to 'contrib/libpcap/pcap-common.c')
-rw-r--r-- | contrib/libpcap/pcap-common.c | 595 |
1 files changed, 263 insertions, 332 deletions
diff --git a/contrib/libpcap/pcap-common.c b/contrib/libpcap/pcap-common.c index 979b5e364dac..f188eeb750ec 100644 --- a/contrib/libpcap/pcap-common.c +++ b/contrib/libpcap/pcap-common.c @@ -18,21 +18,9 @@ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * savefile.c - supports offline use of tcpdump - * Extraction/creation by Jeffrey Mogul, DECWRL - * Modified by Steve McCanne, LBL. - * - * Used to save the received packet headers, after filtering, to - * a file, and then read them later. - * The first record in the file contains saved values for the machine - * dependent values so we can print the dump file on any architecture. + * pcap-common.c - common code for pcap and pcap-ng files */ -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.183 2008-12-23 20:13:29 guy Exp $ (LBL)"; -#endif - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -106,6 +94,23 @@ static const char rcsid[] _U_ = * file, and new values after that one might have been assigned. Also, * do *NOT* use any values below 100 - those might already have been * taken by one (or more!) organizations. + * + * Any platform that defines additional DLT_* codes should: + * + * request a LINKTYPE_* code and value from tcpdump.org, + * as per the above; + * + * add, in their version of libpcap, an entry to map + * those DLT_* codes to the corresponding LINKTYPE_* + * code; + * + * redefine, in their "net/bpf.h", any DLT_* values + * that collide with the values used by their additional + * DLT_* codes, to remove those collisions (but without + * making them collide with any of the LINKTYPE_* + * values equal to 50 or above; they should also avoid + * defining DLT_* values that collide with those + * LINKTYPE_* values, either). */ #define LINKTYPE_NULL DLT_NULL #define LINKTYPE_ETHERNET DLT_EN10MB /* also for 100Mb and up */ @@ -114,7 +119,7 @@ static const char rcsid[] _U_ = #define LINKTYPE_PRONET DLT_PRONET #define LINKTYPE_CHAOS DLT_CHAOS #define LINKTYPE_TOKEN_RING DLT_IEEE802 /* DLT_IEEE802 is used for Token Ring */ -#define LINKTYPE_ARCNET DLT_ARCNET /* BSD-style headers */ +#define LINKTYPE_ARCNET_BSD DLT_ARCNET /* BSD-style headers */ #define LINKTYPE_SLIP DLT_SLIP #define LINKTYPE_PPP DLT_PPP #define LINKTYPE_FDDI DLT_FDDI @@ -140,10 +145,29 @@ static const char rcsid[] _U_ = #define LINKTYPE_SYMANTEC_FIREWALL 99 /* Symantec Enterprise Firewall */ +/* + * These correspond to DLT_s that have different values on different + * platforms; we map between these values in capture files and + * the DLT_ values as returned by pcap_datalink() and passed to + * pcap_open_dead(). + */ #define LINKTYPE_ATM_RFC1483 100 /* LLC/SNAP-encapsulated ATM */ #define LINKTYPE_RAW 101 /* raw IP */ #define LINKTYPE_SLIP_BSDOS 102 /* BSD/OS SLIP BPF header */ #define LINKTYPE_PPP_BSDOS 103 /* BSD/OS PPP BPF header */ + +/* + * Values starting with 104 are used for newly-assigned link-layer + * header type values; for those link-layer header types, the DLT_ + * value returned by pcap_datalink() and passed to pcap_open_dead(), + * and the LINKTYPE_ value that appears in capture files, are the + * same. + * + * LINKTYPE_MATCHING_MIN is the lowest such value; LINKTYPE_MATCHING_MAX + * is the highest such value. + */ +#define LINKTYPE_MATCHING_MIN 104 /* lowest value in the "matching" range */ + #define LINKTYPE_C_HDLC 104 /* Cisco HDLC */ #define LINKTYPE_IEEE802_11 105 /* IEEE 802.11 (wireless) */ #define LINKTYPE_ATM_CLIP 106 /* Linux Classical IP over ATM */ @@ -544,39 +568,39 @@ static const char rcsid[] _U_ = * IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman * <avn@pigeonpoint.com>. */ -#define LINKTYPE_IPMB_LINUX 209 +#define LINKTYPE_IPMB_LINUX 209 /* * FlexRay automotive bus - http://www.flexray.com/ - as requested * by Hannes Kaelber <hannes.kaelber@x2e.de>. */ -#define LINKTYPE_FLEXRAY 210 +#define LINKTYPE_FLEXRAY 210 /* * Media Oriented Systems Transport (MOST) bus for multimedia * transport - http://www.mostcooperation.com/ - as requested * by Hannes Kaelber <hannes.kaelber@x2e.de>. */ -#define LINKTYPE_MOST 211 +#define LINKTYPE_MOST 211 /* * Local Interconnect Network (LIN) bus for vehicle networks - * http://www.lin-subbus.org/ - as requested by Hannes Kaelber * <hannes.kaelber@x2e.de>. */ -#define LINKTYPE_LIN 212 +#define LINKTYPE_LIN 212 /* * X2E-private data link type used for serial line capture, * as requested by Hannes Kaelber <hannes.kaelber@x2e.de>. */ -#define LINKTYPE_X2E_SERIAL 213 +#define LINKTYPE_X2E_SERIAL 213 /* * X2E-private data link type used for the Xoraya data logger * family, as requested by Hannes Kaelber <hannes.kaelber@x2e.de>. */ -#define LINKTYPE_X2E_XORAYA 214 +#define LINKTYPE_X2E_XORAYA 214 /* * IEEE 802.15.4, exactly as it appears in the spec (no padding, no @@ -595,22 +619,22 @@ static const char rcsid[] _U_ = * is used to communicate keystrokes and mouse movements from the * Linux kernel to display systems, such as Xorg. */ -#define LINKTYPE_LINUX_EVDEV 216 +#define LINKTYPE_LINUX_EVDEV 216 /* * GSM Um and Abis interfaces, preceded by a "gsmtap" header. * * Requested by Harald Welte <laforge@gnumonks.org>. */ -#define LINKTYPE_GSMTAP_UM 217 -#define LINKTYPE_GSMTAP_ABIS 218 +#define LINKTYPE_GSMTAP_UM 217 +#define LINKTYPE_GSMTAP_ABIS 218 /* * MPLS, with an MPLS label as the link-layer header. * Requested by Michele Marchetto <michele@openbsd.org> on behalf * of OpenBSD. */ -#define LINKTYPE_MPLS 219 +#define LINKTYPE_MPLS 219 /* * USB packets, beginning with a Linux USB header, with the USB header @@ -622,7 +646,7 @@ static const char rcsid[] _U_ = * DECT packets, with a pseudo-header; requested by * Matthias Wenzel <tcpdump@mazzoo.de>. */ -#define LINKTYPE_DECT 221 +#define LINKTYPE_DECT 221 /* * From: "Lidwa, Eric (GSFC-582.0)[SGT INC]" <eric.lidwa-1@nasa.gov> @@ -633,7 +657,7 @@ static const char rcsid[] _U_ = * legal before I can submit a patch. * */ -#define LINKTYPE_AOS 222 +#define LINKTYPE_AOS 222 /* * Wireless HART (Highway Addressable Remote Transducer) @@ -642,13 +666,13 @@ static const char rcsid[] _U_ = * * Requested by Sam Roberts <vieuxtech@gmail.com>. */ -#define LINKTYPE_WIHART 223 +#define LINKTYPE_WIHART 223 /* * Fibre Channel FC-2 frames, beginning with a Frame_Header. * Requested by Kahou Lei <kahou82@gmail.com>. */ -#define LINKTYPE_FC_2 224 +#define LINKTYPE_FC_2 224 /* * Fibre Channel FC-2 frames, beginning with an encoding of the @@ -710,7 +734,7 @@ static const char rcsid[] _U_ = * An IPv4 or IPv6 datagram follows the pseudo-header; dli_family indicates * which of those it is. */ -#define LINKTYPE_IPNET 226 +#define LINKTYPE_IPNET 226 /* * CAN (Controller Area Network) frames, with a pseudo-header as supplied @@ -719,15 +743,114 @@ static const char rcsid[] _U_ = * * Requested by Felix Obenhuber <felix@obenhuber.de>. */ -#define LINKTYPE_CAN_SOCKETCAN 227 +#define LINKTYPE_CAN_SOCKETCAN 227 /* * Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies * whether it's v4 or v6. Requested by Darren Reed <Darren.Reed@Sun.COM>. */ -#define LINKTYPE_IPV4 228 -#define LINKTYPE_IPV6 229 +#define LINKTYPE_IPV4 228 +#define LINKTYPE_IPV6 229 + +/* + * IEEE 802.15.4, exactly as it appears in the spec (no padding, no + * nothing), and with no FCS at the end of the frame; requested by + * Jon Smirl <jonsmirl@gmail.com>. + */ +#define LINKTYPE_IEEE802_15_4_NOFCS 230 + +/* + * Raw D-Bus: + * + * http://www.freedesktop.org/wiki/Software/dbus + * + * messages: + * + * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-messages + * + * starting with the endianness flag, followed by the message type, etc., + * but without the authentication handshake before the message sequence: + * + * http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol + * + * Requested by Martin Vidner <martin@vidner.net>. + */ +#define LINKTYPE_DBUS 231 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler <hannes@juniper.net>. + */ +#define LINKTYPE_JUNIPER_VS 232 +#define LINKTYPE_JUNIPER_SRX_E2E 233 +#define LINKTYPE_JUNIPER_FIBRECHANNEL 234 + +/* + * DVB-CI (DVB Common Interface for communication between a PC Card + * module and a DVB receiver). See + * + * http://www.kaiser.cx/pcap-dvbci.html + * + * for the specification. + * + * Requested by Martin Kaiser <martin@kaiser.cx>. + */ +#define LINKTYPE_DVB_CI 235 + +/* + * Variant of 3GPP TS 27.010 multiplexing protocol. Requested + * by Hans-Christoph Schemmel <hans-christoph.schemmel@cinterion.com>. + */ +#define LINKTYPE_MUX27010 236 + +/* + * STANAG 5066 D_PDUs. Requested by M. Baris Demiray + * <barisdemiray@gmail.com>. + */ +#define LINKTYPE_STANAG_5066_D_PDU 237 + +/* + * Juniper-private data link type, as per request from + * Hannes Gredler <hannes@juniper.net>. + */ +#define LINKTYPE_JUNIPER_ATM_CEMIC 238 + +/* + * NetFilter LOG messages + * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets) + * + * Requested by Jakub Zawadzki <darkjames-ws@darkjames.pl> + */ +#define LINKTYPE_NFLOG 239 +/* + * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type + * for Ethernet packets with a 4-byte pseudo-header and always + * with the payload including the FCS, as supplied by their + * netANALYZER hardware and software. + * + * Requested by Holger P. Frommer <HPfrommer@hilscher.com> + */ +#define LINKTYPE_NETANALYZER 240 + +/* + * Hilscher Gesellschaft fuer Systemautomation mbH link-layer type + * for Ethernet packets with a 4-byte pseudo-header and FCS and + * 1 byte of SFD, as supplied by their netANALYZER hardware and + * software. + * + * Requested by Holger P. Frommer <HPfrommer@hilscher.com> + */ +#define LINKTYPE_NETANALYZER_TRANSPARENT 241 + +/* + * IP-over-Infiniband, as specified by RFC 4391. + * + * Requested by Petr Sumbera <petr.sumbera@oracle.com>. + */ +#define LINKTYPE_IPOIB 242 + +#define LINKTYPE_MATCHING_MAX 242 /* highest value in the "matching" range */ static struct linktype_map { int dlt; @@ -744,7 +867,7 @@ static struct linktype_map { { DLT_PRONET, LINKTYPE_PRONET }, { DLT_CHAOS, LINKTYPE_CHAOS }, { DLT_IEEE802, LINKTYPE_TOKEN_RING }, - { DLT_ARCNET, LINKTYPE_ARCNET }, + { DLT_ARCNET, LINKTYPE_ARCNET_BSD }, { DLT_SLIP, LINKTYPE_SLIP }, { DLT_PPP, LINKTYPE_PPP }, { DLT_FDDI, LINKTYPE_FDDI }, @@ -785,295 +908,12 @@ static struct linktype_map { /* NetBSD PPP over Ethernet */ { DLT_PPP_ETHER, LINKTYPE_PPP_ETHER }, - /* IEEE 802.11 wireless */ - { DLT_IEEE802_11, LINKTYPE_IEEE802_11 }, - - /* Frame Relay */ - { DLT_FRELAY, LINKTYPE_FRELAY }, - - /* OpenBSD loopback */ - { DLT_LOOP, LINKTYPE_LOOP }, - - /* OpenBSD IPSEC enc */ - { DLT_ENC, LINKTYPE_ENC }, - - /* Linux cooked socket capture */ - { DLT_LINUX_SLL, LINKTYPE_LINUX_SLL }, - - /* Apple LocalTalk hardware */ - { DLT_LTALK, LINKTYPE_LTALK }, - - /* Acorn Econet */ - { DLT_ECONET, LINKTYPE_ECONET }, - - /* OpenBSD DLT_PFLOG */ - { DLT_PFLOG, LINKTYPE_PFLOG }, - - /* For Cisco-internal use */ - { DLT_CISCO_IOS, LINKTYPE_CISCO_IOS }, - - /* Prism II monitor-mode header plus 802.11 header */ - { DLT_PRISM_HEADER, LINKTYPE_PRISM_HEADER }, - - /* FreeBSD Aironet driver stuff */ - { DLT_AIRONET_HEADER, LINKTYPE_AIRONET_HEADER }, - - /* Siemens HiPath HDLC */ - { DLT_HHDLC, LINKTYPE_HHDLC }, - - /* RFC 2625 IP-over-Fibre Channel */ - { DLT_IP_OVER_FC, LINKTYPE_IP_OVER_FC }, - - /* Solaris+SunATM */ - { DLT_SUNATM, LINKTYPE_SUNATM }, - - /* RapidIO */ - { DLT_RIO, LINKTYPE_RIO }, - - /* PCI Express */ - { DLT_PCI_EXP, LINKTYPE_PCI_EXP }, - - /* Xilinx Aurora link layer */ - { DLT_AURORA, LINKTYPE_AURORA }, - - /* 802.11 plus BSD radio header */ - { DLT_IEEE802_11_RADIO, LINKTYPE_IEEE802_11_RADIO }, - - /* Tazmen Sniffer Protocol */ - { DLT_TZSP, LINKTYPE_TZSP }, - - /* Arcnet with Linux-style link-layer headers */ - { DLT_ARCNET_LINUX, LINKTYPE_ARCNET_LINUX }, - - /* Juniper-internal chassis encapsulation */ - { DLT_JUNIPER_MLPPP, LINKTYPE_JUNIPER_MLPPP }, - { DLT_JUNIPER_MLFR, LINKTYPE_JUNIPER_MLFR }, - { DLT_JUNIPER_ES, LINKTYPE_JUNIPER_ES }, - { DLT_JUNIPER_GGSN, LINKTYPE_JUNIPER_GGSN }, - { DLT_JUNIPER_MFR, LINKTYPE_JUNIPER_MFR }, - { DLT_JUNIPER_ATM2, LINKTYPE_JUNIPER_ATM2 }, - { DLT_JUNIPER_SERVICES, LINKTYPE_JUNIPER_SERVICES }, - { DLT_JUNIPER_ATM1, LINKTYPE_JUNIPER_ATM1 }, - - /* Apple IP-over-IEEE 1394 cooked header */ - { DLT_APPLE_IP_OVER_IEEE1394, LINKTYPE_APPLE_IP_OVER_IEEE1394 }, - - /* SS7 */ - { DLT_MTP2_WITH_PHDR, LINKTYPE_MTP2_WITH_PHDR }, - { DLT_MTP2, LINKTYPE_MTP2 }, - { DLT_MTP3, LINKTYPE_MTP3 }, - { DLT_SCCP, LINKTYPE_SCCP }, - - /* DOCSIS MAC frames */ - { DLT_DOCSIS, LINKTYPE_DOCSIS }, - - /* IrDA IrLAP packets + Linux-cooked header */ - { DLT_LINUX_IRDA, LINKTYPE_LINUX_IRDA }, - - /* IBM SP and Next Federation switches */ - { DLT_IBM_SP, LINKTYPE_IBM_SP }, - { DLT_IBM_SN, LINKTYPE_IBM_SN }, - - /* 802.11 plus AVS radio header */ - { DLT_IEEE802_11_RADIO_AVS, LINKTYPE_IEEE802_11_RADIO_AVS }, - /* - * Any platform that defines additional DLT_* codes should: - * - * request a LINKTYPE_* code and value from tcpdump.org, - * as per the above; - * - * add, in their version of libpcap, an entry to map - * those DLT_* codes to the corresponding LINKTYPE_* - * code; - * - * redefine, in their "net/bpf.h", any DLT_* values - * that collide with the values used by their additional - * DLT_* codes, to remove those collisions (but without - * making them collide with any of the LINKTYPE_* - * values equal to 50 or above; they should also avoid - * defining DLT_* values that collide with those - * LINKTYPE_* values, either). + * All LINKTYPE_ values between LINKTYPE_MATCHING_MIN + * and LINKTYPE_MATCHING_MAX are mapped to identical + * DLT_ values. */ - /* Juniper-internal chassis encapsulation */ - { DLT_JUNIPER_MONITOR, LINKTYPE_JUNIPER_MONITOR }, - - /* BACnet MS/TP */ - { DLT_BACNET_MS_TP, LINKTYPE_BACNET_MS_TP }, - - /* PPP for pppd, with direction flag in the PPP header */ - { DLT_PPP_PPPD, LINKTYPE_PPP_PPPD}, - - /* Juniper-internal chassis encapsulation */ - { DLT_JUNIPER_PPPOE, LINKTYPE_JUNIPER_PPPOE }, - { DLT_JUNIPER_PPPOE_ATM,LINKTYPE_JUNIPER_PPPOE_ATM }, - - /* GPRS LLC */ - { DLT_GPRS_LLC, LINKTYPE_GPRS_LLC }, - - /* Transparent Generic Framing Procedure (ITU-T G.7041/Y.1303) */ - { DLT_GPF_T, LINKTYPE_GPF_T }, - - /* Framed Generic Framing Procedure (ITU-T G.7041/Y.1303) */ - { DLT_GPF_F, LINKTYPE_GPF_F }, - - { DLT_GCOM_T1E1, LINKTYPE_GCOM_T1E1 }, - { DLT_GCOM_SERIAL, LINKTYPE_GCOM_SERIAL }, - - /* Juniper-internal chassis encapsulation */ - { DLT_JUNIPER_PIC_PEER, LINKTYPE_JUNIPER_PIC_PEER }, - - /* Endace types */ - { DLT_ERF_ETH, LINKTYPE_ERF_ETH }, - { DLT_ERF_POS, LINKTYPE_ERF_POS }, - - /* viSDN LAPD */ - { DLT_LINUX_LAPD, LINKTYPE_LINUX_LAPD }, - - /* Juniper meta-information before Ether, PPP, Frame Relay, C-HDLC Frames */ - { DLT_JUNIPER_ETHER, LINKTYPE_JUNIPER_ETHER }, - { DLT_JUNIPER_PPP, LINKTYPE_JUNIPER_PPP }, - { DLT_JUNIPER_FRELAY, LINKTYPE_JUNIPER_FRELAY }, - { DLT_JUNIPER_CHDLC, LINKTYPE_JUNIPER_CHDLC }, - - /* Multi Link Frame Relay (FRF.16) */ - { DLT_MFR, LINKTYPE_MFR }, - - /* Juniper Voice PIC */ - { DLT_JUNIPER_VP, LINKTYPE_JUNIPER_VP }, - - /* Controller Area Network (CAN) v2.0B */ - { DLT_A429, LINKTYPE_A429 }, - - /* Arinc 653 Interpartition Communication messages */ - { DLT_A653_ICM, LINKTYPE_A653_ICM }, - - /* USB */ - { DLT_USB, LINKTYPE_USB }, - - /* Bluetooth HCI UART transport layer */ - { DLT_BLUETOOTH_HCI_H4, LINKTYPE_BLUETOOTH_HCI_H4 }, - - /* IEEE 802.16 MAC Common Part Sublayer */ - { DLT_IEEE802_16_MAC_CPS, LINKTYPE_IEEE802_16_MAC_CPS }, - - /* USB with Linux header */ - { DLT_USB_LINUX, LINKTYPE_USB_LINUX }, - - /* Controller Area Network (CAN) v2.0B */ - { DLT_CAN20B, LINKTYPE_CAN20B }, - - /* IEEE 802.15.4 with address fields padded */ - { DLT_IEEE802_15_4_LINUX, LINKTYPE_IEEE802_15_4_LINUX }, - - /* Per Packet Information encapsulated packets */ - { DLT_PPI, LINKTYPE_PPI }, - - /* IEEE 802.16 MAC Common Part Sublayer plus radiotap header */ - { DLT_IEEE802_16_MAC_CPS_RADIO, LINKTYPE_IEEE802_16_MAC_CPS_RADIO }, - - /* Juniper Voice ISM */ - { DLT_JUNIPER_ISM, LINKTYPE_JUNIPER_ISM }, - - /* IEEE 802.15.4 exactly as it appears in the spec */ - { DLT_IEEE802_15_4, LINKTYPE_IEEE802_15_4 }, - - /* Various link-layer types for SITA */ - { DLT_SITA, LINKTYPE_SITA }, - - /* Various link-layer types for Endace */ - { DLT_ERF, LINKTYPE_ERF }, - - /* Special header for u10 Networks boards */ - { DLT_RAIF1, LINKTYPE_RAIF1 }, - - /* IPMB */ - { DLT_IPMB, LINKTYPE_IPMB }, - - /* Juniper Secure Tunnel */ - { DLT_JUNIPER_ST, LINKTYPE_JUNIPER_ST }, - - /* Bluetooth HCI UART transport layer, with pseudo-header */ - { DLT_BLUETOOTH_HCI_H4_WITH_PHDR, LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR }, - - /* AX.25 with KISS header */ - { DLT_AX25_KISS, LINKTYPE_AX25_KISS }, - - /* Raw LAPD, with no pseudo-header */ - { DLT_LAPD, LINKTYPE_LAPD }, - - /* PPP with one-byte pseudo-header giving direction */ - { DLT_PPP_WITH_DIR, LINKTYPE_PPP_WITH_DIR }, - - /* Cisco HDLC with one-byte pseudo-header giving direction */ - { DLT_C_HDLC_WITH_DIR, LINKTYPE_C_HDLC_WITH_DIR }, - - /* Frame Relay with one-byte pseudo-header giving direction */ - { DLT_FRELAY_WITH_DIR, LINKTYPE_FRELAY_WITH_DIR }, - - /* LAPB with one-byte pseudo-header giving direction */ - { DLT_LAPB_WITH_DIR, LINKTYPE_LAPB_WITH_DIR }, - - /* IPMB with Linux pseudo-header */ - { DLT_IPMB_LINUX, LINKTYPE_IPMB_LINUX }, - - /* FlexRay */ - { DLT_FLEXRAY, LINKTYPE_FLEXRAY }, - - /* MOST */ - { DLT_MOST, LINKTYPE_MOST }, - - /* LIN */ - { DLT_LIN, LINKTYPE_LIN }, - - /* X2E-private serial line capture */ - { DLT_X2E_SERIAL, LINKTYPE_X2E_SERIAL }, - - /* X2E-private for Xoraya data logger family */ - { DLT_X2E_XORAYA, LINKTYPE_X2E_XORAYA }, - - /* IEEE 802.15.4 with PHY data for non-ASK PHYs */ - { DLT_IEEE802_15_4_NONASK_PHY, LINKTYPE_IEEE802_15_4_NONASK_PHY }, - - /* Input device events from Linux /dev/input/eventN devices */ - { DLT_LINUX_EVDEV, LINKTYPE_LINUX_EVDEV }, - - /* GSM types */ - { DLT_GSMTAP_UM, LINKTYPE_GSMTAP_UM }, - { DLT_GSMTAP_ABIS, LINKTYPE_GSMTAP_ABIS }, - - /* MPLS, with an MPLS label as the link-layer header */ - { DLT_MPLS, LINKTYPE_MPLS }, - - /* USB with padded Linux header */ - { DLT_USB_LINUX_MMAPPED, LINKTYPE_USB_LINUX_MMAPPED }, - - /* DECT packets with a pseudo-header */ - { DLT_DECT, LINKTYPE_DECT }, - - /* AOS Space Data Link Protocol */ - { DLT_AOS, LINKTYPE_AOS }, - - /* Wireless HART */ - { DLT_WIHART, LINKTYPE_WIHART }, - - /* Fibre Channel FC-2 frames without SOF or EOF */ - { DLT_FC_2, LINKTYPE_FC_2 }, - - /* Fibre Channel FC-2 frames with SOF and EOF */ - { DLT_FC_2_WITH_FRAME_DELIMS, LINKTYPE_FC_2_WITH_FRAME_DELIMS }, - - /* Solaris IPNET */ - { DLT_IPNET, LINKTYPE_IPNET }, - - /* CAN frames with SocketCAN headers */ - { DLT_CAN_SOCKETCAN, LINKTYPE_CAN_SOCKETCAN }, - - /* Raw IPv4/IPv6 */ - { DLT_IPV4, LINKTYPE_IPV4 }, - { DLT_IPV6, LINKTYPE_IPV6 }, - { -1, -1 } }; @@ -1082,6 +922,15 @@ dlt_to_linktype(int dlt) { int i; + /* + * Map the values in the matching range. + */ + if (dlt >= DLT_MATCHING_MIN && dlt <= DLT_MATCHING_MAX) + return (dlt); + + /* + * Map the values outside that range. + */ for (i = 0; map[i].dlt != -1; i++) { if (map[i].dlt == dlt) return (map[i].linktype); @@ -1089,8 +938,8 @@ dlt_to_linktype(int dlt) /* * If we don't have a mapping for this DLT_ code, return an - * error; that means that the table above needs to have an - * entry added. + * error; that means that this is a value with no corresponding + * LINKTYPE_ code, and we need to assign one. */ return (-1); } @@ -1100,6 +949,16 @@ linktype_to_dlt(int linktype) { int i; + /* + * Map the values in the matching range. + */ + if (linktype >= LINKTYPE_MATCHING_MIN && + linktype <= LINKTYPE_MATCHING_MAX) + return (linktype); + + /* + * Map the values outside that range. + */ for (i = 0; map[i].linktype != -1; i++) { if (map[i].linktype == linktype) return (map[i].dlt); @@ -1127,33 +986,72 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf, int header_len_64_bytes) { pcap_usb_header_mmapped *uhdr = (pcap_usb_header_mmapped *)buf; + bpf_u_int32 offset = 0; + usb_isodesc *pisodesc; + int32_t numdesc, i; + + /* + * "offset" is the offset *past* the field we're swapping; + * we skip the field *before* checking to make sure + * the captured data length includes the entire field. + */ /* * The URB id is a totally opaque value; do we really need to * convert it to the reading host's byte order??? */ - if (hdr->caplen < 8) + offset += 8; /* skip past id */ + if (hdr->caplen < offset) return; uhdr->id = SWAPLL(uhdr->id); - if (hdr->caplen < 14) + + offset += 4; /* skip past various 1-byte fields */ + + offset += 2; /* skip past bus_id */ + if (hdr->caplen < offset) return; uhdr->bus_id = SWAPSHORT(uhdr->bus_id); - if (hdr->caplen < 24) + + offset += 2; /* skip past various 1-byte fields */ + + offset += 8; /* skip past ts_sec */ + if (hdr->caplen < offset) return; uhdr->ts_sec = SWAPLL(uhdr->ts_sec); - if (hdr->caplen < 28) + + offset += 4; /* skip past ts_usec */ + if (hdr->caplen < offset) return; uhdr->ts_usec = SWAPLONG(uhdr->ts_usec); - if (hdr->caplen < 32) + + offset += 4; /* skip past status */ + if (hdr->caplen < offset) return; uhdr->status = SWAPLONG(uhdr->status); - if (hdr->caplen < 36) + + offset += 4; /* skip past urb_len */ + if (hdr->caplen < offset) return; uhdr->urb_len = SWAPLONG(uhdr->urb_len); - if (hdr->caplen < 40) + + offset += 4; /* skip past data_len */ + if (hdr->caplen < offset) return; uhdr->data_len = SWAPLONG(uhdr->data_len); + if (uhdr->transfer_type == URB_ISOCHRONOUS) { + offset += 4; /* skip past s.iso.error_count */ + if (hdr->caplen < offset) + return; + uhdr->s.iso.error_count = SWAPLONG(uhdr->s.iso.error_count); + + offset += 4; /* skip past s.iso.numdesc */ + if (hdr->caplen < offset) + return; + uhdr->s.iso.numdesc = SWAPLONG(uhdr->s.iso.numdesc); + } else + offset += 8; /* skip USB setup header */ + if (header_len_64_bytes) { /* * This is either the "version 1" header, with @@ -1163,17 +1061,50 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf, * at the end. Byte swap them as if this were * a "version 1" header. */ - if (hdr->caplen < 52) + offset += 4; /* skip past interval */ + if (hdr->caplen < offset) return; uhdr->interval = SWAPLONG(uhdr->interval); - if (hdr->caplen < 56) + + offset += 4; /* skip past start_frame */ + if (hdr->caplen < offset) return; uhdr->start_frame = SWAPLONG(uhdr->start_frame); - if (hdr->caplen < 60) + + offset += 4; /* skip past xfer_flags */ + if (hdr->caplen < offset) return; uhdr->xfer_flags = SWAPLONG(uhdr->xfer_flags); - if (hdr->caplen < 64) + + offset += 4; /* skip past ndesc */ + if (hdr->caplen < offset) return; uhdr->ndesc = SWAPLONG(uhdr->ndesc); } + + if (uhdr->transfer_type == URB_ISOCHRONOUS) { + /* swap the values in struct linux_usb_isodesc */ + pisodesc = (usb_isodesc *)(void *)(buf+offset); + numdesc = uhdr->s.iso.numdesc; + for (i = 0; i < numdesc; i++) { + offset += 4; /* skip past status */ + if (hdr->caplen < offset) + return; + pisodesc->status = SWAPLONG(pisodesc->status); + + offset += 4; /* skip past offset */ + if (hdr->caplen < offset) + return; + pisodesc->offset = SWAPLONG(pisodesc->offset); + + offset += 4; /* skip past len */ + if (hdr->caplen < offset) + return; + pisodesc->len = SWAPLONG(pisodesc->len); + + offset += 4; /* skip past padding */ + + pisodesc++; + } + } } |