X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/3c4027f5993cf8def131e56b98d1c137be1b1f72..03b1b422b15d19c723d228c74d444127abba38be:/tcpdump-stdinc.h diff --git a/tcpdump-stdinc.h b/tcpdump-stdinc.h index 5aba8fdc..eb6c9428 100644 --- a/tcpdump-stdinc.h +++ b/tcpdump-stdinc.h @@ -69,8 +69,6 @@ #define read _read #define close _close #define O_RDONLY _O_RDONLY - -typedef short ino_t; #endif /* __MINGW32__ */ #ifdef __MINGW32__ @@ -84,6 +82,13 @@ 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. + */ +#ifdef _MSC_VER +#define inline __inline +#endif + #ifndef INET6_ADDRSTRLEN #define INET6_ADDRSTRLEN 46 #endif @@ -131,8 +136,45 @@ typedef char* caddr_t; #endif /* WIN32 */ -#ifdef INET6 -#include "ip6.h" +#ifndef HAVE___ATTRIBUTE__ +#define __attribute__(x) +#endif + +/* + * Used to declare a structure unaligned, so that the C compiler, + * if necessary, generates code that doesn't assume alignment. + * This is required because there is no guarantee that the packet + * data we get from libpcap/WinPcap is properly aligned. + * + * This assumes that, for all compilers that support __attribute__: + * + * 1) they support __attribute__((packed)); + * + * 2) for all instruction set architectures requiring strict + * alignment, declaring a structure with that attribute + * causes the compiler to generate code that handles + * misaligned 2-byte, 4-byte, and 8-byte integral + * quantities. + * + * It does not (yet) handle compilers where you can get the compiler + * to generate code of that sort by some other means. + * + * This is required in order to, for example, keep the compiler from + * generating, for + * + * if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) { + * + * in print-bootp.c, code that loads the first 4-byte word of a + * "struct bootp", masking out the bp_hops field, and comparing the result + * against 0x01010600. + * + * Note: this also requires that padding be put into the structure, + * at least for compilers where it's implemented as __attribute__((packed)). + */ +#if defined(_MSC_VER) && defined(UNALIGNED) +/* MSVC may have its own macro defined with the same name and purpose. */ +#else +#define UNALIGNED __attribute__((packed)) #endif #if defined(WIN32) || defined(MSDOS)