6c9d6754369a55e43cb4eaeb4ec6b32c7f70a536
[tinc] / src / have.h
1 #ifndef TINC_HAVE_H
2 #define TINC_HAVE_H
3
4 /*
5     have.h -- include headers which are known to exist
6     Copyright (C) 1998-2005 Ivo Timmermans
7                   2003-2021 Guus Sliepen <guus@tinc-vpn.org>
8
9     This program is free software; you can redistribute it and/or modify
10     it under the terms of the GNU General Public License as published by
11     the Free Software Foundation; either version 2 of the License, or
12     (at your option) any later version.
13
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18
19     You should have received a copy of the GNU General Public License along
20     with this program; if not, write to the Free Software Foundation, Inc.,
21     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 #ifdef HAVE_WINDOWS
25 #define WINVER 0x0600
26 #define _WIN32_WINNT 0x0600
27 #define WIN32_LEAN_AND_MEAN
28 #define _CRT_SECURE_NO_WARNINGS
29 #define _CRT_NONSTDC_NO_WARNINGS
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <stdbool.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <signal.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #ifdef HAVE_UNISTD_H
42 #include <unistd.h>
43 #endif
44 #include <limits.h>
45 #include <math.h>
46 #include <time.h>
47
48 #ifdef HAVE_STATIC_ASSERT
49 #define STATIC_ASSERT(expr, msg) _Static_assert((expr), msg)
50 #else
51 #define STATIC_ASSERT(check, msg)
52 #endif
53
54 #ifdef HAVE_ATTR_PACKED
55 #define PACKED(...) __VA_ARGS__ __attribute__((__packed__))
56 #else
57 #ifdef _MSC_VER
58 #define PACKED(...) __pragma(pack(push, 1)) __VA_ARGS__ __pragma(pack(pop))
59 #else
60 #warning Your compiler does not support __packed__. Use at your own risk.
61 #endif
62 #endif
63
64 #ifdef HAVE_ATTR_MALLOC
65 #define ATTR_MALLOC __attribute__((__malloc__))
66 #else
67 #define ATTR_MALLOC
68 #endif
69
70 #ifdef HAVE_ATTR_NONNULL
71 #define ATTR_NONNULL __attribute__((__nonnull__))
72 #else
73 #define ATTR_NONNULL
74 #endif
75
76 #ifdef HAVE_ATTR_WARN_UNUSED_RESULT
77 #define ATTR_WARN_UNUSED __attribute__((__warn_unused_result__))
78 #else
79 #define ATTR_WARN_UNUSED
80 #endif
81
82 #ifdef HAVE_ATTR_FORMAT
83 #define ATTR_FORMAT(func, str, nonstr) __attribute__((format(func, str, nonstr)))
84 #else
85 #define ATTR_FORMAT(func, str, nonstr)
86 #endif
87
88 #ifdef HAVE_ALLOCA_H
89 #include <alloca.h>
90 #elif defined(HAVE_NETBSD)
91 #define alloca(size) __builtin_alloca(size)
92 #endif
93
94 #ifdef HAVE_WINDOWS
95 #ifdef HAVE_W32API_H
96 #include <w32api.h>
97 #endif
98
99 #include <winsock2.h>
100 #include <windows.h>
101 #include <ws2tcpip.h>
102
103 #ifdef _MSC_VER
104 #include <io.h>
105 #include <process.h>
106 #include <direct.h>
107 #endif
108 #endif // HAVE_WINDOWS
109
110 #ifdef HAVE_TERMIOS_H
111 #include <termios.h>
112 #endif
113
114 #ifdef HAVE_INTTYPES_H
115 #include <inttypes.h>
116 #endif
117
118 /* Include system specific headers */
119
120 #ifdef HAVE_STDDEF_H
121 #include <stddef.h>
122 #endif
123
124 #ifdef HAVE_SYSLOG_H
125 #include <syslog.h>
126 #endif
127
128 #ifdef HAVE_SYS_RANDOM_H
129 #include <sys/random.h>
130 #endif
131
132 #ifdef HAVE_SYS_TIME_H
133 #include <sys/time.h>
134 #endif
135
136 #ifdef HAVE_SYS_TYPES_H
137 #include <sys/types.h>
138 #endif
139
140 #ifdef HAVE_SYS_STAT_H
141 #include <sys/stat.h>
142 #endif
143
144 #ifdef HAVE_SYS_FILE_H
145 #include <sys/file.h>
146 #endif
147
148 #ifdef HAVE_SYS_MMAN_H
149 #include <sys/mman.h>
150 #endif
151
152 #ifdef HAVE_SYS_WAIT_H
153 #include <sys/wait.h>
154 #endif
155
156 #ifdef HAVE_SYS_IOCTL_H
157 #include <sys/ioctl.h>
158 #endif
159
160 #ifdef HAVE_SYS_PARAM_H
161 #include <sys/param.h>
162 #endif
163
164 #ifdef HAVE_SYS_RESOURCE_H
165 #include <sys/resource.h>
166 #endif
167
168 #ifdef HAVE_SYS_UN_H
169 #include <sys/un.h>
170 #endif
171
172 #ifdef HAVE_DIRENT_H
173 #include <dirent.h>
174 #elif defined(_MSC_VER)
175 #include "dirent.h"
176 #endif
177
178 /* SunOS really wants sys/socket.h BEFORE net/if.h,
179    and FreeBSD wants these lines below the rest. */
180
181 #ifdef HAVE_NETDB_H
182 #include <netdb.h>
183 #endif
184
185 #ifdef HAVE_SYS_SOCKET_H
186 #include <sys/socket.h>
187 #endif
188
189 #ifdef HAVE_NET_IF_H
190 #include <net/if.h>
191 #endif
192
193 #ifdef HAVE_NET_IF_TYPES_H
194 #include <net/if_types.h>
195 #endif
196
197 #ifdef HAVE_NET_IF_TUN_H
198 #include <net/if_tun.h>
199 #endif
200
201 #ifdef HAVE_NET_TUN_IF_TUN_H
202 #include <net/tun/if_tun.h>
203 #endif
204
205 #ifdef HAVE_NET_IF_TAP_H
206 #include <net/if_tap.h>
207 #endif
208
209 #ifdef HAVE_NET_TAP_IF_TAP_H
210 #include <net/tap/if_tap.h>
211 #endif
212
213 #ifdef HAVE_NETINET_IN_SYSTM_H
214 #include <netinet/in_systm.h>
215 #endif
216
217 #ifdef HAVE_NETINET_IN_H
218 #include <netinet/in.h>
219 #endif
220
221 #ifdef HAVE_ARPA_INET_H
222 #include <arpa/inet.h>
223 #endif
224
225 #ifdef HAVE_NETINET_IP_H
226 #include <netinet/ip.h>
227 #endif
228
229 #ifdef HAVE_NETINET_TCP_H
230 #include <netinet/tcp.h>
231 #endif
232
233 #ifdef HAVE_NETINET_IN6_H
234 #include <netinet/in6.h>
235 #endif
236
237 #ifdef HAVE_NETINET_IP6_H
238 #include <netinet/ip6.h>
239 #endif
240
241 #ifdef HAVE_NET_ETHERNET_H
242 #include <net/ethernet.h>
243 #endif
244
245 #ifdef HAVE_NET_IF_ARP_H
246 #include <net/if_arp.h>
247 #endif
248
249 #ifdef HAVE_NETINET_IP_ICMP_H
250 #include <netinet/ip_icmp.h>
251 #endif
252
253 #ifdef HAVE_NETINET_ICMP6_H
254 #include <netinet/icmp6.h>
255 #endif
256
257 #ifdef HAVE_NETINET_IF_ETHER_H
258 #include <netinet/if_ether.h>
259 #endif
260
261 #ifdef HAVE_ARPA_NAMESER_H
262 #include <arpa/nameser.h>
263 #endif
264
265 #ifdef HAVE_RESOLV_H
266 #include <resolv.h>
267 #endif
268
269 #ifdef HAVE_LINUX_IF_TUN_H
270 #include <linux/if_tun.h>
271 #endif
272
273 #ifdef HAVE_GETOPT_H
274 #include <getopt.h>
275 #else
276 #include "getopt.h"
277 #endif
278
279 #ifdef STATUS
280 #undef STATUS
281 #endif
282
283 #ifdef HAVE_WINDOWS
284 #define SLASH "\\"
285 #else
286 #define SLASH "/"
287 #endif
288
289 #endif