Move tcpdump-3.9/ to tcpdump/. No need for a versioned dir.
[dragonfly.git] / contrib / tcpdump / tcpdump-stdinc.h
CommitLineData
c8cf0f94
PA
1/*
2 * Copyright (c) 2002 - 2003
3 * NetGroup, Politecnico di Torino (Italy)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
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.
18 *
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.
30 *
31 *
32 * @(#) $Header: /tcpdump/master/tcpdump/tcpdump-stdinc.h,v 1.12.2.5 2006/06/23 02:07:27 hannes Exp $ (LBL)
33 */
34
35/*
36 * Include the appropriate OS header files on Windows and various flavors
37 * of UNIX, and also define some additional items and include various
38 * non-OS header files on Windows, and; this isolates most of the platform
39 * differences to this one file.
40 */
41
42#ifndef tcpdump_stdinc_h
43#define tcpdump_stdinc_h
44
45#ifdef WIN32
46
47#include <stdio.h>
48#include <winsock2.h>
49#include <Ws2tcpip.h>
50#include "bittypes.h"
51#include <ctype.h>
52#include <time.h>
53#include <io.h>
54#include <fcntl.h>
55#include <sys/types.h>
56#include <net/netdb.h> /* in wpcap's Win32/include */
57
58#if !defined(__MINGW32__) && !defined(__WATCOMC__)
59#undef toascii
60#define isascii __isascii
61#define toascii __toascii
62#define stat _stat
63#define open _open
64#define fstat _fstat
65#define read _read
66#define close _close
67#define O_RDONLY _O_RDONLY
68
69typedef short ino_t;
70#endif /* __MINGW32__ */
71
72#ifdef __MINGW32__
73#include <stdint.h>
74#endif
75
76/* Protos for missing/x.c functions (ideally <missing/addrinfo.h>
77 * should be used, but it clashes with <ws2tcpip.h>).
78 */
79extern const char *inet_ntop (int, const void *, char *, size_t);
80extern int inet_pton (int, const char *, void *);
81extern int inet_aton (const char *cp, struct in_addr *addr);
82
83#ifndef INET6_ADDRSTRLEN
84#define INET6_ADDRSTRLEN 46
85#endif
86
87#ifndef toascii
88#define toascii(c) ((c) & 0x7f)
89#endif
90
91#ifndef caddr_t
92typedef char* caddr_t;
93#endif /* caddr_t */
94
95#define MAXHOSTNAMELEN 64
96#define NI_MAXHOST 1025
97#define snprintf _snprintf
98#define vsnprintf _vsnprintf
99#define RETSIGTYPE void
100
101#else /* WIN32 */
102
103#include <ctype.h>
104#include <unistd.h>
105#include <netdb.h>
106#if HAVE_INTTYPES_H
107#include <inttypes.h>
108#else
109#if HAVE_STDINT_H
110#include <stdint.h>
111#endif
112#endif
113#ifdef HAVE_SYS_BITYPES_H
114#include <sys/bitypes.h>
115#endif
116#include <sys/param.h>
117#include <sys/types.h> /* concession to AIX */
118#include <sys/time.h>
119#include <sys/socket.h>
120#include <netinet/in.h>
121
122#ifdef TIME_WITH_SYS_TIME
123#include <time.h>
124#endif
125
126#include <arpa/inet.h>
127
128#endif /* WIN32 */
129
130#ifdef INET6
131#include "ip6.h"
132#endif
133
134#if defined(WIN32) || defined(MSDOS)
135 #define FOPEN_READ_TXT "rt"
136 #define FOPEN_READ_BIN "rb"
137 #define FOPEN_WRITE_TXT "wt"
138 #define FOPEN_WRITE_BIN "wb"
139#else
140 #define FOPEN_READ_TXT "r"
141 #define FOPEN_READ_BIN FOPEN_READ_TXT
142 #define FOPEN_WRITE_TXT "w"
143 #define FOPEN_WRITE_BIN FOPEN_WRITE_TXT
144#endif
145
146#if defined(__GNUC__) && defined(__i386__) && !defined(__ntohl)
147 #undef ntohl
148 #undef ntohs
149 #undef htonl
150 #undef htons
151
152 extern __inline__ unsigned long __ntohl (unsigned long x);
153 extern __inline__ unsigned short __ntohs (unsigned short x);
154
155 #define ntohl(x) __ntohl(x)
156 #define ntohs(x) __ntohs(x)
157 #define htonl(x) __ntohl(x)
158 #define htons(x) __ntohs(x)
159
160 extern __inline__ unsigned long __ntohl (unsigned long x)
161 {
162 __asm__ ("xchgb %b0, %h0\n\t" /* swap lower bytes */
163 "rorl $16, %0\n\t" /* swap words */
164 "xchgb %b0, %h0" /* swap higher bytes */
165 : "=q" (x) : "0" (x));
166 return (x);
167 }
168
169 extern __inline__ unsigned short __ntohs (unsigned short x)
170 {
171 __asm__ ("xchgb %b0, %h0" /* swap bytes */
172 : "=q" (x) : "0" (x));
173 return (x);
174 }
175#endif
176
177#ifndef INET_ADDRSTRLEN
178#define INET_ADDRSTRLEN 16
179#endif
180
181#ifndef TRUE
182#define TRUE 1
183#endif
184
185#ifndef FALSE
186#define FALSE 0
187#endif
188
189#endif /* tcpdump_stdinc_h */