1 /* MIT License 2 * 3 * Copyright (c) 2004 Daniel Stenberg 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy 6 * of this software and associated documentation files (the "Software"), to deal 7 * in the Software without restriction, including without limitation the rights 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 * copies of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 * 24 * SPDX-License-Identifier: MIT 25 */ 26 #ifndef HEADER_CARES_SETUP_H 27 #define HEADER_CARES_SETUP_H 28 29 /* 30 * Define WIN32 when build target is Win32 API 31 */ 32 33 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) 34 # define WIN32 35 #endif 36 37 /* 38 * Include configuration script results or hand-crafted 39 * configuration file for platforms which lack config tool. 40 */ 41 42 #ifdef HAVE_CONFIG_H 43 # include "ares_config.h" 44 #else 45 46 # ifdef WIN32 47 # include "config-win32.h" 48 # endif 49 50 #endif /* HAVE_CONFIG_H */ 51 52 /* ================================================================ */ 53 /* Definition of preprocessor macros/symbols which modify compiler */ 54 /* behaviour or generated code characteristics must be done here, */ 55 /* as appropriate, before any system header file is included. It is */ 56 /* also possible to have them defined in the config file included */ 57 /* before this point. As a result of all this we frown inclusion of */ 58 /* system header files in our config files, avoid this at any cost. */ 59 /* ================================================================ */ 60 61 /* 62 * AIX 4.3 and newer needs _THREAD_SAFE defined to build 63 * proper reentrant code. Others may also need it. 64 */ 65 66 #ifdef NEED_THREAD_SAFE 67 # ifndef _THREAD_SAFE 68 # define _THREAD_SAFE 69 # endif 70 #endif 71 72 /* 73 * Tru64 needs _REENTRANT set for a few function prototypes and 74 * things to appear in the system header files. Unixware needs it 75 * to build proper reentrant code. Others may also need it. 76 */ 77 78 #ifdef NEED_REENTRANT 79 # ifndef _REENTRANT 80 # define _REENTRANT 81 # endif 82 #endif 83 84 /* ================================================================ */ 85 /* If you need to include a system header file for your platform, */ 86 /* please, do it beyond the point further indicated in this file. */ 87 /* ================================================================ */ 88 89 /* 90 * c-ares external interface definitions are also used internally, 91 * and might also include required system header files to define them. 92 */ 93 94 #include <ares_build.h> 95 96 /* 97 * Compile time sanity checks must also be done when building the library. 98 */ 99 100 #include <ares_rules.h> 101 102 /* ================================================================= */ 103 /* No system header file shall be included in this file before this */ 104 /* point. The only allowed ones are those included from ares_build.h */ 105 /* ================================================================= */ 106 107 /* 108 * Include header files for windows builds before redefining anything. 109 * Use this preproessor block only to include or exclude windows.h, 110 * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs 111 * to any other further and independent block. Under Cygwin things work 112 * just as under linux (e.g. <sys/socket.h>) and the winsock headers should 113 * never be included when __CYGWIN__ is defined. configure script takes 114 * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H, 115 * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined. 116 */ 117 118 #ifdef HAVE_WINDOWS_H 119 # ifndef WIN32_LEAN_AND_MEAN 120 # define WIN32_LEAN_AND_MEAN 121 # endif 122 # include <windows.h> 123 # ifdef HAVE_WINSOCK2_H 124 # include <winsock2.h> 125 # ifdef HAVE_WS2TCPIP_H 126 # include <ws2tcpip.h> 127 # endif 128 # else 129 # ifdef HAVE_WINSOCK_H 130 # include <winsock.h> 131 # endif 132 # endif 133 #endif 134 135 /* 136 * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else 137 * define USE_WINSOCK to 1 if we have and use WINSOCK API, else 138 * undefine USE_WINSOCK. 139 */ 140 141 #ifdef USE_WINSOCK 142 # undef USE_WINSOCK 143 #endif 144 #ifdef HAVE_WINSOCK2_H 145 # define USE_WINSOCK 2 146 #else 147 # ifdef HAVE_WINSOCK_H 148 # define USE_WINSOCK 1 149 # endif 150 #endif 151 152 /* 153 * Work-arounds for systems without configure support 154 */ 155 156 #ifndef HAVE_CONFIG_H 157 158 # if !defined(HAVE_SYS_TIME_H) && !defined(_MSC_VER) && !defined(__WATCOMC__) 159 # define HAVE_SYS_TIME_H 160 # endif 161 162 # if !defined(HAVE_UNISTD_H) && !defined(_MSC_VER) 163 # define HAVE_UNISTD_H 1 164 # endif 165 166 # if !defined(HAVE_SYS_UIO_H) && !defined(WIN32) && !defined(MSDOS) 167 # define HAVE_SYS_UIO_H 168 # endif 169 170 #endif /* HAVE_CONFIG_H */ 171 172 /* 173 * Arg 2 type for gethostname in case it hasn't been defined in config file. 174 */ 175 176 #ifndef GETHOSTNAME_TYPE_ARG2 177 # ifdef USE_WINSOCK 178 # define GETHOSTNAME_TYPE_ARG2 int 179 # else 180 # define GETHOSTNAME_TYPE_ARG2 size_t 181 # endif 182 #endif 183 184 #ifdef __POCC__ 185 # include <sys/types.h> 186 # include <unistd.h> 187 # define ESRCH 3 188 #endif 189 190 /* 191 * Android does have the arpa/nameser.h header which is detected by configure 192 * but it appears to be empty with recent NDK r7b / r7c, so we undefine here. 193 * z/OS does have the arpa/nameser.h header which is detected by configure 194 * but it is not fully implemented and missing identifiers, so udefine here. 195 */ 196 #if (defined(ANDROID) || defined(__ANDROID__) || defined(__MVS__)) && \ 197 defined(HAVE_ARPA_NAMESER_H) 198 # undef HAVE_ARPA_NAMESER_H 199 #endif 200 201 /* 202 * Recent autoconf versions define these symbols in ares_config.h. We don't 203 * want them (since they collide with the libcurl ones when we build 204 * --enable-debug) so we undef them again here. 205 */ 206 207 #ifdef PACKAGE_STRING 208 # undef PACKAGE_STRING 209 #endif 210 #ifdef PACKAGE_TARNAME 211 # undef PACKAGE_TARNAME 212 #endif 213 #ifdef PACKAGE_VERSION 214 # undef PACKAGE_VERSION 215 #endif 216 #ifdef PACKAGE_BUGREPORT 217 # undef PACKAGE_BUGREPORT 218 #endif 219 #ifdef PACKAGE_NAME 220 # undef PACKAGE_NAME 221 #endif 222 #ifdef VERSION 223 # undef VERSION 224 #endif 225 #ifdef PACKAGE 226 # undef PACKAGE 227 #endif 228 229 /* IPv6 compatibility */ 230 #if !defined(HAVE_AF_INET6) 231 # if defined(HAVE_PF_INET6) 232 # define AF_INET6 PF_INET6 233 # else 234 # define AF_INET6 AF_MAX + 1 235 # endif 236 #endif 237 238 /* 239 * Include macros and defines that should only be processed once. 240 */ 241 242 #ifndef __SETUP_ONCE_H 243 # include "setup_once.h" 244 #endif 245 246 #endif /* HEADER_CARES_SETUP_H */ 247