]> The Tcpdump Group git mirrors - tcpdump/blobdiff - netdissect-stdinc.h
Don't require IPv6 library support in order to support IPv6 addresses.
[tcpdump] / netdissect-stdinc.h
index 093fc0928e881eaf28965c517f4ce38d0dbd954d..449678525ab7a5fe144729a579668aa7d17ce041 100644 (file)
 
 #ifdef _WIN32
 
+/*
+ * Includes and definitions for Windows.
+ */
+
 #include <stdint.h>
 #include <stdio.h>
 #include <winsock2.h>
 #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);
 
 /*
@@ -171,13 +170,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 +243,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 +258,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 +299,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