]> The Tcpdump Group git mirrors - tcpdump/blob - tcpdump-stdinc.h
bugfix: don't forget to increment the tlv header size, misc. display cosmetics
[tcpdump] / tcpdump-stdinc.h
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 2005-03-27 01:35:45 guy 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 "bittypes.h"
50 #include <ctype.h>
51 #include <time.h>
52 #include <io.h>
53 #include "IP6_misc.h"
54 #include <fcntl.h>
55 #include <sys/types.h>
56 #include <net/netdb.h> /* in wpcap's Win32/include */
57
58 #ifdef __MINGW32__
59 #include <stdint.h>
60 #endif
61
62 /* Protos for missing/x.c functions (ideally <missing/addrinfo.h>
63 * should be used, but it clashes with <ws2tcpip.h>).
64 */
65 extern const char *inet_ntop (int, const void *, char *, size_t);
66 extern int inet_pton (int, const char *, void *);
67 extern int inet_aton (const char *cp, struct in_addr *addr);
68
69 #ifndef INET6_ADDRSTRLEN
70 #define INET6_ADDRSTRLEN 46
71 #endif
72
73 #ifndef toascii
74 #define toascii(c) ((c) & 0x7f)
75 #endif
76
77 #ifndef caddr_t
78 typedef char* caddr_t;
79 #endif /* caddr_t */
80
81 #define MAXHOSTNAMELEN 64
82 #define NI_MAXHOST 1025
83 #define snprintf _snprintf
84 #define vsnprintf _vsnprintf
85 #define RETSIGTYPE void
86
87 #else /* WIN32 */
88
89 #include <ctype.h>
90 #include <unistd.h>
91 #include <netdb.h>
92 #ifdef INTTYPES_H_DEFINES_FORMATS
93 #include <inttypes.h>
94 #endif
95 #include <sys/param.h>
96 #include <sys/types.h> /* concession to AIX */
97 #include <sys/time.h>
98 #include <sys/socket.h>
99 #include <netinet/in.h>
100
101 #ifdef TIME_WITH_SYS_TIME
102 #include <time.h>
103 #endif
104
105 #include <arpa/inet.h>
106
107 #endif /* WIN32 */
108
109 #ifdef INET6
110 #include "ip6.h"
111 #endif
112
113 #if defined(WIN32) || defined(MSDOS)
114 #define FOPEN_READ_TXT "rt"
115 #define FOPEN_READ_BIN "rb"
116 #define FOPEN_WRITE_TXT "wt"
117 #define FOPEN_WRITE_BIN "wb"
118 #else
119 #define FOPEN_READ_TXT "r"
120 #define FOPEN_READ_BIN FOPEN_READ_TXT
121 #define FOPEN_WRITE_TXT "w"
122 #define FOPEN_WRITE_BIN FOPEN_WRITE_TXT
123 #endif
124
125 #if defined(__GNUC__) && defined(__i386__)
126 #undef ntohl
127 #undef ntohs
128 #undef htonl
129 #undef htons
130
131 extern __inline__ unsigned long __ntohl (unsigned long x);
132 extern __inline__ unsigned short __ntohs (unsigned short x);
133
134 #define ntohl(x) __ntohl(x)
135 #define ntohs(x) __ntohs(x)
136 #define htonl(x) __ntohl(x)
137 #define htons(x) __ntohs(x)
138
139 extern __inline__ unsigned long __ntohl (unsigned long x)
140 {
141 __asm__ ("xchgb %b0, %h0\n\t" /* swap lower bytes */
142 "rorl $16, %0\n\t" /* swap words */
143 "xchgb %b0, %h0" /* swap higher bytes */
144 : "=q" (x) : "0" (x));
145 return (x);
146 }
147
148 extern __inline__ unsigned short __ntohs (unsigned short x)
149 {
150 __asm__ ("xchgb %b0, %h0" /* swap bytes */
151 : "=q" (x) : "0" (x));
152 return (x);
153 }
154 #endif
155
156 #ifndef INET_ADDRSTRLEN
157 #define INET_ADDRSTRLEN 16
158 #endif
159
160 #endif /* tcpdump_stdinc_h */