1 /* $NetBSD: netdb.h,v 1.1.1.3 2014/12/10 03:34:43 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* Id */ 20 21 /*! \file */ 22 23 #ifndef IRS_NETDB_H 24 #define IRS_NETDB_H 1 25 26 #include <stddef.h> /* Required on FreeBSD (and others?) for size_t. */ 27 28 /* 29 * Define if <netdb.h> does not declare struct addrinfo. 30 */ 31 #undef ISC_IRS_NEEDADDRINFO 32 33 #ifdef ISC_IRS_NEEDADDRINFO 34 struct addrinfo { 35 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 36 int ai_family; /* PF_xxx */ 37 int ai_socktype; /* SOCK_xxx */ 38 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 39 size_t ai_addrlen; /* Length of ai_addr */ 40 char *ai_canonname; /* Canonical name for hostname */ 41 struct sockaddr *ai_addr; /* Binary address */ 42 struct addrinfo *ai_next; /* Next structure in linked list */ 43 }; 44 #endif 45 46 /* 47 * Undefine all #defines we are interested in as <netdb.h> may or may not have 48 * defined them. 49 */ 50 51 /* 52 * Error return codes from gethostbyname() and gethostbyaddr() 53 * (left in extern int h_errno). 54 */ 55 56 #undef NETDB_INTERNAL 57 #undef NETDB_SUCCESS 58 #undef HOST_NOT_FOUND 59 #undef TRY_AGAIN 60 #undef NO_RECOVERY 61 #undef NO_DATA 62 #undef NO_ADDRESS 63 64 #define NETDB_INTERNAL -1 /* see errno */ 65 #define NETDB_SUCCESS 0 /* no problem */ 66 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 67 #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */ 68 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 69 #define NO_DATA 4 /* Valid name, no data record of requested type */ 70 #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 71 72 /* 73 * Error return codes from getaddrinfo(). EAI_INSECUREDATA is our own extension 74 * and it's very unlikely to be already defined, but undef it just in case; it 75 * at least doesn't do any harm. 76 */ 77 78 #undef EAI_ADDRFAMILY 79 #undef EAI_AGAIN 80 #undef EAI_BADFLAGS 81 #undef EAI_FAIL 82 #undef EAI_FAMILY 83 #undef EAI_MEMORY 84 #undef EAI_NODATA 85 #undef EAI_NONAME 86 #undef EAI_SERVICE 87 #undef EAI_SOCKTYPE 88 #undef EAI_SYSTEM 89 #undef EAI_BADHINTS 90 #undef EAI_PROTOCOL 91 #undef EAI_OVERFLOW 92 #undef EAI_INSECUREDATA 93 #undef EAI_MAX 94 95 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 96 #define EAI_AGAIN 2 /* temporary failure in name resolution */ 97 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 98 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 99 #define EAI_FAMILY 5 /* ai_family not supported */ 100 #define EAI_MEMORY 6 /* memory allocation failure */ 101 #define EAI_NODATA 7 /* no address associated with hostname */ 102 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 103 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 104 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 105 #define EAI_SYSTEM 11 /* system error returned in errno */ 106 #define EAI_BADHINTS 12 107 #define EAI_PROTOCOL 13 108 #define EAI_OVERFLOW 14 109 #define EAI_INSECUREDATA 15 110 #define EAI_MAX 16 111 112 /* 113 * Flag values for getaddrinfo() 114 */ 115 #undef AI_PASSIVE 116 #undef AI_CANONNAME 117 #undef AI_NUMERICHOST 118 119 #define AI_PASSIVE 0x00000001 120 #define AI_CANONNAME 0x00000002 121 #define AI_NUMERICHOST 0x00000004 122 123 /* 124 * Flag values for getipnodebyname() 125 */ 126 #undef AI_V4MAPPED 127 #undef AI_ALL 128 #undef AI_ADDRCONFIG 129 #undef AI_DEFAULT 130 131 #define AI_V4MAPPED 0x00000008 132 #define AI_ALL 0x00000010 133 #define AI_ADDRCONFIG 0x00000020 134 #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG) 135 136 /* 137 * Constants for lwres_getnameinfo() 138 */ 139 #undef NI_MAXHOST 140 #undef NI_MAXSERV 141 142 #define NI_MAXHOST 1025 143 #define NI_MAXSERV 32 144 145 /* 146 * Flag values for lwres_getnameinfo() 147 */ 148 #undef NI_NOFQDN 149 #undef NI_NUMERICHOST 150 #undef NI_NAMEREQD 151 #undef NI_NUMERICSERV 152 #undef NI_DGRAM 153 #undef NI_NUMERICSCOPE 154 155 #define NI_NOFQDN 0x00000001 156 #define NI_NUMERICHOST 0x00000002 157 #define NI_NAMEREQD 0x00000004 158 #define NI_NUMERICSERV 0x00000008 159 #define NI_DGRAM 0x00000010 160 161 /* 162 * Define to map into irs_ namespace. 163 */ 164 165 #define IRS_NAMESPACE 166 167 #ifdef IRS_NAMESPACE 168 169 /* 170 * Use our versions not the ones from the C library. 171 */ 172 173 #ifdef getnameinfo 174 #undef getnameinfo 175 #endif 176 #define getnameinfo irs_getnameinfo 177 178 #ifdef getaddrinfo 179 #undef getaddrinfo 180 #endif 181 #define getaddrinfo irs_getaddrinfo 182 183 #ifdef freeaddrinfo 184 #undef freeaddrinfo 185 #endif 186 #define freeaddrinfo irs_freeaddrinfo 187 188 #ifdef gai_strerror 189 #undef gai_strerror 190 #endif 191 #define gai_strerror irs_gai_strerror 192 193 #endif 194 195 int getaddrinfo(const char *, const char *, 196 const struct addrinfo *, struct addrinfo **); 197 int getnameinfo(const struct sockaddr *, socklen_t, char *, 198 DWORD, char *, DWORD, int); 199 void freeaddrinfo(struct addrinfo *); 200 char *gai_strerror(int); 201 202 /* 203 * Tell Emacs to use C mode on this file. 204 * Local variables: 205 * mode: c 206 * End: 207 */ 208 209 #endif /* IRS_NETDB_H */ 210