1 1.1 christos /* 2 1.1 christos * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 1.1 christos * 4 1.1 christos * SPDX-License-Identifier: MPL-2.0 5 1.1 christos * 6 1.1 christos * This Source Code Form is subject to the terms of the Mozilla Public 7 1.1 christos * License, v. 2.0. If a copy of the MPL was not distributed with this 8 1.1 christos * file, you can obtain one at https://mozilla.org/MPL/2.0/. 9 1.1 christos * 10 1.1 christos * See the COPYRIGHT file distributed with this work for additional 11 1.1 christos * information regarding copyright ownership. 12 1.1 christos */ 13 1.1 christos 14 1.1 christos /*! \file */ 15 1.1 christos 16 1.1 christos #ifndef IRS_NETDB_H 17 1.1 christos #define IRS_NETDB_H 1 18 1.1 christos 19 1.1 christos #include <stddef.h> /* Required on FreeBSD (and others?) for size_t. */ 20 1.1 christos #include <netdb.h> /* Contractual provision. */ 21 1.1 christos 22 1.1 christos /* 23 1.1 christos * Undefine all #defines we are interested in as <netdb.h> may or may not have 24 1.1 christos * defined them. 25 1.1 christos */ 26 1.1 christos 27 1.1 christos /* 28 1.1 christos * Error return codes from gethostbyname() and gethostbyaddr() 29 1.1 christos * (left in extern int h_errno). 30 1.1 christos */ 31 1.1 christos 32 1.1 christos #undef NETDB_INTERNAL 33 1.1 christos #undef NETDB_SUCCESS 34 1.1 christos #undef HOST_NOT_FOUND 35 1.1 christos #undef TRY_AGAIN 36 1.1 christos #undef NO_RECOVERY 37 1.1 christos #undef NO_DATA 38 1.1 christos #undef NO_ADDRESS 39 1.1 christos 40 1.1 christos #define NETDB_INTERNAL -1 /* see errno */ 41 1.1 christos #define NETDB_SUCCESS 0 /* no problem */ 42 1.1 christos #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ 43 1.1 christos #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */ 44 1.1 christos #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 45 1.1 christos #define NO_DATA 4 /* Valid name, no data record of requested type */ 46 1.1 christos #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 47 1.1 christos 48 1.1 christos /* 49 1.1 christos * Error return codes from getaddrinfo(). EAI_INSECUREDATA is our own extension 50 1.1 christos * and it's very unlikely to be already defined, but undef it just in case; it 51 1.1 christos * at least doesn't do any harm. 52 1.1 christos */ 53 1.1 christos 54 1.1 christos #undef EAI_ADDRFAMILY 55 1.1 christos #undef EAI_AGAIN 56 1.1 christos #undef EAI_BADFLAGS 57 1.1 christos #undef EAI_FAIL 58 1.1 christos #undef EAI_FAMILY 59 1.1 christos #undef EAI_MEMORY 60 1.1 christos #undef EAI_NODATA 61 1.1 christos #undef EAI_NONAME 62 1.1 christos #undef EAI_SERVICE 63 1.1 christos #undef EAI_SOCKTYPE 64 1.1 christos #undef EAI_SYSTEM 65 1.1 christos #undef EAI_BADHINTS 66 1.1 christos #undef EAI_PROTOCOL 67 1.1 christos #undef EAI_OVERFLOW 68 1.1 christos #undef EAI_INSECUREDATA 69 1.1 christos #undef EAI_MAX 70 1.1 christos 71 1.1 christos #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 72 1.1 christos #define EAI_AGAIN 2 /* temporary failure in name resolution */ 73 1.1 christos #define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 74 1.1 christos #define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 75 1.1 christos #define EAI_FAMILY 5 /* ai_family not supported */ 76 1.1 christos #define EAI_MEMORY 6 /* memory allocation failure */ 77 1.1 christos #define EAI_NODATA 7 /* no address associated with hostname */ 78 1.1 christos #define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 79 1.1 christos #define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 80 1.1 christos #define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 81 1.1 christos #define EAI_SYSTEM 11 /* system error returned in errno */ 82 1.1 christos #define EAI_BADHINTS 12 83 1.1 christos #define EAI_PROTOCOL 13 84 1.1 christos #define EAI_OVERFLOW 14 85 1.1 christos #define EAI_INSECUREDATA 15 86 1.1 christos #define EAI_MAX 16 87 1.1 christos 88 1.1 christos /* 89 1.1 christos * Flag values for getaddrinfo() 90 1.1 christos */ 91 1.1 christos #undef AI_PASSIVE 92 1.1 christos #undef AI_CANONNAME 93 1.1 christos #undef AI_NUMERICHOST 94 1.1 christos 95 1.1 christos #define AI_PASSIVE 0x00000001 96 1.1 christos #define AI_CANONNAME 0x00000002 97 1.1 christos #define AI_NUMERICHOST 0x00000004 98 1.1 christos 99 1.1 christos /* 100 1.1 christos * Flag values for getipnodebyname() 101 1.1 christos */ 102 1.1 christos #undef AI_V4MAPPED 103 1.1 christos #undef AI_ALL 104 1.1 christos #undef AI_ADDRCONFIG 105 1.1 christos #undef AI_DEFAULT 106 1.1 christos 107 1.1 christos #define AI_V4MAPPED 0x00000008 108 1.1 christos #define AI_ALL 0x00000010 109 1.1 christos #define AI_ADDRCONFIG 0x00000020 110 1.1 christos #define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG) 111 1.1 christos 112 1.1 christos /* 113 1.1 christos * Constants for getnameinfo() 114 1.1 christos */ 115 1.1 christos #undef NI_MAXHOST 116 1.1 christos #undef NI_MAXSERV 117 1.1 christos 118 1.1 christos #define NI_MAXHOST 1025 119 1.1 christos #define NI_MAXSERV 32 120 1.1 christos 121 1.1 christos /* 122 1.1 christos * Flag values for getnameinfo() 123 1.1 christos */ 124 1.1 christos #undef NI_NOFQDN 125 1.1 christos #undef NI_NUMERICHOST 126 1.1 christos #undef NI_NAMEREQD 127 1.1 christos #undef NI_NUMERICSERV 128 1.1 christos #undef NI_DGRAM 129 1.1 christos #undef NI_NUMERICSCOPE 130 1.1 christos 131 1.1 christos #define NI_NOFQDN 0x00000001 132 1.1 christos #define NI_NUMERICHOST 0x00000002 133 1.1 christos #define NI_NAMEREQD 0x00000004 134 1.1 christos #define NI_NUMERICSERV 0x00000008 135 1.1 christos #define NI_DGRAM 0x00000010 136 1.1 christos 137 1.1 christos /* 138 1.1 christos * Define to map into irs_ namespace. 139 1.1 christos */ 140 1.1 christos 141 1.1 christos #ifndef __NetBSD__ 142 1.1 christos #define IRS_NAMESPACE 143 1.1 christos #endif 144 1.1 christos 145 1.1 christos #ifdef IRS_NAMESPACE 146 1.1 christos 147 1.1 christos /* 148 1.1 christos * Use our versions not the ones from the C library. 149 1.1 christos */ 150 1.1 christos 151 1.1 christos #ifdef getnameinfo 152 1.1 christos #undef getnameinfo 153 1.1 christos #endif 154 1.1 christos #define getnameinfo irs_getnameinfo 155 1.1 christos 156 1.1 christos #ifdef getaddrinfo 157 1.1 christos #undef getaddrinfo 158 1.1 christos #endif 159 1.1 christos #define getaddrinfo irs_getaddrinfo 160 1.1 christos 161 1.1 christos #ifdef freeaddrinfo 162 1.1 christos #undef freeaddrinfo 163 1.1 christos #endif 164 1.1 christos #define freeaddrinfo irs_freeaddrinfo 165 1.1 christos 166 1.1 christos #ifdef gai_strerror 167 1.1 christos #undef gai_strerror 168 1.1 christos #endif 169 1.1 christos #define gai_strerror irs_gai_strerror 170 1.1 christos 171 1.1 christos int 172 1.1 christos getaddrinfo(const char *hostname, const char *servname, 173 1.1 christos const struct addrinfo *hints, struct addrinfo **res); 174 1.1 christos 175 1.1 christos int 176 1.1 christos getnameinfo(const struct sockaddr *sa, socklen_t salen, 177 1.1 christos char *host, socklen_t hostlen, 178 1.1 christos char *serv, socklen_t servlen, 179 1.1 christos int flags); 180 1.1 christos 181 1.1 christos void freeaddrinfo (struct addrinfo *ai); 182 1.1 christos 183 1.1 christos const char * 184 1.1 christos gai_strerror(int ecode); 185 1.1 christos 186 1.1 christos #endif /* IRS_NAMESPACE */ 187 1.1 christos 188 1.1 christos /* 189 1.1 christos * Tell Emacs to use C mode on this file. 190 1.1 christos * Local variables: 191 1.1 christos * mode: c 192 1.1 christos * End: 193 1.1 christos */ 194 1.1 christos 195 1.1 christos #endif /* IRS_NETDB_H */ 196