2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
8 * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
32 #ifdef HAVE_SYS_WAIT_H
33 # include <sys/wait.h>
38 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
41 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
45 #ifdef TIME_WITH_SYS_TIME
46 # include <sys/time.h>
49 # ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
56 #ifdef HAVE_SYS_SOCKET_H
57 #include <sys/socket.h>
60 #ifdef HAVE_SYS_IOCTL_H
61 #include <sys/ioctl.h>
64 #ifdef HAVE_SYS_STAT_H
72 #ifdef HAVE_SYS_FILE_H
128 #ifdef HAVE_NETINET_IN_H
129 #include <netinet/in.h>
132 #ifdef HAVE_SYS_POLL_H
133 #include <sys/poll.h>
136 #ifdef HAVE_SYS_EPOLL_H
137 #include <sys/epoll.h>
140 #ifdef TARGET_SOLARIS
141 #ifdef HAVE_STRINGS_H
150 #ifdef HAVE_ARPA_INET_H
151 #include <arpa/inet.h>
160 #if defined(HAVE_NETINET_IF_ETHER_H)
161 #include <netinet/if_ether.h>
164 #ifdef HAVE_LINUX_IF_TUN_H
165 #include <linux/if_tun.h>
168 #ifdef HAVE_NETINET_IP_H
169 #include <netinet/ip.h>
172 #ifdef HAVE_LINUX_SOCKIOS_H
173 #include <linux/sockios.h>
176 #ifdef HAVE_LINUX_TYPES_H
177 #include <linux/types.h>
180 #ifdef HAVE_LINUX_ERRQUEUE_H
181 #include <linux/errqueue.h>
184 #endif /* TARGET_LINUX */
186 #ifdef TARGET_SOLARIS
188 #ifdef HAVE_STROPTS_H
193 #ifdef HAVE_NET_IF_TUN_H
194 #include <net/if_tun.h>
197 #ifdef HAVE_SYS_SOCKIO_H
198 #include <sys/sockio.h>
201 #ifdef HAVE_NETINET_IN_SYSTM_H
202 #include <netinet/in_systm.h>
205 #ifdef HAVE_NETINET_IP_H
206 #include <netinet/ip.h>
209 #ifdef HAVE_NETINET_TCP_H
210 #include <netinet/tcp.h>
213 #endif /* TARGET_SOLARIS */
215 #ifdef TARGET_OPENBSD
217 #ifdef HAVE_SYS_UIO_H
221 #ifdef HAVE_NETINET_IN_SYSTM_H
222 #include <netinet/in_systm.h>
225 #ifdef HAVE_NETINET_IP_H
226 #include <netinet/ip.h>
229 #ifdef HAVE_NET_IF_TUN_H
230 #include <net/if_tun.h>
233 #endif /* TARGET_OPENBSD */
235 #ifdef TARGET_FREEBSD
237 #ifdef HAVE_SYS_UIO_H
241 #ifdef HAVE_NETINET_IN_SYSTM_H
242 #include <netinet/in_systm.h>
245 #ifdef HAVE_NETINET_IP_H
246 #include <netinet/ip.h>
249 #ifdef HAVE_NET_IF_TUN_H
250 #include <net/if_tun.h>
253 #endif /* TARGET_FREEBSD */
257 #ifdef HAVE_NET_IF_TUN_H
258 #include <net/if_tun.h>
261 #endif /* TARGET_NETBSD */
264 #include <iphlpapi.h>
267 #ifdef HAVE_SYS_MMAN_H
269 #define _P1003_1B_VISIBLE
270 #endif /* TARGET_DARWIN */
271 #include <sys/mman.h>
275 * Pedantic mode is meant to accomplish lint-style program checking,
276 * not to build a working executable.
278 #ifdef __STRICT_ANSI__
280 # undef HAVE_CPP_VARARG_MACRO_GCC
281 # undef HAVE_CPP_VARARG_MACRO_ISO
282 # undef EMPTY_ARRAY_SIZE
283 # define EMPTY_ARRAY_SIZE 1
291 * Do we have the capability to support the --passtos option?
293 #if defined(IPPROTO_IP) && defined(IP_TOS) && defined(HAVE_SETSOCKOPT)
294 #define PASSTOS_CAPABILITY 1
296 #define PASSTOS_CAPABILITY 0
300 * Do we have the capability to report extended socket errors?
302 #if defined(HAVE_LINUX_TYPES_H) && defined(HAVE_LINUX_ERRQUEUE_H) && defined(HAVE_SOCK_EXTENDED_ERR) && defined(HAVE_MSGHDR) && defined(HAVE_CMSGHDR) && defined(CMSG_FIRSTHDR) && defined(CMSG_NXTHDR) && defined(IP_RECVERR) && defined(MSG_ERRQUEUE) && defined(SOL_IP) && defined(HAVE_IOVEC)
303 #define EXTENDED_SOCKET_ERROR_CAPABILITY 1
305 #define EXTENDED_SOCKET_ERROR_CAPABILITY 0
312 #undef EXTENDED_SOCKET_ERROR_CAPABILITY
313 #define EXTENDED_SOCKET_ERROR_CAPABILITY 0
317 * Do we have a syslog capability?
319 #if defined(HAVE_OPENLOG) && defined(HAVE_SYSLOG)
320 #define SYSLOG_CAPABILITY 1
322 #define SYSLOG_CAPABILITY 0
326 * Does this OS draw a distinction between binary and ascii files?
333 * Directory separation char
336 #define OS_SPECIFIC_DIRSEP '\\'
338 #define OS_SPECIFIC_DIRSEP '/'
342 * Define a boolean value based
352 * Our socket descriptor type.
355 #define SOCKET_UNDEFINED (INVALID_SOCKET)
356 typedef SOCKET socket_descriptor_t
;
358 #define SOCKET_UNDEFINED (-1)
359 typedef int socket_descriptor_t
;
363 socket_defined (const socket_descriptor_t sd
)
365 return sd
!= SOCKET_UNDEFINED
;
369 * Should statistics counters be 64 bits?
371 #define USE_64_BIT_COUNTERS
374 * Do we have point-to-multipoint capability?
377 #if defined(ENABLE_CLIENT_SERVER) && defined(USE_CRYPTO) && defined(USE_SSL) && defined(HAVE_GETTIMEOFDAY)
383 #if P2MP && !defined(ENABLE_CLIENT_ONLY)
384 #define P2MP_SERVER 1
386 #define P2MP_SERVER 0
390 * Do we have a plug-in capability?
392 #if defined(USE_LIBDL) || defined(USE_LOAD_LIBRARY)
393 #define ENABLE_PLUGIN
397 * Do we have pthread capability?
400 #if defined(USE_CRYPTO) && defined(USE_SSL) && P2MP
408 * Pthread support is currently experimental (and quite unfinished).
410 #if 1 /* JYFIXME -- if defined, disable pthread */
415 * Should we include OCC (options consistency check) code?
422 * Should we include NTLM proxy functionality
424 #if defined(USE_CRYPTO) && defined(ENABLE_HTTP_PROXY)
431 * Is poll available on this platform?
433 #if defined(HAVE_POLL) && defined(HAVE_SYS_POLL_H)
440 * Is epoll available on this platform?
442 #if defined(HAVE_EPOLL_CREATE) && defined(HAVE_SYS_EPOLL_H)