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