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 __ARES_SETUP_H 27 #define __ARES_SETUP_H 28 29 /* ============================================================================ 30 * NOTE: This file is automatically included by ares_private.h and should not 31 * typically be included directly. 32 * All c-ares source files should include ares_private.h as the 33 * first header. 34 * ============================================================================ 35 */ 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 # ifdef _WIN32 46 # include "config-win32.h" 47 # endif 48 #endif /* HAVE_CONFIG_H */ 49 50 /* 51 * c-ares external interface definitions are also used internally, 52 * and might also include required system header files to define them. 53 */ 54 55 #include "ares_build.h" 56 57 /* ================================================================= */ 58 /* No system header file shall be included in this file before this */ 59 /* point. The only allowed ones are those included from ares_build.h */ 60 /* ================================================================= */ 61 62 /* 63 * Include header files for windows builds before redefining anything. 64 * Use this preproessor block only to include or exclude windows.h, 65 * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs 66 * to any other further and independent block. Under Cygwin things work 67 * just as under linux (e.g. <sys/socket.h>) and the winsock headers should 68 * never be included when __CYGWIN__ is defined. configure script takes 69 * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H, 70 * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined. 71 */ 72 73 #ifdef USE_WINSOCK 74 # undef USE_WINSOCK 75 #endif 76 77 #ifdef HAVE_WINDOWS_H 78 # ifndef WIN32_LEAN_AND_MEAN 79 # define WIN32_LEAN_AND_MEAN 80 # endif 81 # include <windows.h> 82 # ifdef HAVE_WINSOCK2_H 83 # include <winsock2.h> 84 # define USE_WINSOCK 2 85 # ifdef HAVE_WS2TCPIP_H 86 # include <ws2tcpip.h> 87 # endif 88 # else 89 # ifdef HAVE_WINSOCK_H 90 # include <winsock.h> 91 # define USE_WINSOCK 1 92 # endif 93 # endif 94 #endif 95 96 97 #include <stdio.h> 98 #include <stdlib.h> 99 #include <string.h> 100 #include <stdarg.h> 101 #include <ctype.h> 102 103 #ifdef HAVE_ERRNO_H 104 # include <errno.h> 105 #endif 106 107 #ifdef HAVE_SYS_TYPES_H 108 # include <sys/types.h> 109 #endif 110 111 #ifdef HAVE_MALLOC_H 112 # include <malloc.h> 113 #endif 114 115 #ifdef HAVE_SYS_STAT_H 116 # include <sys/stat.h> 117 #endif 118 119 #ifdef HAVE_SYS_TIME_H 120 # include <sys/time.h> 121 #endif 122 123 #ifdef HAVE_TIME_H 124 # include <time.h> 125 #endif 126 127 #ifdef HAVE_UNISTD_H 128 # include <unistd.h> 129 #endif 130 131 #ifdef HAVE_SYS_SOCKET_H 132 # include <sys/socket.h> 133 #endif 134 135 /* 136 * Arg 2 type for gethostname in case it hasn't been defined in config file. 137 */ 138 139 #ifndef GETHOSTNAME_TYPE_ARG2 140 # ifdef USE_WINSOCK 141 # define GETHOSTNAME_TYPE_ARG2 int 142 # else 143 # define GETHOSTNAME_TYPE_ARG2 size_t 144 # endif 145 #endif 146 147 #ifdef __POCC__ 148 # include <sys/types.h> 149 # include <unistd.h> 150 # define ESRCH 3 151 #endif 152 153 /* 154 * Android does have the arpa/nameser.h header which is detected by configure 155 * but it appears to be empty with recent NDK r7b / r7c, so we undefine here. 156 * z/OS does have the arpa/nameser.h header which is detected by configure 157 * but it is not fully implemented and missing identifiers, so udefine here. 158 */ 159 #if (defined(ANDROID) || defined(__ANDROID__) || defined(__MVS__)) && \ 160 defined(HAVE_ARPA_NAMESER_H) 161 # undef HAVE_ARPA_NAMESER_H 162 #endif 163 164 /* 165 * Recent autoconf versions define these symbols in ares_config.h. We don't 166 * want them (since they collide with the libcurl ones when we build 167 * --enable-debug) so we undef them again here. 168 */ 169 170 #ifdef PACKAGE_STRING 171 # undef PACKAGE_STRING 172 #endif 173 #ifdef PACKAGE_TARNAME 174 # undef PACKAGE_TARNAME 175 #endif 176 #ifdef PACKAGE_VERSION 177 # undef PACKAGE_VERSION 178 #endif 179 #ifdef PACKAGE_BUGREPORT 180 # undef PACKAGE_BUGREPORT 181 #endif 182 #ifdef PACKAGE_NAME 183 # undef PACKAGE_NAME 184 #endif 185 #ifdef VERSION 186 # undef VERSION 187 #endif 188 #ifdef PACKAGE 189 # undef PACKAGE 190 #endif 191 192 /* IPv6 compatibility */ 193 #if !defined(HAVE_AF_INET6) 194 # if defined(HAVE_PF_INET6) 195 # define AF_INET6 PF_INET6 196 # else 197 # define AF_INET6 AF_MAX + 1 198 # endif 199 #endif 200 201 202 /* Definition of timeval struct for platforms that don't have it. */ 203 204 #ifndef HAVE_STRUCT_TIMEVAL 205 struct timeval { 206 ares_int64_t tv_sec; 207 long tv_usec; 208 }; 209 #endif 210 211 212 /* 213 * Macro used to include code only in debug builds. 214 */ 215 216 #ifdef DEBUGBUILD 217 # define DEBUGF(x) x 218 #else 219 # define DEBUGF(x) \ 220 do { \ 221 } while (0) 222 #endif 223 224 #endif /* __ARES_SETUP_H */ 225