]> The Tcpdump Group git mirrors - tcpdump/blobdiff - netdissect-stdinc.h
Avoiding conditional directives that break statements
[tcpdump] / netdissect-stdinc.h
old mode 100644 (file)
new mode 100755 (executable)
index 093fc09..e201afa
 
 #ifdef _WIN32
 
+/*
+ * Includes and definitions for Windows.
+ */
+
 #include <stdint.h>
 #include <stdio.h>
 #include <winsock2.h>
 #include <ws2tcpip.h>
-#include "bittypes.h"   /* in wpcap's Win32/include */
 #include <ctype.h>
 #include <time.h>
 #include <io.h>
 #include <fcntl.h>
 #include <sys/types.h>
-#include <net/netdb.h>  /* in wpcap's Win32/include */
 
 #ifndef uint8_t
 #define uint8_t                unsigned char
 
 #endif /* _MSC_EXTENSIONS */
 
+/*
+ * Suppress definition of intN_t in bittypes.h, as included by <pcap/pcap.h>
+ * on Windows.
+ * (Yes, HAVE_U_INTn_T, as the definition guards are UN*X-oriented, and
+ * we check for u_intN_t in the UN*X configure script.)
+ */
+#define HAVE_U_INT8_T
+#define HAVE_U_INT16_T
+#define HAVE_U_INT32_T
+#define HAVE_U_INT64_T
+
 #ifdef _MSC_VER
 #define stat _stat
 #define open _open
 #define O_RDONLY _O_RDONLY
 #endif  /* _MSC_VER */
 
-/* Protos for missing/x.c functions (ideally <missing/addrinfo.h>
- * should be used, but it clashes with <ws2tcpip.h>).
- */
-extern const char *inet_ntop (int, const void *, char *, size_t);
-extern int inet_pton (int, const char *, void *);
-extern int inet_aton (const char *cp, struct in_addr *addr);
-
 /*
  * With MSVC, for C, __inline is used to make a function an inline.
  */
@@ -156,6 +162,10 @@ extern int inet_aton (const char *cp, struct in_addr *addr);
 #define inline __inline
 #endif
 
+#ifdef AF_INET6
+#define HAVE_OS_IPV6_SUPPORT
+#endif
+
 #ifndef INET6_ADDRSTRLEN
 #define INET6_ADDRSTRLEN 46
 #endif
@@ -171,13 +181,16 @@ typedef char* caddr_t;
 #endif /* caddr_t */
 
 #define MAXHOSTNAMELEN 64
-#define        NI_MAXHOST      1025
 #define snprintf _snprintf
 #define vsnprintf _vsnprintf
 #define RETSIGTYPE void
 
 #else /* _WIN32 */
 
+/*
+ * Includes and definitions for various flavors of UN*X.
+ */
+
 #include <ctype.h>
 #include <unistd.h>
 #include <netdb.h>
@@ -241,6 +254,9 @@ typedef char* caddr_t;
 #define UNALIGNED      __attribute__((packed))
 #endif
 
+/*
+ * fopen() read and write modes for text files and binary files.
+ */
 #if defined(_WIN32) || defined(MSDOS)
   #define FOPEN_READ_TXT   "rt"
   #define FOPEN_READ_BIN   "rb"
@@ -253,6 +269,16 @@ typedef char* caddr_t;
   #define FOPEN_WRITE_BIN  FOPEN_WRITE_TXT
 #endif
 
+/*
+ * Inline x86 assembler-language versions of ntoh[ls]() and hton[ls](),
+ * defined if the OS doesn't provide them.  These assume no more than
+ * an 80386, so, for example, it avoids the bswap instruction added in
+ * the 80486.
+ *
+ * (We don't use them on OS X; Apple provides their own, which *doesn't*
+ * avoid the bswap instruction, as OS X only supports machines that
+ * have it.)
+ */
 #if defined(__GNUC__) && defined(__i386__) && !defined(__APPLE__) && !defined(__ntohl)
   #undef ntohl
   #undef ntohs
@@ -284,6 +310,30 @@ typedef char* caddr_t;
   }
 #endif
 
+/*
+ * If the OS doesn't define AF_INET6 and struct in6_addr:
+ *
+ * define AF_INET6, so we can use it internally as a "this is an
+ * IPv6 address" indication;
+ *
+ * define struct in6_addr so that we can use it for IPv6 addresses.
+ */
+#ifndef HAVE_OS_IPV6_SUPPORT
+#define AF_INET6       24
+
+struct in6_addr {
+       union {
+               __uint8_t   __u6_addr8[16];
+               __uint16_t  __u6_addr16[8];
+               __uint32_t  __u6_addr32[4];
+       } __u6_addr;                    /* 128-bit IP6 address */
+};
+#endif
+
+#ifndef NI_MAXHOST
+#define        NI_MAXHOST      1025
+#endif
+  
 #ifndef INET_ADDRSTRLEN
 #define INET_ADDRSTRLEN 16
 #endif