netdb.h revision 158477
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1980, 1983, 1988, 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes * 1. Redistributions of source code must retain the above copyright
91539Srgrimes *    notice, this list of conditions and the following disclaimer.
101539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111539Srgrimes *    notice, this list of conditions and the following disclaimer in the
121539Srgrimes *    documentation and/or other materials provided with the distribution.
131539Srgrimes * 3. All advertising materials mentioning features or use of this software
141539Srgrimes *    must display the following acknowledgement:
151539Srgrimes *	This product includes software developed by the University of
161539Srgrimes *	California, Berkeley and its contributors.
171539Srgrimes * 4. Neither the name of the University nor the names of its contributors
181539Srgrimes *    may be used to endorse or promote products derived from this software
191539Srgrimes *    without specific prior written permission.
201539Srgrimes *
211539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311539Srgrimes * SUCH DAMAGE.
321539Srgrimes *
331539Srgrimes * -
341539Srgrimes * Portions Copyright (c) 1993 by Digital Equipment Corporation.
358858Srgrimes *
361539Srgrimes * Permission to use, copy, modify, and distribute this software for any
371539Srgrimes * purpose with or without fee is hereby granted, provided that the above
381539Srgrimes * copyright notice and this permission notice appear in all copies, and that
391539Srgrimes * the name of Digital Equipment Corporation not be used in advertising or
401539Srgrimes * publicity pertaining to distribution of the document or software without
411539Srgrimes * specific, written prior permission.
428858Srgrimes *
431539Srgrimes * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
441539Srgrimes * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
451539Srgrimes * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
461539Srgrimes * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
471539Srgrimes * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
481539Srgrimes * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
491539Srgrimes * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
501539Srgrimes * SOFTWARE.
511539Srgrimes * -
521539Srgrimes * --Copyright--
531539Srgrimes */
541539Srgrimes
5536888Speter/*
5636888Speter *      @(#)netdb.h	8.1 (Berkeley) 6/2/93
5736888Speter *      From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
5850473Speter * $FreeBSD: head/include/netdb.h 158477 2006-05-12 15:37:23Z ume $
5936888Speter */
6036888Speter
611539Srgrimes#ifndef _NETDB_H_
621539Srgrimes#define _NETDB_H_
631539Srgrimes
6484463Sbde#include <sys/cdefs.h>
65102227Smike#include <sys/_types.h>
66158477Sume#include <machine/_limits.h>
6721055Speter
68102227Smike#ifndef _SIZE_T_DECLARED
69102227Smiketypedef	__size_t	size_t;
70102227Smike#define	_SIZE_T_DECLARED
7172510Sume#endif
7272510Sume
73102227Smike#ifndef _SOCKLEN_T_DECLARED
74102227Smiketypedef	__socklen_t	socklen_t;
75102227Smike#define	_SOCKLEN_T_DECLARED
7684463Sbde#endif
7784463Sbde
78146244Sume#ifndef _UINT32_T_DECLARED
79146244Sumetypedef	__uint32_t	uint32_t;
80146244Sume#define	_UINT32_T_DECLARED
81146244Sume#endif
82146244Sume
8336888Speter#ifndef _PATH_HEQUIV
8436888Speter# define	_PATH_HEQUIV	"/etc/hosts.equiv"
8536888Speter#endif
861539Srgrimes#define	_PATH_HOSTS	"/etc/hosts"
871539Srgrimes#define	_PATH_NETWORKS	"/etc/networks"
881539Srgrimes#define	_PATH_PROTOCOLS	"/etc/protocols"
891539Srgrimes#define	_PATH_SERVICES	"/etc/services"
901539Srgrimes
91156960Sume#define	h_errno (*__h_errno())
9210132Speter
931539Srgrimes/*
941539Srgrimes * Structures returned by network data base library.  All addresses are
951539Srgrimes * supplied in host order, and returned in network order (suitable for
961539Srgrimes * use in system calls).
971539Srgrimes */
9883047Sobrienstruct hostent {
991539Srgrimes	char	*h_name;	/* official name of host */
1001539Srgrimes	char	**h_aliases;	/* alias list */
1011539Srgrimes	int	h_addrtype;	/* host address type */
1021539Srgrimes	int	h_length;	/* length of address */
1031539Srgrimes	char	**h_addr_list;	/* list of addresses from name server */
10413771Smpp#define	h_addr	h_addr_list[0]	/* address, for backward compatibility */
1051539Srgrimes};
1061539Srgrimes
10783047Sobrienstruct netent {
1081539Srgrimes	char		*n_name;	/* official name of net */
1091539Srgrimes	char		**n_aliases;	/* alias list */
1101539Srgrimes	int		n_addrtype;	/* net address type */
111146244Sume	uint32_t	n_net;		/* network # */
1121539Srgrimes};
1131539Srgrimes
11483047Sobrienstruct servent {
1151539Srgrimes	char	*s_name;	/* official service name */
1161539Srgrimes	char	**s_aliases;	/* alias list */
1171539Srgrimes	int	s_port;		/* port # */
1181539Srgrimes	char	*s_proto;	/* protocol to use */
1191539Srgrimes};
1201539Srgrimes
12183047Sobrienstruct protoent {
1221539Srgrimes	char	*p_name;	/* official protocol name */
1231539Srgrimes	char	**p_aliases;	/* alias list */
1241539Srgrimes	int	p_proto;	/* protocol # */
1251539Srgrimes};
1261539Srgrimes
12755163Sshinstruct addrinfo {
12855163Sshin	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
12955163Sshin	int	ai_family;	/* PF_xxx */
13055163Sshin	int	ai_socktype;	/* SOCK_xxx */
13155163Sshin	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
132146244Sume	socklen_t ai_addrlen;	/* length of ai_addr */
13355163Sshin	char	*ai_canonname;	/* canonical name for hostname */
13455163Sshin	struct	sockaddr *ai_addr;	/* binary address */
13555163Sshin	struct	addrinfo *ai_next;	/* next structure in linked list */
13655163Sshin};
13755163Sshin
1381539Srgrimes/*
1391539Srgrimes * Error return codes from gethostbyname() and gethostbyaddr()
140126243Sgreen * (left in h_errno).
1411539Srgrimes */
1421539Srgrimes
14310132Speter#define	NETDB_INTERNAL	-1	/* see errno */
14410132Speter#define	NETDB_SUCCESS	0	/* no problem */
1451539Srgrimes#define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
14613771Smpp#define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */
1471539Srgrimes#define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
1481539Srgrimes#define	NO_DATA		4 /* Valid name, no data record of requested type */
1491539Srgrimes#define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
1501539Srgrimes
15155163Sshin/*
15255163Sshin * Error return codes from getaddrinfo()
15355163Sshin */
154121430Sume#if 0
155121430Sume/* obsoleted */
15655163Sshin#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
157121430Sume#endif
15855163Sshin#define	EAI_AGAIN	 2	/* temporary failure in name resolution */
15955163Sshin#define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
16055163Sshin#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
16155163Sshin#define	EAI_FAMILY	 5	/* ai_family not supported */
16255163Sshin#define	EAI_MEMORY	 6	/* memory allocation failure */
163121430Sume#if 0
164121430Sume/* obsoleted */
16555163Sshin#define	EAI_NODATA	 7	/* no address associated with hostname */
166121430Sume#endif
16755163Sshin#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
16855163Sshin#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
16955163Sshin#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
17055163Sshin#define	EAI_SYSTEM	11	/* system error returned in errno */
17155163Sshin#define	EAI_BADHINTS	12
17255163Sshin#define	EAI_PROTOCOL	13
17374393Sume#define	EAI_MAX		14
17455163Sshin
17555163Sshin/*
17655163Sshin * Flag values for getaddrinfo()
17755163Sshin */
17855163Sshin#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
17955163Sshin#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
180140908Sume#define	AI_NUMERICHOST	0x00000004 /* prevent host name resolution */
181140908Sume#define	AI_NUMERICSERV	0x00000008 /* prevent service name resolution */
182140908Sume/* valid flags for addrinfo (not a standard def, apps should not use it) */
18372693Sume#define AI_MASK \
184140908Sume    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
185140908Sume    AI_ADDRCONFIG)
18655163Sshin
18755163Sshin#define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
18855163Sshin#define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */
18955163Sshin#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
19055163Sshin#define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */
19155163Sshin/* special recommended flags for getipnodebyname */
19255163Sshin#define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
19355163Sshin
19455163Sshin/*
19555163Sshin * Constants for getnameinfo()
19655163Sshin */
19755163Sshin#define	NI_MAXHOST	1025
19855163Sshin#define	NI_MAXSERV	32
19955163Sshin
20055163Sshin/*
20155163Sshin * Flag values for getnameinfo()
20255163Sshin */
20355163Sshin#define	NI_NOFQDN	0x00000001
20455163Sshin#define	NI_NUMERICHOST	0x00000002
20555163Sshin#define	NI_NAMEREQD	0x00000004
20655163Sshin#define	NI_NUMERICSERV	0x00000008
20755163Sshin#define	NI_DGRAM	0x00000010
208146690Sume#if 0 /* obsolete */
20955163Sshin#define NI_WITHSCOPEID	0x00000020
210121316Sume#endif
21155163Sshin
21255163Sshin/*
21355163Sshin * Scope delimit character
21455163Sshin */
21557033Sshin#define	SCOPE_DELIMITER	'%'
21655163Sshin
2171539Srgrimes__BEGIN_DECLS
21893032Simpvoid		endhostent(void);
21993032Simpvoid		endnetent(void);
22093032Simpvoid		endnetgrent(void);
22193032Simpvoid		endprotoent(void);
22293032Simpvoid		endservent(void);
22393032Simpvoid		freehostent(struct hostent *);
224158477Sume#if __LONG_BIT == 64
225158477Sumestruct hostent	*gethostbyaddr(const void *, int, int);
226158477Sumeint		gethostbyaddr_r(const void *, int, int, struct hostent *,
227157779Sume    char *, size_t, struct hostent **, int *);
228158477Sume#else
229158477Sumestruct hostent	*gethostbyaddr(const void *, socklen_t, int);
230158477Sumeint		gethostbyaddr_r(const void *, socklen_t, int, struct hostent *,
231158477Sume    char *, size_t, struct hostent **, int *);
232158477Sume#endif
23393032Simpstruct hostent	*gethostbyname(const char *);
234157779Sumeint		gethostbyname_r(const char *, struct hostent *, char *, size_t,
235157779Sume    struct hostent **, int *);
23693032Simpstruct hostent	*gethostbyname2(const char *, int);
237157779Sumeint		gethostbyname2_r(const char *, int, struct hostent *, char *,
238157779Sume    size_t, struct hostent **, int *);
23993032Simpstruct hostent	*gethostent(void);
240157779Sumeint		gethostent_r(struct hostent *, char *, size_t,
241157779Sume    struct hostent **, int *);
24293032Simpstruct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
24393032Simpstruct hostent	*getipnodebyname(const char *, int, int, int *);
244146244Sumestruct netent	*getnetbyaddr(uint32_t, int);
245157779Sumeint		getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t,
246157779Sume    struct netent**, int *);
24793032Simpstruct netent	*getnetbyname(const char *);
248157779Sumeint		getnetbyname_r(const char *, struct netent *, char *, size_t,
249157779Sume    struct netent **, int *);
25093032Simpstruct netent	*getnetent(void);
251157779Sumeint		getnetent_r(struct netent *, char *, size_t, struct netent **,
252157779Sume    int *);
25393032Simpint		getnetgrent(char **, char **, char **);
25493032Simpstruct protoent	*getprotobyname(const char *);
255157779Sumeint		getprotobyname_r(const char *, struct protoent *, char *,
256157779Sume    size_t, struct protoent **);
25793032Simpstruct protoent	*getprotobynumber(int);
258157779Sumeint		getprotobynumber_r(int, struct protoent *, char *, size_t,
259157779Sume    struct protoent **);
26093032Simpstruct protoent	*getprotoent(void);
261157779Sumeint		getprotoent_r(struct protoent *, char *, size_t,
262157779Sume    struct protoent **);
26393032Simpstruct servent	*getservbyname(const char *, const char *);
264157779Sumeint		getservbyname_r(const char *, const char *, struct servent *,
265157779Sume    char *, size_t, struct servent **);
26693032Simpstruct servent	*getservbyport(int, const char *);
267157779Sumeint		getservbyport_r(int, const char *, struct servent *, char *,
268157779Sume    size_t, struct servent **);
26993032Simpstruct servent	*getservent(void);
270157779Sumeint		getservent_r(struct servent *, char *, size_t,
271157779Sume    struct servent **);
27293032Simpvoid		herror(const char *);
27393032Simp__const char	*hstrerror(int);
27493032Simpint		innetgr(const char *, const char *, const char *, const char *);
27593032Simpvoid		sethostent(int);
27693032Simp/* void		sethostfile(const char *); */
27793032Simpvoid		setnetent(int);
27893032Simpvoid		setprotoent(int);
27993032Simpint		getaddrinfo(const char *, const char *,
28093032Simp			    const struct addrinfo *, struct addrinfo **);
28193032Simpint		getnameinfo(const struct sockaddr *, socklen_t, char *,
28293032Simp			    size_t, char *, size_t, int);
28393032Simpvoid		freeaddrinfo(struct addrinfo *);
284141908Sphantomconst char	*gai_strerror(int);
28593032Simpvoid		setnetgrent(const char *);
28693032Simpvoid		setservent(int);
28717902Speter
28817902Speter/*
28917902Speter * PRIVATE functions specific to the FreeBSD implementation
29017902Speter */
29117902Speter
29217902Speter/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */
293156960Sumeint	* __h_errno(void);
2941539Srgrimes__END_DECLS
2951539Srgrimes
2961539Srgrimes#endif /* !_NETDB_H_ */
297