]> The Tcpdump Group git mirrors - libpcap/commitdiff
Put the stuff to get the sized integer types defined into pcap-types.h.
authorGuy Harris <[email protected]>
Mon, 4 Sep 2017 07:51:48 +0000 (00:51 -0700)
committerGuy Harris <[email protected]>
Mon, 4 Sep 2017 07:51:48 +0000 (00:51 -0700)
Have pcap-types.h arrange to define the intN_t/u_intN_t types, and the
INTn_MAX/UINTn_MAX values, on all platforms, and use it wherever it's
appropriate.

Include it up front in scanner.l, to avoid redefinitions of the
INTn_MAX/UINTn_MAX types.

14 files changed:
Makefile.in
bpf/net/bpf_filter.c
bpf_image.c
etherent.c
gencode.c
optimize.c
pcap-common.c
pcap-stdinc.h
pcap-types.h [new file with mode: 0644]
pcap.c
savefile.c
scanner.l
sf-pcap-ng.c
sf-pcap.c

index bacf2053fbea98c2fba68a19cd53f01a13d29ea2..f443711c6e1cdbf5863c367a327e806ffa913402 100644 (file)
@@ -130,6 +130,7 @@ HDR = $(PUBHDR) \
        pcap-int.h \
        pcap-rpcap.h \
        pcap-stdinc.h \
+       pcap-types.h \
        portability.h \
        ppp.h \
        rpcap-protocol.h \
index 0ff31f9d462f2b5aa849634d5f9e652183f12410..fc63cac080ba2edf46e9f2a44c5dffb3adbccb5b 100644 (file)
 #include <config.h>
 #endif
 
-#ifdef _WIN32
+#include <pcap-types.h>
 
+#ifdef _WIN32
 #include <pcap-stdinc.h>
-
 #else /* _WIN32 */
 
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/time.h>
index ec659dc1b2b7a6cdedfeb2e14cb5c58ce7ddcbd6..392f5d734a8da7bc0eeabf268fadf9386cd58f50 100644 (file)
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #endif /* _WIN32 */
 
 #include <stdio.h>
index 0f0ef0aeec410c8190ccb4ee3133faf854189c26..550a2203c83c3366b9497dc433872fe11a95f354 100644 (file)
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #endif /* _WIN32 */
 
 #include <ctype.h>
index 49011de2190006fd2217423b650b7ac537b3b489..f0ad3426ce86cfdf45432946d6176ff309374257 100644 (file)
--- a/gencode.c
+++ b/gencode.c
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
 #else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #include <sys/socket.h>
 #endif /* _WIN32 */
 
index 21c9cd97b1a362b42036d041e16e10c172e16460..4d5834e5843a75c2c038624c724c32db6b7fc26f 100644 (file)
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #endif /* _WIN32 */
 
 #include <stdio.h>
index 8a34ec858a7503c598f553983922bf723b533564..5fa9b7e5fd86ae0971d0678dabeaa36d49435559 100644 (file)
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #endif /* _WIN32 */
 
 #include "pcap-int.h"
index a1be680988650ae4b3f4528629cfbaa8381768a8..9ea1f681bdb15de7bf385a34d9925d15bb2977dd 100644 (file)
 
 #include <ws2tcpip.h>
 
-#if defined(_MSC_VER)
-  /*
-   * MSVC.
-   */
-  #if _MSC_VER >= 1800
-    /*
-     * VS 2013 or newer; we have <inttypes.h>.
-     */
-    #include <inttypes.h>
-
-    #define u_int8_t uint8_t
-    #define u_int16_t uint16_t
-    #define u_int32_t uint32_t
-    #define u_int64_t uint64_t
-  #else
-    /*
-     * Earlier VS; we have to define this stuff ourselves.
-     */
-    #ifndef HAVE_U_INT8_T
-      typedef unsigned char u_int8_t;
-      typedef signed char int8_t;
-    #endif
-
-    #ifndef HAVE_U_INT16_T
-      typedef unsigned short u_int16_t;
-      typedef signed short int16_t;
-    #endif
-
-    #ifndef HAVE_U_INT32_T
-      typedef unsigned int u_int32_t;
-      typedef signed int int32_t;
-    #endif
-
-    #ifndef HAVE_U_INT64_T
-      #ifdef _MSC_EXTENSIONS
-        typedef unsigned _int64 u_int64_t;
-        typedef _int64 int64_t;
-      #else /* _MSC_EXTENSIONS */
-        typedef unsigned long long u_int64_t;
-        typedef long long int64_t;
-      #endif
-    #endif
-  #endif
-#elif defined(__MINGW32__)
-  #include <stdint.h>
-#endif
+#include <pcap-types.h>
 
 #endif /* pcap_stdinc_h */
