1 1.72 jkoshy /* $NetBSD: netdb.h,v 1.72 2024/02/16 11:13:59 jkoshy Exp $ */ 2 1.12 itojun 3 1.12 itojun /* 4 1.60 christos * ++Copyright++ 1980, 1983, 1988, 1993 5 1.60 christos * - 6 1.6 mrg * Copyright (c) 1980, 1983, 1988, 1993 7 1.6 mrg * The Regents of the University of California. All rights reserved. 8 1.1 cgd * 9 1.1 cgd * Redistribution and use in source and binary forms, with or without 10 1.1 cgd * modification, are permitted provided that the following conditions 11 1.1 cgd * are met: 12 1.1 cgd * 1. Redistributions of source code must retain the above copyright 13 1.1 cgd * notice, this list of conditions and the following disclaimer. 14 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 cgd * notice, this list of conditions and the following disclaimer in the 16 1.1 cgd * documentation and/or other materials provided with the distribution. 17 1.31 agc * 3. Neither the name of the University nor the names of its contributors 18 1.1 cgd * may be used to endorse or promote products derived from this software 19 1.1 cgd * without specific prior written permission. 20 1.1 cgd * 21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 1.1 cgd * SUCH DAMAGE. 32 1.6 mrg * - 33 1.6 mrg * Portions Copyright (c) 1993 by Digital Equipment Corporation. 34 1.39 christos * 35 1.6 mrg * Permission to use, copy, modify, and distribute this software for any 36 1.6 mrg * purpose with or without fee is hereby granted, provided that the above 37 1.6 mrg * copyright notice and this permission notice appear in all copies, and that 38 1.6 mrg * the name of Digital Equipment Corporation not be used in advertising or 39 1.6 mrg * publicity pertaining to distribution of the document or software without 40 1.6 mrg * specific, written prior permission. 41 1.39 christos * 42 1.6 mrg * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL 43 1.6 mrg * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES 44 1.6 mrg * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT 45 1.6 mrg * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 46 1.6 mrg * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 47 1.6 mrg * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 48 1.6 mrg * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 49 1.6 mrg * SOFTWARE. 50 1.6 mrg * - 51 1.39 christos * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 52 1.39 christos * All rights reserved. 53 1.39 christos * 54 1.39 christos * Redistribution and use in source and binary forms, with or without 55 1.39 christos * modification, are permitted provided that the following conditions 56 1.39 christos * are met: 57 1.39 christos * 1. Redistributions of source code must retain the above copyright 58 1.39 christos * notice, this list of conditions and the following disclaimer. 59 1.39 christos * 2. Redistributions in binary form must reproduce the above copyright 60 1.39 christos * notice, this list of conditions and the following disclaimer in the 61 1.39 christos * documentation and/or other materials provided with the distribution. 62 1.39 christos * 3. All advertising materials mentioning features or use of this software 63 1.39 christos * must display the following acknowledgement: 64 1.39 christos * This product includes software developed by WIDE Project and 65 1.39 christos * its contributors. 66 1.39 christos * 4. Neither the name of the project nor the names of its contributors 67 1.39 christos * may be used to endorse or promote products derived from this software 68 1.39 christos * without specific prior written permission. 69 1.39 christos * 70 1.39 christos * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 71 1.39 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 72 1.39 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 73 1.39 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 74 1.39 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 75 1.39 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 76 1.39 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 77 1.39 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 78 1.39 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 79 1.39 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 80 1.39 christos * SUCH DAMAGE. 81 1.39 christos * - 82 1.6 mrg * --Copyright-- 83 1.6 mrg */ 84 1.6 mrg 85 1.39 christos /* 86 1.39 christos * @(#)netdb.h 8.1 (Berkeley) 6/2/93 87 1.61 christos * Id: netdb.h,v 1.22 2008/02/28 05:34:17 marka Exp 88 1.39 christos */ 89 1.39 christos 90 1.1 cgd #ifndef _NETDB_H_ 91 1.39 christos #define _NETDB_H_ 92 1.1 cgd 93 1.66 joerg #include <sys/cdefs.h> 94 1.37 kleink #include <machine/endian_machdep.h> 95 1.23 kleink #include <sys/ansi.h> 96 1.29 bjh21 #include <sys/featuretest.h> 97 1.13 kleink #include <inttypes.h> 98 1.23 kleink /* 99 1.23 kleink * Data types 100 1.23 kleink */ 101 1.23 kleink #ifndef socklen_t 102 1.23 kleink typedef __socklen_t socklen_t; 103 1.39 christos #define socklen_t __socklen_t 104 1.23 kleink #endif 105 1.23 kleink 106 1.13 kleink #ifdef _BSD_SIZE_T_ 107 1.13 kleink typedef _BSD_SIZE_T_ size_t; 108 1.13 kleink #undef _BSD_SIZE_T_ 109 1.13 kleink #endif 110 1.11 kleink 111 1.29 bjh21 #if defined(_NETBSD_SOURCE) 112 1.39 christos #ifndef _PATH_HEQUIV 113 1.1 cgd #define _PATH_HEQUIV "/etc/hosts.equiv" 114 1.39 christos #endif 115 1.39 christos #ifndef _PATH_HOSTS 116 1.1 cgd #define _PATH_HOSTS "/etc/hosts" 117 1.39 christos #endif 118 1.39 christos #ifndef _PATH_NETWORKS 119 1.1 cgd #define _PATH_NETWORKS "/etc/networks" 120 1.39 christos #endif 121 1.39 christos #ifndef _PATH_PROTOCOLS 122 1.1 cgd #define _PATH_PROTOCOLS "/etc/protocols" 123 1.39 christos #endif 124 1.39 christos #ifndef _PATH_SERVICES 125 1.1 cgd #define _PATH_SERVICES "/etc/services" 126 1.11 kleink #endif 127 1.63 joerg #ifndef _PATH_SERVICES_CDB 128 1.63 joerg #define _PATH_SERVICES_CDB "/var/db/services.cdb" 129 1.63 joerg #endif 130 1.54 christos #ifndef _PATH_SERVICES_DB 131 1.59 christos #define _PATH_SERVICES_DB "/var/db/services.db" 132 1.54 christos #endif 133 1.39 christos #endif 134 1.1 cgd 135 1.39 christos __BEGIN_DECLS 136 1.6 mrg extern int h_errno; 137 1.61 christos extern int * __h_errno(void); 138 1.60 christos #ifdef _REENTRANT 139 1.60 christos #define h_errno (*__h_errno()) 140 1.60 christos #endif 141 1.39 christos __END_DECLS 142 1.6 mrg 143 1.56 christos /*% 144 1.1 cgd * Structures returned by network data base library. All addresses are 145 1.1 cgd * supplied in host order, and returned in network order (suitable for 146 1.1 cgd * use in system calls). 147 1.1 cgd */ 148 1.1 cgd struct hostent { 149 1.56 christos char *h_name; /*%< official name of host */ 150 1.56 christos char **h_aliases; /*%< alias list */ 151 1.56 christos int h_addrtype; /*%< host address type */ 152 1.56 christos int h_length; /*%< length of address */ 153 1.56 christos char **h_addr_list; /*%< list of addresses from name server */ 154 1.71 andvar #define h_addr h_addr_list[0] /*%< address, for backward compatibility */ 155 1.1 cgd }; 156 1.1 cgd 157 1.56 christos /*% 158 1.1 cgd * Assumption here is that a network number 159 1.6 mrg * fits in an unsigned long -- probably a poor one. 160 1.1 cgd */ 161 1.1 cgd struct netent { 162 1.56 christos char *n_name; /*%< official name of net */ 163 1.56 christos char **n_aliases; /*%< alias list */ 164 1.56 christos int n_addrtype; /*%< net address type */ 165 1.70 nia #if defined(__sparc__) && defined(_LP64) 166 1.37 kleink int __n_pad0; /* ABI compatibility */ 167 1.37 kleink #endif 168 1.56 christos uint32_t n_net; /*%< network # */ 169 1.70 nia #if defined(__alpha__) 170 1.37 kleink int __n_pad0; /* ABI compatibility */ 171 1.37 kleink #endif 172 1.1 cgd }; 173 1.1 cgd 174 1.1 cgd struct servent { 175 1.56 christos char *s_name; /*%< official service name */ 176 1.56 christos char **s_aliases; /*%< alias list */ 177 1.56 christos int s_port; /*%< port # */ 178 1.56 christos char *s_proto; /*%< protocol to use */ 179 1.1 cgd }; 180 1.1 cgd 181 1.1 cgd struct protoent { 182 1.56 christos char *p_name; /*%< official protocol name */ 183 1.56 christos char **p_aliases; /*%< alias list */ 184 1.56 christos int p_proto; /*%< protocol # */ 185 1.1 cgd }; 186 1.1 cgd 187 1.23 kleink /* 188 1.23 kleink * Note: ai_addrlen used to be a size_t, per RFC 2553. 189 1.23 kleink * In XNS5.2, and subsequently in POSIX-2001 and 190 1.23 kleink * draft-ietf-ipngwg-rfc2553bis-02.txt it was changed to a socklen_t. 191 1.55 christos * To accommodate for this while preserving binary compatibility with the 192 1.23 kleink * old interface, we prepend or append 32 bits of padding, depending on 193 1.23 kleink * the (LP64) architecture's endianness. 194 1.23 kleink * 195 1.23 kleink * This should be deleted the next time the libc major number is 196 1.23 kleink * incremented. 197 1.23 kleink */ 198 1.30 bjh21 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 199 1.30 bjh21 defined(_NETBSD_SOURCE) 200 1.12 itojun struct addrinfo { 201 1.56 christos int ai_flags; /*%< AI_PASSIVE, AI_CANONNAME */ 202 1.56 christos int ai_family; /*%< PF_xxx */ 203 1.56 christos int ai_socktype; /*%< SOCK_xxx */ 204 1.56 christos int ai_protocol; /*%< 0 or IPPROTO_xxx for IPv4 and IPv6 */ 205 1.38 kleink #if defined(__sparc__) && defined(_LP64) 206 1.57 christos int __ai_pad0; /* ABI compatibility */ 207 1.23 kleink #endif 208 1.56 christos socklen_t ai_addrlen; /*%< length of ai_addr */ 209 1.70 nia #if defined(__alpha__) 210 1.56 christos int __ai_pad0; /* ABI compatibility */ 211 1.23 kleink #endif 212 1.57 christos char *ai_canonname; /*%< canonical name for hostname */ 213 1.56 christos struct sockaddr *ai_addr; /*%< binary address */ 214 1.56 christos struct addrinfo *ai_next; /*%< next structure in linked list */ 215 1.12 itojun }; 216 1.13 kleink #endif 217 1.12 itojun 218 1.56 christos /*% 219 1.1 cgd * Error return codes from gethostbyname() and gethostbyaddr() 220 1.1 cgd * (left in extern int h_errno). 221 1.1 cgd */ 222 1.5 jtc 223 1.29 bjh21 #if defined(_NETBSD_SOURCE) 224 1.56 christos #define NETDB_INTERNAL -1 /*%< see errno */ 225 1.56 christos #define NETDB_SUCCESS 0 /*%< no problem */ 226 1.11 kleink #endif 227 1.56 christos #define NO_ADDRESS NO_DATA /* no address, look for MX record */ 228 1.56 christos #define HOST_NOT_FOUND 1 /*%< Authoritative Answer Host not found */ 229 1.56 christos #define TRY_AGAIN 2 /*%< Non-Authoritive Host not found, or SERVERFAIL */ 230 1.56 christos #define NO_RECOVERY 3 /*%< Non recoverable errors, FORMERR, REFUSED, NOTIMP */ 231 1.56 christos #define NO_DATA 4 /*%< Valid name, no data record of requested type */ 232 1.29 bjh21 #if defined(_NETBSD_SOURCE) 233 1.56 christos #define NO_ADDRESS NO_DATA /*%< no address, look for MX record */ 234 1.11 kleink #endif 235 1.1 cgd 236 1.12 itojun /* 237 1.12 itojun * Error return codes from getaddrinfo() 238 1.12 itojun */ 239 1.30 bjh21 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 240 1.30 bjh21 defined(_NETBSD_SOURCE) 241 1.56 christos #define EAI_ADDRFAMILY 1 /*%< address family for hostname not supported */ 242 1.56 christos #define EAI_AGAIN 2 /*%< temporary failure in name resolution */ 243 1.56 christos #define EAI_BADFLAGS 3 /*%< invalid value for ai_flags */ 244 1.56 christos #define EAI_FAIL 4 /*%< non-recoverable failure in name resolution */ 245 1.56 christos #define EAI_FAMILY 5 /*%< ai_family not supported */ 246 1.56 christos #define EAI_MEMORY 6 /*%< memory allocation failure */ 247 1.56 christos #define EAI_NODATA 7 /*%< no address associated with hostname */ 248 1.56 christos #define EAI_NONAME 8 /*%< hostname nor servname provided, or not known */ 249 1.56 christos #define EAI_SERVICE 9 /*%< servname not supported for ai_socktype */ 250 1.56 christos #define EAI_SOCKTYPE 10 /*%< ai_socktype not supported */ 251 1.56 christos #define EAI_SYSTEM 11 /*%< system error returned in errno */ 252 1.53 ginsbach #define EAI_BADHINTS 12 /* invalid value for hints */ 253 1.53 ginsbach #define EAI_PROTOCOL 13 /* resolved protocol is unknown */ 254 1.53 ginsbach #define EAI_OVERFLOW 14 /* argument buffer overflow */ 255 1.53 ginsbach #define EAI_MAX 15 256 1.30 bjh21 #endif /* _POSIX_C_SOURCE >= 200112 || _XOPEN_SOURCE >= 520 || _NETBSD_SOURCE */ 257 1.12 itojun 258 1.56 christos /*% 259 1.12 itojun * Flag values for getaddrinfo() 260 1.12 itojun */ 261 1.30 bjh21 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 262 1.30 bjh21 defined(_NETBSD_SOURCE) 263 1.12 itojun #define AI_PASSIVE 0x00000001 /* get address to use bind() */ 264 1.12 itojun #define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 265 1.35 itojun #define AI_NUMERICHOST 0x00000004 /* prevent host name resolution */ 266 1.35 itojun #define AI_NUMERICSERV 0x00000008 /* prevent service name resolution */ 267 1.67 christos #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 268 1.35 itojun /* valid flags for addrinfo (not a standard def, apps should not use it) */ 269 1.67 christos #ifdef _NETBSD_SOURCE 270 1.67 christos #define AI_SRV 0x00000800 /* do _srv lookups */ 271 1.67 christos #define AI_MASK \ 272 1.67 christos (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ 273 1.67 christos AI_ADDRCONFIG | AI_SRV) 274 1.67 christos #else 275 1.35 itojun #define AI_MASK \ 276 1.65 christos (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \ 277 1.65 christos AI_ADDRCONFIG) 278 1.41 christos #endif 279 1.68 riz #endif 280 1.12 itojun 281 1.30 bjh21 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 282 1.30 bjh21 defined(_NETBSD_SOURCE) 283 1.56 christos /*% 284 1.12 itojun * Constants for getnameinfo() 285 1.12 itojun */ 286 1.29 bjh21 #if defined(_NETBSD_SOURCE) 287 1.12 itojun #define NI_MAXHOST 1025 288 1.12 itojun #define NI_MAXSERV 32 289 1.22 kleink #endif 290 1.12 itojun 291 1.56 christos /*% 292 1.12 itojun * Flag values for getnameinfo() 293 1.12 itojun */ 294 1.12 itojun #define NI_NOFQDN 0x00000001 295 1.12 itojun #define NI_NUMERICHOST 0x00000002 296 1.12 itojun #define NI_NAMEREQD 0x00000004 297 1.12 itojun #define NI_NUMERICSERV 0x00000008 298 1.12 itojun #define NI_DGRAM 0x00000010 299 1.72 jkoshy #define NI_WITHSCOPEID 0x00000020 /* Obsolete. */ 300 1.39 christos #define NI_NUMERICSCOPE 0x00000040 301 1.14 itojun 302 1.56 christos /*% 303 1.14 itojun * Scope delimit character 304 1.14 itojun */ 305 1.29 bjh21 #if defined(_NETBSD_SOURCE) 306 1.39 christos #define SCOPE_DELIMITER '%' 307 1.22 kleink #endif 308 1.30 bjh21 #endif /* (_POSIX_C_SOURCE - 0) >= 200112L || ... */ 309 1.18 itojun 310 1.1 cgd __BEGIN_DECLS 311 1.48 perry void endhostent(void); 312 1.48 perry void endnetent(void); 313 1.48 perry void endprotoent(void); 314 1.48 perry void endservent(void); 315 1.44 ginsbach #if (_XOPEN_SOURCE - 0) >= 520 && (_XOPEN_SOURCE - 0) < 600 || \ 316 1.44 ginsbach defined(_NETBSD_SOURCE) 317 1.44 ginsbach #if 0 /* we do not ship this */ 318 1.48 perry void freehostent(struct hostent *); 319 1.44 ginsbach #endif 320 1.44 ginsbach #endif 321 1.69 christos struct hostent *gethostbyaddr(const void *, socklen_t, int); 322 1.48 perry struct hostent *gethostbyname(const char *); 323 1.29 bjh21 #if defined(_NETBSD_SOURCE) 324 1.48 perry struct hostent *gethostbyname2(const char *, int); 325 1.11 kleink #endif 326 1.48 perry struct hostent *gethostent(void); 327 1.48 perry struct netent *getnetbyaddr(uint32_t, int); 328 1.48 perry struct netent *getnetbyname(const char *); 329 1.48 perry struct netent *getnetent(void); 330 1.48 perry struct protoent *getprotobyname(const char *); 331 1.48 perry struct protoent *getprotobynumber(int); 332 1.48 perry struct protoent *getprotoent(void); 333 1.48 perry struct servent *getservbyname(const char *, const char *); 334 1.48 perry struct servent *getservbyport(int, const char *); 335 1.48 perry struct servent *getservent(void); 336 1.29 bjh21 #if defined(_NETBSD_SOURCE) 337 1.48 perry void herror(const char *); 338 1.48 perry const char *hstrerror(int); 339 1.11 kleink #endif 340 1.48 perry void sethostent(int); 341 1.29 bjh21 #if defined(_NETBSD_SOURCE) 342 1.48 perry /* void sethostfile(const char *); */ 343 1.11 kleink #endif 344 1.48 perry void setnetent(int); 345 1.48 perry void setprotoent(int); 346 1.64 christos void setservent(int); 347 1.30 bjh21 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \ 348 1.30 bjh21 defined(_NETBSD_SOURCE) 349 1.50 kleink int getaddrinfo(const char * __restrict, const char * __restrict, 350 1.50 kleink const struct addrinfo * __restrict, 351 1.50 kleink struct addrinfo ** __restrict); 352 1.50 kleink int getnameinfo(const struct sockaddr * __restrict, socklen_t, 353 1.50 kleink char * __restrict, socklen_t, 354 1.50 kleink char * __restrict, socklen_t, int); 355 1.62 tsarna struct addrinfo *allocaddrinfo(socklen_t); 356 1.48 perry void freeaddrinfo(struct addrinfo *); 357 1.48 perry const char *gai_strerror(int); 358 1.13 kleink #endif 359 1.1 cgd __END_DECLS 360 1.1 cgd 361 1.1 cgd #endif /* !_NETDB_H_ */ 362