Add check for __Static_assert() and asserts on struct sizes
[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_ALLOCA_H
55 #include <alloca.h>
56 #elif defined(HAVE_NETBSD)
57 #define alloca(size) __builtin_alloca(size)
58 #endif
59
60 #ifdef HAVE_WINDOWS
61 #ifdef HAVE_W32API_H
62 #include <w32api.h>
63 #endif
64
65 #include <winsock2.h>
66 #include <windows.h>
67 #include <ws2tcpip.h>
68
69 #ifdef _MSC_VER
70 #include <io.h>
71 #include <process.h>
72 #include <direct.h>
73 #endif
74 #endif // HAVE_WINDOWS
75
76 #ifdef HAVE_TERMIOS_H
77 #include <termios.h>
78 #endif
79
80 #ifdef HAVE_INTTYPES_H
81 #include <inttypes.h>
82 #endif
83
84 /* Include system specific headers */
85
86 #ifdef HAVE_STDDEF_H
87 #include <stddef.h>
88 #endif
89
90 #ifdef HAVE_SYSLOG_H
91 #include <syslog.h>
92 #endif
93
94 #ifdef HAVE_SYS_TIME_H
95 #include <sys/time.h>
96 #endif
97
98
99 #ifdef HAVE_SYS_TYPES_H
100 #include <sys/types.h>
101 #endif
102
103 #ifdef HAVE_SYS_STAT_H
104 #include <sys/stat.h>
105 #endif
106
107 #ifdef HAVE_SYS_FILE_H
108 #include <sys/file.h>
109 #endif
110
111 #ifdef HAVE_SYS_MMAN_H
112 #include <sys/mman.h>
113 #endif
114
115 #ifdef HAVE_SYS_WAIT_H
116 #include <sys/wait.h>
117 #endif
118
119 #ifdef HAVE_SYS_IOCTL_H
120 #include <sys/ioctl.h>
121 #endif
122
123 #ifdef HAVE_SYS_PARAM_H
124 #include <sys/param.h>
125 #endif
126
127 #ifdef HAVE_SYS_RESOURCE_H
128 #include <sys/resource.h>
129 #endif
130
131 #ifdef HAVE_SYS_UN_H
132 #include <sys/un.h>
133 #endif
134
135 #ifdef HAVE_DIRENT_H
136 #include <dirent.h>
137 #elif defined(_MSC_VER)
138 #include "dirent.h"
139 #endif
140
141 /* SunOS really wants sys/socket.h BEFORE net/if.h,
142    and FreeBSD wants these lines below the rest. */
143
144 #ifdef HAVE_NETDB_H
145 #include <netdb.h>
146 #endif
147
148 #ifdef HAVE_SYS_SOCKET_H
149 #include <sys/socket.h>
150 #endif
151
152 #ifdef HAVE_NET_IF_H
153 #include <net/if.h>
154 #endif
155
156 #ifdef HAVE_NET_IF_TYPES_H
157 #include <net/if_types.h>
158 #endif
159
160 #ifdef HAVE_NET_IF_TUN_H
161 #include <net/if_tun.h>
162 #endif
163
164 #ifdef HAVE_NET_TUN_IF_TUN_H
165 #include <net/tun/if_tun.h>
166 #endif
167
168 #ifdef HAVE_NET_IF_TAP_H
169 #include <net/if_tap.h>
170 #endif
171
172 #ifdef HAVE_NET_TAP_IF_TAP_H
173 #include <net/tap/if_tap.h>
174 #endif
175
176 #ifdef HAVE_NETINET_IN_SYSTM_H
177 #include <netinet/in_systm.h>
178 #endif
179
180 #ifdef HAVE_NETINET_IN_H
181 #include <netinet/in.h>
182 #endif
183
184 #ifdef HAVE_ARPA_INET_H
185 #include <arpa/inet.h>
186 #endif
187
188 #ifdef HAVE_NETINET_IP_H
189 #include <netinet/ip.h>
190 #endif
191
192 #ifdef HAVE_NETINET_TCP_H
193 #include <netinet/tcp.h>
194 #endif
195
196 #ifdef HAVE_NETINET_IN6_H
197 #include <netinet/in6.h>
198 #endif
199
200 #ifdef HAVE_NETINET_IP6_H
201 #include <netinet/ip6.h>
202 #endif
203
204 #ifdef HAVE_NET_ETHERNET_H
205 #include <net/ethernet.h>
206 #endif
207
208 #ifdef HAVE_NET_IF_ARP_H
209 #include <net/if_arp.h>
210 #endif
211
212 #ifdef HAVE_NETINET_IP_ICMP_H
213 #include <netinet/ip_icmp.h>
214 #endif
215
216 #ifdef HAVE_NETINET_ICMP6_H
217 #include <netinet/icmp6.h>
218 #endif
219
220 #ifdef HAVE_NETINET_IF_ETHER_H
221 #include <netinet/if_ether.h>
222 #endif
223
224 #ifdef HAVE_ARPA_NAMESER_H
225 #include <arpa/nameser.h>
226 #endif
227
228 #ifdef HAVE_RESOLV_H
229 #include <resolv.h>
230 #endif
231
232 #ifdef HAVE_LINUX_IF_TUN_H
233 #include <linux/if_tun.h>
234 #endif
235
236 #ifdef HAVE_GETOPT_H
237 #include <getopt.h>
238 #else
239 #include "getopt.h"
240 #endif
241
242 #ifdef STATUS
243 #undef STATUS
244 #endif
245
246 #ifdef HAVE_WINDOWS
247 #define SLASH "\\"
248 #else
249 #define SLASH "/"
250 #endif
251
252 #endif