diff --git a/pcap-types.h b/pcap-types.h
new file mode 100644 (file)
index 0000000..7c318d0
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
+ * Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Politecnico di Torino nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef pcap_types_h
+#define pcap_types_h
+
+/*
+ * Get the integer types we use defined, by hook or by crook.
+ */
+#if defined(_MSC_VER)
+  /*
+   * Target is Windows, compiler is MSVC.
+   */
+  #if _MSC_VER >= 1800
+    /*
+     * VS 2013 or newer; we have <inttypes.h>.
+     */
+    #include <inttypes.h>
+
+    #define u_int8_t uint8_t
+    #define u_int16_t uint16_t
+    #define u_int32_t uint32_t
+    #define u_int64_t uint64_t
+  #else
+    /*
+     * Earlier VS; we have to define this stuff ourselves.
+     */
+    #ifndef HAVE_U_INT8_T
+      typedef unsigned char u_int8_t;
+      typedef signed char int8_t;
+    #endif
+
+    #ifndef HAVE_U_INT16_T
+      typedef unsigned short u_int16_t;
+      typedef signed short int16_t;
+    #endif
+
+    #ifndef HAVE_U_INT32_T
+      typedef unsigned int u_int32_t;
+      typedef signed int int32_t;
+    #endif
+
+    #ifndef HAVE_U_INT64_T
+      #ifdef _MSC_EXTENSIONS
+        typedef unsigned _int64 u_int64_t;
+        typedef _int64 int64_t;
+      #else /* _MSC_EXTENSIONS */
+        typedef unsigned long long u_int64_t;
+        typedef long long int64_t;
+      #endif
+    #endif
+  #endif
+#elif defined(__MINGW32__)
+  /*
+   * Target is Windows, compiler is MinGW.
+   */
+  #include <stdint.h>
+#elif !defined(_WIN32)
+  /*
+   * Target is UN*X or MS-DOS.
+   */
+  #if HAVE_INTTYPES_H
+    #include <inttypes.h>
+  #elif HAVE_STDINT_H
+    #include <stdint.h>
+  #endif
+  #ifdef HAVE_SYS_BITYPES_H
+    #include <sys/bitypes.h>
+  #endif
+  #include <sys/types.h>
+#endif
+
+#endif /* pcap_types_h */
diff --git a/pcap.c b/pcap.c
index 2957f9120014500926d1eec093b45b8e11dbb984..98e06e5ba2f6761ebcab01cd0da4ae9b98d94bbc 100644 (file)
--- a/pcap.c
+++ b/pcap.c
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
 #else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
 #include <sys/param.h>
-#include <sys/types.h>
 #ifndef MSDOS
 #include <sys/file.h>
 #endif
index 695d7a20a831ef9fc1dcb941ac05df3da2f8c6c2..4dd8f54575fa6e01c1be040c49b129140aa0208c 100644 (file)
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #endif /* _WIN32 */
 
 #include <errno.h>
index 346eb0708d89984de5cad7cb02e972d85ef3c9d6..befcfdfd3d46be23190a4393f1f2a7dbc1caa228 100644 (file)
--- a/scanner.l
+++ b/scanner.l
@@ -3,6 +3,25 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+
+/*
+ * Must come first to avoid warnings on Windows.
+ *
+ * Flex-generated scanners may only include <inttypes.h> if __STDC_VERSION__
+ * is defined with a value >= 199901, meaning "full C99", and MSVC may not
+ * define it with that value, because it isn't 100% C99-compliant, even
+ * though it has an <inttypes.h> capable of defining everything the Flex
+ * scanner needs.
+ *
+ * We, however, will include it if we know we have an MSVC version that has
+ * it; this means that we may define the INTn_MAX and UINTn_MAX values in
+ * scanner.c, and then include <stdint.h>, which may define them differently
+ * (same value, but different string of characters), causing compiler warnings.
+ *
+ * If we include it here, and they're defined, that'll prevent scanner.c
+ * from defining them.
+ */
+#include <pcap-types.h>
 }
 
 /*
 
 #ifdef _WIN32
   #include <pcap-stdinc.h>
-#else
-  #if HAVE_INTTYPES_H
-    #include <inttypes.h>
-  #elif HAVE_STDINT_H
-    #include <stdint.h>
-  #endif
-  #ifdef HAVE_SYS_BITYPES_H
-    #include <sys/bitypes.h>
-  #endif
-  #include <sys/types.h>
 #endif
 
 #include <ctype.h>
index 768e96b7803396e2022e876f895bbcd45ce18b9e..639eed538833f2f627a9defd3874451faf60a81a 100644 (file)
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #endif /* _WIN32 */
 
 #include <errno.h>
index d83bb104050c711edca513620655f97349bf1749..8e12826b66c6352e8ced11da2f2ec56685fd3a0d 100644 (file)
--- a/sf-pcap.c
+++ b/sf-pcap.c
 #include <config.h>
 #endif
 
+#include <pcap-types.h>
 #ifdef _WIN32
 #include <pcap-stdinc.h>
-#else /* _WIN32 */
-#if HAVE_INTTYPES_H
-#include <inttypes.h>
-#elif HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_SYS_BITYPES_H
-#include <sys/bitypes.h>
-#endif
-#include <sys/types.h>
 #endif /* _WIN32 */
 
 #include <errno.h>