1 /* 2 * Copyright (c) 2001, 02 Motoyuki Kasahara 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its contributors 13 * may be used to endorse or promote products derived from this software 14 * without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef GETADDRINFO_H 30 #define GETADDRINFO_H 31 32 #ifdef HAVE_CONFIG_H 33 #include "config.h" 34 #endif 35 36 #include <sys/types.h> 37 38 #ifdef WIN32 39 #include <time.h> 40 #include <winsock2.h> 41 #ifdef DO_IPV6 42 #include <ws2tcpip.h> 43 #endif /* DO_IPV6 */ 44 #include <windows.h> 45 #else 46 #include <sys/socket.h> 47 #include <netdb.h> 48 #endif 49 50 51 /********************************************************************/ 52 /* 53 * Undefine all the macros. 54 * <netdb.h> might defines some of them. 55 */ 56 #ifdef EAI_ADDRFAMILY 57 #undef EAI_ADDRFAMILY 58 #endif 59 #ifdef EAI_AGAIN 60 #undef EAI_AGAIN 61 #endif 62 #ifdef EAI_BADFLAGS 63 #undef EAI_BADFLAGS 64 #endif 65 #ifdef EAI_FAIL 66 #undef EAI_FAIL 67 #endif 68 #ifdef EAI_FAMILY 69 #undef EAI_FAMILY 70 #endif 71 #ifdef EAI_MEMORY 72 #undef EAI_MEMORY 73 #endif 74 #ifdef EAI_NONAME 75 #undef EAI_NONAME 76 #endif 77 #ifdef EAI_OVERFLOW 78 #undef EAI_OVERFLOW 79 #endif 80 #ifdef EAI_SERVICE 81 #undef EAI_SERVICE 82 #endif 83 #ifdef EAI_SOCKTYPE 84 #undef EAI_SOCKTYPE 85 #endif 86 #ifdef EAI_SYSTEM 87 #undef EAI_SYSTEM 88 #endif 89 90 #ifdef AI_PASSIVE 91 #undef AI_PASSIVE 92 #endif 93 #ifdef AI_CANONNAME 94 #undef AI_CANONNAME 95 #endif 96 #ifdef AI_NUMERICHOST 97 #undef AI_NUMERICHOST 98 #endif 99 #ifdef AI_NUMERICSERV 100 #undef AI_NUMERICSERV 101 #endif 102 #ifdef AI_V4MAPPED 103 #undef AI_V4MAPPED 104 #endif 105 #ifdef AI_ALL 106 #undef AI_ALL 107 #endif 108 #ifdef AI_ADDRCONFIG 109 #undef AI_ADDRCONFIG 110 #endif 111 #ifdef AI_DEFAULT 112 #undef AI_DEFAULT 113 #endif 114 115 #ifdef NI_NOFQDN 116 #undef NI_NOFQDN 117 #endif 118 #ifdef NI_NUMERICHOST 119 #undef NI_NUMERICHOST 120 #endif 121 #ifdef NI_NAMEREQD 122 #undef NI_NAMEREQD 123 #endif 124 #ifdef NI_NUMERICSERV 125 #undef NI_NUMERICSERV 126 #endif 127 #ifdef NI_NUMERICSCOPE 128 #undef NI_NUMERICSCOPE 129 #endif 130 131 #ifdef NI_DGRAM 132 #undef NI_DGRAM 133 #endif 134 #ifdef NI_MAXHOST 135 #undef NI_MAXHOST 136 #endif 137 #ifdef NI_MAXSERV 138 #undef NI_MAXSERV 139 #endif 140 141 /* 142 * Fake struct and function names. 143 * <netdb.h> might declares all or some of them. 144 */ 145 #if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO) 146 #define addrinfo my_addrinfo 147 #define gai_strerror my_gai_strerror 148 #define freeaddrinfo my_freeaddrinfo 149 #define getaddrinfo my_getaddrinfo 150 #define getnameinfo my_getnameinfo 151 #endif 152 153 /********************************************************************/ 154 /* 155 * Error codes. 156 */ 157 #define EAI_ADDRFAMILY 1 158 #define EAI_AGAIN 2 159 #define EAI_BADFLAGS 3 160 #define EAI_FAIL 4 161 #define EAI_FAMILY 5 162 #define EAI_MEMORY 6 163 #define EAI_NONAME 7 164 #define EAI_OVERFLOW 8 165 #define EAI_SERVICE 9 166 #define EAI_SOCKTYPE 10 167 #define EAI_SYSTEM 11 168 169 /* 170 * Flags for getaddrinfo(). 171 */ 172 #define AI_ADDRCONFIG 0x0001 173 #define AI_ALL 0x0002 174 #define AI_CANONNAME 0x0004 175 #define AI_NUMERICHOST 0x0008 176 #define AI_NUMERICSERV 0x0010 177 #define AI_PASSIVE 0x0020 178 #define AI_V4MAPPED 0x0040 179 #define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG) 180 181 /* 182 * Flags for getnameinfo(). 183 */ 184 #define NI_DGRAM 0x0001 185 #define NI_NAMEREQD 0x0002 186 #define NI_NOFQDN 0x0004 187 #define NI_NUMERICHOST 0x0008 188 #define NI_NUMERICSCOPE 0x0010 189 #define NI_NUMERICSERV 0x0020 190 191 /* 192 * Maximum length of FQDN and servie name for getnameinfo(). 193 */ 194 #define NI_MAXHOST 1025 195 #define NI_MAXSERV 32 196 197 /* 198 * Address families and Protocol families. 199 */ 200 #ifndef AF_UNSPEC 201 #define AF_UNSPEC AF_INET 202 #endif 203 #ifndef PF_UNSPEC 204 #define PF_UNSPEC PF_INET 205 #endif 206 207 /* 208 * struct addrinfo. 209 */ 210 struct addrinfo { 211 int ai_flags; 212 int ai_family; 213 int ai_socktype; 214 int ai_protocol; 215 socklen_t ai_addrlen; 216 char *ai_canonname; 217 struct sockaddr *ai_addr; 218 struct addrinfo *ai_next; 219 }; 220 221 /* 222 * Functions. 223 */ 224 #ifdef __STDC__ 225 const char *gai_strerror(int); 226 void freeaddrinfo(struct addrinfo *); 227 int getaddrinfo(const char *, const char *, const struct addrinfo *, 228 struct addrinfo **); 229 int getnameinfo(const struct sockaddr *, socklen_t, char *, 230 socklen_t, char *, socklen_t, int); 231 #else 232 const char *gai_strerror(); 233 void freeaddrinfo(); 234 int getaddrinfo(); 235 int getnameinfo(); 236 #endif 237 238 #endif /* not GETADDRINFO_H */ 239