]> The Tcpdump Group git mirrors - libpcap/blobdiff - pcap-common.c
pcap_create_interface() needs the interface name on Linux.
[libpcap] / pcap-common.c
index b4f0909316c795bd46c63d091a57a4a054a753d5..1aca831a873eeda702e6f5ff92de31965d69e2f6 100644 (file)
@@ -25,9 +25,9 @@
 #include "config.h"
 #endif
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* WIN32 */
+#else /* _WIN32 */
 #if HAVE_INTTYPES_H
 #include <inttypes.h>
 #elif HAVE_STDINT_H
@@ -37,7 +37,7 @@
 #include <sys/bitypes.h>
 #endif
 #include <sys/types.h>
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 #include "pcap-int.h"
 #include "pcap/usb.h"
 
 #define LINKTYPE_GPRS_LLC      169             /* GPRS LLC */
 #define LINKTYPE_GPF_T         170             /* GPF-T (ITU-T G.7041/Y.1303) */
-#define LINKTYPE_GPF_F         171             /* GPF-T (ITU-T G.7041/Y.1303) */
+#define LINKTYPE_GPF_F         171             /* GPF-F (ITU-T G.7041/Y.1303) */
 
 /*
  * Requested by Oolan Zimmer <[email protected]> for use in Gcom's T1/E1 line
 
 /*
  * Juniper-private data link type, as per request from
- * Hannes Gredler <[email protected]>. 
+ * Hannes Gredler <[email protected]>.
  * The Link Types are used for prepending meta-information
  * like interface index, interface name
  * before standard Ethernet, PPP, Frelay & C-HDLC Frames
 
 /*
  * Juniper-private data link type, as per request from
- * Hannes Gredler <[email protected]>. 
+ * Hannes Gredler <[email protected]>.
  * The DLT_ is used for internal communication with a
  * voice Adapter Card (PIC)
  */
 #define LINKTYPE_A653_ICM       185
 
 /*
- * USB packets, beginning with a USB setup header; requested by
- * Paolo Abeni <[email protected]>.
+ * This used to be "USB packets, beginning with a USB setup header;
+ * requested by Paolo Abeni <[email protected]>."
+ *
+ * However, that header didn't work all that well - it left out some
+ * useful information - and was abandoned in favor of the DLT_USB_LINUX
+ * header.
+ *
+ * This is now used by FreeBSD for its BPF taps for USB; that has its
+ * own headers.  So it is written, so it is done.
  */
-#define LINKTYPE_USB           186
+#define LINKTYPE_USB_FREEBSD   186
 
 /*
  * Bluetooth HCI UART transport layer (part H:4); requested by
 
 /*
  * Juniper-private data link type, as per request from
- * Hannes Gredler <[email protected]>. 
+ * Hannes Gredler <[email protected]>.
  * The DLT_ is used for internal communication with a
  * integrated service module (ISM).
  */
 
 /*
  * Juniper-private data link type, as per request from
- * Hannes Gredler <[email protected]>. 
+ * Hannes Gredler <[email protected]>.
  * The DLT_ is used for capturing data on a secure tunnel interface.
  */
 #define LINKTYPE_JUNIPER_ST     200
  */
 #define LINKTYPE_IEEE802_15_4_NONASK_PHY       215
 
-/* 
+/*
  * David Gibson <[email protected]> requested this for
  * captures from the Linux kernel /dev/input/eventN devices. This
  * is used to communicate keystrokes and mouse movements from the
- * Linux kernel to display systems, such as Xorg. 
+ * Linux kernel to display systems, such as Xorg.
  */
 #define LINKTYPE_LINUX_EVDEV   216
 
 
 /*
  * Juniper-private data link type, as per request from
- * Hannes Gredler <[email protected]>. 
+ * Hannes Gredler <[email protected]>.
  */
 #define LINKTYPE_JUNIPER_VS                    232
 #define LINKTYPE_JUNIPER_SRX_E2E               233
 
 /*
  * Juniper-private data link type, as per request from
- * Hannes Gredler <[email protected]>. 
+ * Hannes Gredler <[email protected]>.
  */
 #define LINKTYPE_JUNIPER_ATM_CEMIC             238
 
 /*
- * NetFilter LOG messages 
+ * NetFilter LOG messages
  * (payload of netlink NFNL_SUBSYS_ULOG/NFULNL_MSG_PACKET packets)
  *
  * Requested by Jakub Zawadzki <[email protected]>
 
 /*
  * Link-layer header type for upper-protocol layer PDU saves from wireshark.
- * 
+ *
  * the actual contents are determined by two TAGs stored with each
  * packet:
  *   EXP_PDU_TAG_LINKTYPE          the link type (LINKTYPE_ value) of the
  */
 #define LINKTYPE_PROFIBUS_DL           257
 
-
 /*
  * Apple's DLT_PKTAP headers.
  *
  */
 #define LINKTYPE_EPON          259
 
-#define LINKTYPE_MATCHING_MAX  259             /* highest value in the "matching" range */
+/*
+ * IPMI trace packets, as specified by Table 3-20 "Trace Data Block Format"
+ * in the PICMG HPM.2 specification.
+ */
+#define LINKTYPE_IPMI_HPM_2    260
+
+/*
+ * per  Joshua Wright <[email protected]>, formats for Zwave captures.
+ */
+#define LINKTYPE_ZWAVE_R1_R2   261
+#define LINKTYPE_ZWAVE_R3      262
+
+/*
+ * per Steve Karg <[email protected]>, formats for Wattstopper
+ * Digital Lighting Management room bus serial protocol captures.
+ */
+#define LINKTYPE_WATTSTOPPER_DLM 263
+
+/*
+ * ISO 14443 contactless smart card messages.
+ */
+#define LINKTYPE_ISO_14443      264
+
+#define LINKTYPE_MATCHING_MAX  264             /* highest value in the "matching" range */
 
 static struct linktype_map {
        int     dlt;
@@ -1150,8 +1179,6 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
 {
        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;
@@ -1160,7 +1187,7 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
         */
 
        /*
-        * The URB id is a totally opaque value; do we really need to 
+        * The URB id is a totally opaque value; do we really need to
         * convert it to the reading host's byte order???
         */
        offset += 8;                    /* skip past id */
@@ -1215,6 +1242,17 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
        } else
                offset += 8;                    /* skip USB setup header */
 
+       /*
+        * With the old header, there are no isochronous descriptors
+        * after the header.
+        *
+        * With the new header, the actual number of descriptors in
+        * the header is not s.iso.numdesc, it's ndesc - only the
+        * first N descriptors, for some value of N, are put into
+        * the header, and ndesc is set to the actual number copied.
+        * In addition, if s.iso.numdesc is negative, no descriptors
+        * are captured, and ndesc is set to 0.
+        */
        if (header_len_64_bytes) {
                /*
                 * This is either the "version 1" header, with
@@ -1243,31 +1281,33 @@ swap_linux_usb_header(const struct pcap_pkthdr *hdr, u_char *buf,
                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++;
+               if (uhdr->transfer_type == URB_ISOCHRONOUS) {
+                       /* swap the values in struct linux_usb_isodesc */
+                       usb_isodesc *pisodesc;
+                       u_int32_t i;
+
+                       pisodesc = (usb_isodesc *)(void *)(buf+offset);
+                       for (i = 0; i < uhdr->ndesc; 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++;
+                       }
                }
        }
 }
@@ -1298,7 +1338,7 @@ swap_nflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
                return;
        }
 
-       if (!(nfhdr->nflog_version) == 0) {
+       if (nfhdr->nflog_version != 0) {
                /* Unknown NFLOG version */
                return;
        }