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