Wipe (some) secrets from memory after use
[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 #ifdef HAVE_ATTR_MALLOC
67 #define ATTR_MALLOC __attribute__((__malloc__))
68 #else
69 #define ATTR_MALLOC
70 #endif
71
72 #ifdef HAVE_ATTR_NONNULL
73 #define ATTR_NONNULL __attribute__((__nonnull__))
74 #else
75 #define ATTR_NONNULL
76 #endif
77
78 #ifdef HAVE_ATTR_WARN_UNUSED_RESULT
79 #define ATTR_WARN_UNUSED __attribute__((__warn_unused_result__))
80 #else
81 #define ATTR_WARN_UNUSED
82 #endif
83
84 #ifdef HAVE_ATTR_FORMAT
85 #define ATTR_FORMAT(func, str, nonstr) __attribute__((format(func, str, nonstr)))
86 #else
87 #define ATTR_FORMAT(func, str, nonstr)
88 #endif
89
90 #ifdef HAVE_ALLOCA_H
91 #include <alloca.h>
92 #elif defined(HAVE_NETBSD)
93 #define alloca(size) __builtin_alloca(size)
94 #endif
95
96 #ifdef HAVE_WINDOWS
97 #ifdef HAVE_W32API_H
98 #include <w32api.h>
99 #endif
100
101 #include <winsock2.h>
102 #include <windows.h>
103 #include <ws2tcpip.h>
104
105 #ifdef _MSC_VER
106 #include <io.h>
107 #include <process.h>
108 #include <direct.h>
109 #endif
110 #endif // HAVE_WINDOWS
111
112 #ifdef HAVE_TERMIOS_H
113 #include <termios.h>
114 #endif
115
116 #ifdef HAVE_INTTYPES_H
117 #include <inttypes.h>
118 #endif
119
120 /* Include system specific headers */
121
122 #ifdef HAVE_STDDEF_H
123 #include <stddef.h>
124 #endif
125
126 #ifdef HAVE_SYSLOG_H
127 #include <syslog.h>
128 #endif
129
130 #ifdef HAVE_SYS_RANDOM_H
131 #include <sys/random.h>
132 #endif
133
134 #ifdef HAVE_SYS_TIME_H
135 #include <sys/time.h>
136 #endif
137
138 #ifdef HAVE_SYS_TYPES_H
139 #include <sys/types.h>
140 #endif
141
142 #ifdef HAVE_SYS_STAT_H
143 #include <sys/stat.h>
144 #endif
145
146 #ifdef HAVE_SYS_FILE_H
147 #include <sys/file.h>
148 #endif
149
150 #ifdef HAVE_SYS_MMAN_H
151 #include <sys/mman.h>
152 #endif
153
154 #ifdef HAVE_SYS_WAIT_H
155 #include <sys/wait.h>
156 #endif
157
158 #ifdef HAVE_SYS_IOCTL_H
159 #include <sys/ioctl.h>
160 #endif
161
162 #ifdef HAVE_SYS_PARAM_H
163 #include <sys/param.h>
164 #endif
165
166 #ifdef HAVE_SYS_RESOURCE_H
167 #include <sys/resource.h>
168 #endif
169
170 #ifdef HAVE_SYS_UN_H
171 #include <sys/un.h>
172 #endif
173
174 #ifdef HAVE_DIRENT_H
175 #include <dirent.h>
176 #elif defined(_MSC_VER)
177 #include "dirent.h"
178 #endif
179
180 /* SunOS really wants sys/socket.h BEFORE net/if.h,
181    and FreeBSD wants these lines below the rest. */
182
183 #ifdef HAVE_NETDB_H
184 #include <netdb.h>
185 #endif
186
187 #ifdef HAVE_SYS_SOCKET_H
188 #include <sys/socket.h>
189 #endif
190
191 #ifdef HAVE_NET_IF_H
192 #include <net/if.h>
193 #endif
194
195 #ifdef HAVE_NET_IF_TYPES_H
196 #include <net/if_types.h>
197 #endif
198
199 #ifdef HAVE_NET_IF_TUN_H
200 #include <net/if_tun.h>
201 #endif
202
203 #ifdef HAVE_NET_TUN_IF_TUN_H
204 #include <net/tun/if_tun.h>
205 #endif
206
207 #ifdef HAVE_NET_IF_TAP_H
208 #include <net/if_tap.h>
209 #endif
210
211 #ifdef HAVE_NET_TAP_IF_TAP_H
212 #include <net/tap/if_tap.h>
213 #endif
214
215 #ifdef HAVE_NETINET_IN_SYSTM_H
216 #include <netinet/in_systm.h>
217 #endif
218
219 #ifdef HAVE_NETINET_IN_H
220 #include <netinet/in.h>
221 #endif
222
223 #ifdef HAVE_ARPA_INET_H
224 #include <arpa/inet.h>
225 #endif
226
227 #ifdef HAVE_NETINET_IP_H
228 #include <netinet/ip.h>
229 #endif
230
231 #ifdef HAVE_NETINET_TCP_H
232 #include <netinet/tcp.h>
233 #endif
234
235 #ifdef HAVE_NETINET_IN6_H
236 #include <netinet/in6.h>
237 #endif
238
239 #ifdef HAVE_NETINET_IP6_H
240 #include <netinet/ip6.h>
241 #endif
242
243 #ifdef HAVE_NET_ETHERNET_H
244 #include <net/ethernet.h>
245 #endif
246
247 #ifdef HAVE_NET_IF_ARP_H
248 #include <net/if_arp.h>
249 #endif
250
251 #ifdef HAVE_NETINET_IP_ICMP_H
252 #include <netinet/ip_icmp.h>
253 #endif
254
255 #ifdef HAVE_NETINET_ICMP6_H
256 #include <netinet/icmp6.h>
257 #endif
258
259 #ifdef HAVE_NETINET_IF_ETHER_H
260 #include <netinet/if_ether.h>
261 #endif
262
263 #ifdef HAVE_ARPA_NAMESER_H
264 #include <arpa/nameser.h>
265 #endif
266
267 #ifdef HAVE_RESOLV_H
268 #include <resolv.h>
269 #endif
270
271 #ifdef HAVE_LINUX_IF_TUN_H
272 #include <linux/if_tun.h>
273 #endif
274
275 #ifdef HAVE_GETOPT_H
276 #include <getopt.h>
277 #else
278 #include "getopt.h"
279 #endif
280
281 #ifdef STATUS
282 #undef STATUS
283 #endif
284
285 #ifdef HAVE_WINDOWS
286 #define SLASH "\\"
287 #else
288 #define SLASH "/"
289 #endif
290
291 #endif