GitHub CI: update list of container images
[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 #define __STDC_WANT_LIB_EXT1__ 1
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <stdarg.h>
37 #include <stdbool.h>
38 #include <string.h>
39 #include <ctype.h>
40 #include <signal.h>
41 #include <errno.h>
42 #include <fcntl.h>
43 #ifdef HAVE_UNISTD_H
44 #include <unistd.h>
45 #endif
46 #include <limits.h>
47 #include <math.h>
48 #include <time.h>
49
50 #ifdef HAVE_STATIC_ASSERT
51 #define STATIC_ASSERT(expr, msg) _Static_assert((expr), msg)
52 #else
53 #define STATIC_ASSERT(check, msg)
54 #endif
55
56 #ifdef HAVE_ATTR_PACKED
57 #define PACKED(...) __VA_ARGS__ __attribute__((__packed__))
58 #else
59 #ifdef _MSC_VER
60 #define PACKED(...) __pragma(pack(push, 1)) __VA_ARGS__ __pragma(pack(pop))
61 #else
62 #warning Your compiler does not support __packed__. Use at your own risk.
63 #endif
64 #endif
65
66 #if defined(HAVE_ATTR_MALLOC_WITH_ARG)
67 #define ATTR_DEALLOCATOR(dealloc) __attribute__((__malloc__(dealloc)))
68 #else
69 #define ATTR_DEALLOCATOR(dealloc)
70 #endif
71
72 #ifdef HAVE_ATTR_MALLOC
73 #define ATTR_MALLOC __attribute__((__malloc__))
74 #else
75 #define ATTR_MALLOC
76 #endif
77
78 #ifdef HAVE_ATTR_NONNULL
79 #define ATTR_NONNULL __attribute__((__nonnull__))
80 #else
81 #define ATTR_NONNULL
82 #endif
83
84 #ifdef HAVE_ATTR_WARN_UNUSED_RESULT
85 #define ATTR_WARN_UNUSED __attribute__((__warn_unused_result__))
86 #else
87 #define ATTR_WARN_UNUSED
88 #endif
89
90 #ifdef HAVE_ATTR_FORMAT
91 #define ATTR_FORMAT(func, str, nonstr) __attribute__((format(func, str, nonstr)))
92 #else
93 #define ATTR_FORMAT(func, str, nonstr)
94 #endif
95
96 #ifdef HAVE_ALLOCA_H
97 #include <alloca.h>
98 #elif defined(HAVE_NETBSD)
99 #define alloca(size) __builtin_alloca(size)
100 #endif
101
102 #ifdef HAVE_WINDOWS
103 #ifdef HAVE_W32API_H
104 #include <w32api.h>
105 #endif
106
107 #include <winsock2.h>
108 #include <windows.h>
109 #include <ws2tcpip.h>
110
111 #ifdef _MSC_VER
112 #include <io.h>
113 #include <process.h>
114 #include <direct.h>
115 #endif
116 #endif // HAVE_WINDOWS
117
118 #ifdef HAVE_TERMIOS_H
119 #include <termios.h>
120 #endif
121
122 #ifdef HAVE_INTTYPES_H
123 #include <inttypes.h>
124 #endif
125
126 /* Include system specific headers */
127
128 #ifdef HAVE_STDDEF_H
129 #include <stddef.h>
130 #endif
131
132 #ifdef HAVE_SYSLOG_H
133 #include <syslog.h>
134 #endif
135
136 #ifdef HAVE_SYS_RANDOM_H
137 #include <sys/random.h>
138 #endif
139
140 #ifdef HAVE_SYS_TIME_H
141 #include <sys/time.h>
142 #endif
143
144 #ifdef HAVE_SYS_TYPES_H
145 #include <sys/types.h>
146 #endif
147
148 #ifdef HAVE_SYS_STAT_H
149 #include <sys/stat.h>
150 #endif
151
152 #ifdef HAVE_SYS_FILE_H
153 #include <sys/file.h>
154 #endif
155
156 #ifdef HAVE_SYS_MMAN_H
157 #include <sys/mman.h>
158 #endif
159
160 #ifdef HAVE_SYS_WAIT_H
161 #include <sys/wait.h>
162 #endif
163
164 #ifdef HAVE_SYS_IOCTL_H
165 #include <sys/ioctl.h>
166 #endif
167
168 #ifdef HAVE_SYS_PARAM_H
169 #include <sys/param.h>
170 #endif
171
172 #ifdef HAVE_SYS_RESOURCE_H
173 #include <sys/resource.h>
174 #endif
175
176 #ifdef HAVE_SYS_UN_H
177 #include <sys/un.h>
178 #endif
179
180 #ifdef HAVE_DIRENT_H
181 #include <dirent.h>
182 #elif defined(_MSC_VER)
183 #include "dirent.h"
184 #endif
185
186 /* SunOS really wants sys/socket.h BEFORE net/if.h,
187    and FreeBSD wants these lines below the rest. */
188
189 #ifdef HAVE_NETDB_H
190 #include <netdb.h>
191 #endif
192
193 #ifdef HAVE_SYS_SOCKET_H
194 #include <sys/socket.h>
195 #endif
196
197 #ifdef HAVE_NET_IF_H
198 #include <net/if.h>
199 #endif
200
201 #ifdef HAVE_NET_IF_TYPES_H
202 #include <net/if_types.h>
203 #endif
204
205 #ifdef HAVE_NET_IF_TUN_H
206 #include <net/if_tun.h>
207 #endif
208
209 #ifdef HAVE_NET_TUN_IF_TUN_H
210 #include <net/tun/if_tun.h>
211 #endif
212
213 #ifdef HAVE_NET_IF_TAP_H
214 #include <net/if_tap.h>
215 #endif
216
217 #ifdef HAVE_NET_TAP_IF_TAP_H
218 #include <net/tap/if_tap.h>
219 #endif
220
221 #ifdef HAVE_NETINET_IN_SYSTM_H
222 #include <netinet/in_systm.h>
223 #endif
224
225 #ifdef HAVE_NETINET_IN_H
226 #include <netinet/in.h>
227 #endif
228
229 #ifdef HAVE_ARPA_INET_H
230 #include <arpa/inet.h>
231 #endif
232
233 #ifdef HAVE_NETINET_IP_H
234 #include <netinet/ip.h>
235 #endif
236
237 #ifdef HAVE_NETINET_TCP_H
238 #include <netinet/tcp.h>
239 #endif
240
241 #ifdef HAVE_NETINET_IN6_H
242 #include <netinet/in6.h>
243 #endif
244
245 #ifdef HAVE_NETINET_IP6_H
246 #include <netinet/ip6.h>
247 #endif
248
249 #ifdef HAVE_NET_ETHERNET_H
250 #include <net/ethernet.h>
251 #endif
252
253 #ifdef HAVE_NET_IF_ARP_H
254 #include <net/if_arp.h>
255 #endif
256
257 #ifdef HAVE_NETINET_IP_ICMP_H
258 #include <netinet/ip_icmp.h>
259 #endif
260
261 #ifdef HAVE_NETINET_ICMP6_H
262 #include <netinet/icmp6.h>
263 #endif
264
265 #ifdef HAVE_NETINET_IF_ETHER_H
266 #include <netinet/if_ether.h>
267 #endif
268
269 #ifdef HAVE_ARPA_NAMESER_H
270 #include <arpa/nameser.h>
271 #endif
272
273 #ifdef HAVE_RESOLV_H
274 #include <resolv.h>
275 #endif
276
277 #ifdef HAVE_LINUX_IF_TUN_H
278 #include <linux/if_tun.h>
279 #endif
280
281 #ifdef HAVE_GETOPT_H
282 #include <getopt.h>
283 #else
284 #include "getopt.h"
285 #endif
286
287 #ifdef STATUS
288 #undef STATUS
289 #endif
290
291 #ifdef HAVE_WINDOWS
292 #define SLASH "\\"
293 #else
294 #define SLASH "/"
295 #endif
296
297 #endif