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