aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-12-18 08:31:51 -0800
committerGuy Harris <guy@alum.mit.edu>2019-12-18 08:31:51 -0800
commit0103d2880a8f6e78fe001fe35f8be958eeda81eb (patch)
treee33f0c41ff67c2811c7713668bbdba8fd6ea3175
parente0c3bfb4d609b3505ee1f0040e902f019270793d (diff)
Work around for bogus definition of _MSC_VER with non-MS compilers.
Try to work around software using pcap that defines _MSC_VER with non-MS compilers before including pcap.h. We expect _MSC_VER to be defined only for Microsoft's compiler, and to be defined with a value that reflects what version of the compiler is being used, so that we can determine, among other things, what Microsoft extensions are available. Try to detect it being defined by other software that wants to trick us into thinking something's being compiled with Microsoft's compiler, and undo the definition of _MSC_VER.
-rw-r--r--pcap/pcap.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/pcap/pcap.h b/pcap/pcap.h
index d2b1ae1b..e738c762 100644
--- a/pcap/pcap.h
+++ b/pcap/pcap.h
@@ -69,6 +69,49 @@
#ifndef lib_pcap_pcap_h
#define lib_pcap_pcap_h
+/*
+ * Some software that uses libpcap/WinPcap/Npcap defines _MSC_VER before
+ * includeing pcap.h if it's not defined - and it defines it to 1500.
+ * (I'm looking at *you*, lwIP!)
+ *
+ * Attempt to detect this, and undefine _MSC_VER so that we can *reliably*
+ * use it to know what compiler is being used and, if it's Visual Studio,
+ * what version is being used.
+ */
+#if defined(_MSC_VER)
+ /*
+ * We assume here that software such as that doesn't define _MSC_FULL_VER
+ * as well and that it defines _MSC_VER with a value > 1200.
+ *
+ * DO NOT BREAK THESE ASSUMPTIONS. IF YOU FEEL YOU MUST DEFINE _MSC_VER
+ * WITH A COMPILER THAT'S NOT MICROSOFT'S C COMPILER, PLEASE CONTACT
+ * US SO THAT WE CAN MAKE IT SO THAT YOU DON'T HAVE TO DO THAT. THANK
+ * YOU.
+ *
+ * OK, is _MSC_FULL_VER defined?
+ */
+ #if !defined(_MSC_FULL_VER)
+ /*
+ * According to
+ *
+ * https://sourceforge.net/p/predef/wiki/Compilers/
+ *
+ * with "Visual C++ 6.0 Processor Pack"/Visual C++ 6.0 SP6 and
+ * later, _MSC_FULL_VER is defined, so either this is an older
+ * version of Visual C++ or it's not Visual C++ at all.
+ *
+ * For Visual C++ 6.0, _MSC_VER is defined as 1200.
+ */
+ #if _MSC_VER > 1200
+ /*
+ * If this is Visual C++, _MSC_FULL_VER should be defined, so we
+ * assume this isn't Visual C++, and undo the lie that it is.
+ */
+ #undef _MSC_VER
+ #endif
+ #endif
+#endif
+
#include <pcap/funcattrs.h>
#include <pcap/pcap-inttypes.h>