]>
The Tcpdump Group git mirrors - tcpdump/blob - tcpdump-stdinc.h
2 * Copyright (c) 2002 - 2003
3 * NetGroup, Politecnico di Torino (Italy)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Include the appropriate OS header files on Windows and various flavors
34 * of UNIX, and also define some additional items and include various
35 * non-OS header files on Windows, and; this isolates most of the platform
36 * differences to this one file.
39 #ifndef tcpdump_stdinc_h
40 #define tcpdump_stdinc_h
52 #include <sys/types.h>
53 #include <net/netdb.h> /* in wpcap's Win32/include */
59 #if !defined(__MINGW32__) && !defined(__WATCOMC__)
65 #define O_RDONLY _O_RDONLY
66 #endif /* __MINGW32__ */
72 /* Protos for missing/x.c functions (ideally <missing/addrinfo.h>
73 * should be used, but it clashes with <ws2tcpip.h>).
75 extern const char *inet_ntop (int, const void *, char *, size_t);
76 extern int inet_pton (int, const char *, void *);
77 extern int inet_aton (const char *cp
, struct in_addr
*addr
);
80 * With MSVC, for C, __inline is used to make a function an inline.
83 #define inline __inline
86 #ifndef INET6_ADDRSTRLEN
87 #define INET6_ADDRSTRLEN 46
91 typedef char* caddr_t
;
94 #define MAXHOSTNAMELEN 64
95 #define NI_MAXHOST 1025
96 #define snprintf _snprintf
97 #define vsnprintf _vsnprintf
98 #define RETSIGTYPE void
106 #include <inttypes.h>
110 #include <sys/param.h>
111 #include <sys/types.h> /* concession to AIX */
112 #include <sys/time.h>
113 #include <sys/socket.h>
114 #include <netinet/in.h>
116 #ifdef TIME_WITH_SYS_TIME
120 #include <arpa/inet.h>
124 #ifndef HAVE___ATTRIBUTE__
125 #define __attribute__(x)
129 * Used to declare a structure unaligned, so that the C compiler,
130 * if necessary, generates code that doesn't assume alignment.
131 * This is required because there is no guarantee that the packet
132 * data we get from libpcap/WinPcap is properly aligned.
134 * This assumes that, for all compilers that support __attribute__:
136 * 1) they support __attribute__((packed));
138 * 2) for all instruction set architectures requiring strict
139 * alignment, declaring a structure with that attribute
140 * causes the compiler to generate code that handles
141 * misaligned 2-byte, 4-byte, and 8-byte integral
144 * It does not (yet) handle compilers where you can get the compiler
145 * to generate code of that sort by some other means.
147 * This is required in order to, for example, keep the compiler from
150 * if (bp->bp_htype == 1 && bp->bp_hlen == 6 && bp->bp_op == BOOTPREQUEST) {
152 * in print-bootp.c, code that loads the first 4-byte word of a
153 * "struct bootp", masking out the bp_hops field, and comparing the result
154 * against 0x01010600.
156 * Note: this also requires that padding be put into the structure,
157 * at least for compilers where it's implemented as __attribute__((packed)).
159 #if defined(_MSC_VER) && defined(UNALIGNED)
160 /* MSVC may have its own macro defined with the same name and purpose. */
162 #define UNALIGNED __attribute__((packed))
165 #if defined(WIN32) || defined(MSDOS)
166 #define FOPEN_READ_TXT "rt"
167 #define FOPEN_READ_BIN "rb"
168 #define FOPEN_WRITE_TXT "wt"
169 #define FOPEN_WRITE_BIN "wb"
171 #define FOPEN_READ_TXT "r"
172 #define FOPEN_READ_BIN FOPEN_READ_TXT
173 #define FOPEN_WRITE_TXT "w"
174 #define FOPEN_WRITE_BIN FOPEN_WRITE_TXT
177 #if defined(__GNUC__) && defined(__i386__) && !defined(__APPLE__) && !defined(__ntohl)
183 static __inline__
unsigned long __ntohl (unsigned long x
);
184 static __inline__
unsigned short __ntohs (unsigned short x
);
186 #define ntohl(x) __ntohl(x)
187 #define ntohs(x) __ntohs(x)
188 #define htonl(x) __ntohl(x)
189 #define htons(x) __ntohs(x)
191 static __inline__
unsigned long __ntohl (unsigned long x
)
193 __asm__ ("xchgb %b0, %h0\n\t" /* swap lower bytes */
194 "rorl $16, %0\n\t" /* swap words */
195 "xchgb %b0, %h0" /* swap higher bytes */
196 : "=q" (x
) : "0" (x
));
200 static __inline__
unsigned short __ntohs (unsigned short x
)
202 __asm__ ("xchgb %b0, %h0" /* swap bytes */
203 : "=q" (x
) : "0" (x
));
208 #ifndef INET_ADDRSTRLEN
209 #define INET_ADDRSTRLEN 16
221 * The Apple deprecation workaround macros below were adopted from the
222 * FreeRADIUS server code under permission of Alan DeKok and Arran Cudbard-Bell.
225 #define XSTRINGIFY(x) #x
228 * Macros for controlling warnings in GCC >= 4.2 and clang >= 2.8
230 #define DIAG_JOINSTR(x,y) XSTRINGIFY(x ## y)
231 #define DIAG_DO_PRAGMA(x) _Pragma (#x)
233 #if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
234 # define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(GCC diagnostic x)
235 # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
236 # define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
237 # define DIAG_ON(x) DIAG_PRAGMA(pop)
239 # define DIAG_OFF(x) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
240 # define DIAG_ON(x) DIAG_PRAGMA(warning DIAG_JOINSTR(-W,x))
242 #elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__ >= 208)
243 # define DIAG_PRAGMA(x) DIAG_DO_PRAGMA(clang diagnostic x)
244 # define DIAG_OFF(x) DIAG_PRAGMA(push) DIAG_PRAGMA(ignored DIAG_JOINSTR(-W,x))
245 # define DIAG_ON(x) DIAG_PRAGMA(pop)
252 * For dealing with APIs which are only deprecated in OSX (like the OpenSSL API)
255 # define USES_APPLE_DEPRECATED_API DIAG_OFF(deprecated-declarations)
256 # define USES_APPLE_RST DIAG_ON(deprecated-declarations)
258 # define USES_APPLE_DEPRECATED_API
259 # define USES_APPLE_RST
263 * end of Apple deprecation workaround macros
267 #define min(a,b) ((a)>(b)?(b):(a))
270 #define max(a,b) ((b)>(a)?(b):(a))
273 #endif /* tcpdump_stdinc_h */