netdb.h revision 203964
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.
13203964Simp * 3. Neither the name of the University nor the names of its contributors
141539Srgrimes *    may be used to endorse or promote products derived from this software
151539Srgrimes *    without specific prior written permission.
161539Srgrimes *
171539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271539Srgrimes * SUCH DAMAGE.
281539Srgrimes *
291539Srgrimes * -
301539Srgrimes * Portions Copyright (c) 1993 by Digital Equipment Corporation.
318858Srgrimes *
321539Srgrimes * Permission to use, copy, modify, and distribute this software for any
331539Srgrimes * purpose with or without fee is hereby granted, provided that the above
341539Srgrimes * copyright notice and this permission notice appear in all copies, and that
351539Srgrimes * the name of Digital Equipment Corporation not be used in advertising or
361539Srgrimes * publicity pertaining to distribution of the document or software without
371539Srgrimes * specific, written prior permission.
388858Srgrimes *
391539Srgrimes * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
401539Srgrimes * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
411539Srgrimes * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
421539Srgrimes * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
431539Srgrimes * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
441539Srgrimes * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
451539Srgrimes * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
461539Srgrimes * SOFTWARE.
471539Srgrimes * -
481539Srgrimes * --Copyright--
491539Srgrimes */
501539Srgrimes
5136888Speter/*
5236888Speter *      @(#)netdb.h	8.1 (Berkeley) 6/2/93
5336888Speter *      From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
5450473Speter * $FreeBSD: head/include/netdb.h 203964 2010-02-16 19:39:50Z imp $
5536888Speter */
5636888Speter
571539Srgrimes#ifndef _NETDB_H_
581539Srgrimes#define _NETDB_H_
591539Srgrimes
6084463Sbde#include <sys/cdefs.h>
61102227Smike#include <sys/_types.h>
6221055Speter
63102227Smike#ifndef _SIZE_T_DECLARED
64102227Smiketypedef	__size_t	size_t;
65102227Smike#define	_SIZE_T_DECLARED
6672510Sume#endif
6772510Sume
68102227Smike#ifndef _SOCKLEN_T_DECLARED
69102227Smiketypedef	__socklen_t	socklen_t;
70102227Smike#define	_SOCKLEN_T_DECLARED
7184463Sbde#endif
7284463Sbde
73146244Sume#ifndef _UINT32_T_DECLARED
74146244Sumetypedef	__uint32_t	uint32_t;
75146244Sume#define	_UINT32_T_DECLARED
76146244Sume#endif
77146244Sume
7836888Speter#ifndef _PATH_HEQUIV
7936888Speter# define	_PATH_HEQUIV	"/etc/hosts.equiv"
8036888Speter#endif
811539Srgrimes#define	_PATH_HOSTS	"/etc/hosts"
821539Srgrimes#define	_PATH_NETWORKS	"/etc/networks"
831539Srgrimes#define	_PATH_PROTOCOLS	"/etc/protocols"
841539Srgrimes#define	_PATH_SERVICES	"/etc/services"
851539Srgrimes
86156960Sume#define	h_errno (*__h_errno())
8710132Speter
881539Srgrimes/*
891539Srgrimes * Structures returned by network data base library.  All addresses are
901539Srgrimes * supplied in host order, and returned in network order (suitable for
911539Srgrimes * use in system calls).
921539Srgrimes */
9383047Sobrienstruct hostent {
941539Srgrimes	char	*h_name;	/* official name of host */
951539Srgrimes	char	**h_aliases;	/* alias list */
961539Srgrimes	int	h_addrtype;	/* host address type */
971539Srgrimes	int	h_length;	/* length of address */
981539Srgrimes	char	**h_addr_list;	/* list of addresses from name server */
9913771Smpp#define	h_addr	h_addr_list[0]	/* address, for backward compatibility */
1001539Srgrimes};
1011539Srgrimes
10283047Sobrienstruct netent {
1031539Srgrimes	char		*n_name;	/* official name of net */
1041539Srgrimes	char		**n_aliases;	/* alias list */
1051539Srgrimes	int		n_addrtype;	/* net address type */
106146244Sume	uint32_t	n_net;		/* network # */
1071539Srgrimes};
1081539Srgrimes
10983047Sobrienstruct servent {
1101539Srgrimes	char	*s_name;	/* official service name */
1111539Srgrimes	char	**s_aliases;	/* alias list */
1121539Srgrimes	int	s_port;		/* port # */
1131539Srgrimes	char	*s_proto;	/* protocol to use */
1141539Srgrimes};
1151539Srgrimes
11683047Sobrienstruct protoent {
1171539Srgrimes	char	*p_name;	/* official protocol name */
1181539Srgrimes	char	**p_aliases;	/* alias list */
1191539Srgrimes	int	p_proto;	/* protocol # */
1201539Srgrimes};
1211539Srgrimes
12255163Sshinstruct addrinfo {
12355163Sshin	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
12455163Sshin	int	ai_family;	/* PF_xxx */
12555163Sshin	int	ai_socktype;	/* SOCK_xxx */
12655163Sshin	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
127146244Sume	socklen_t ai_addrlen;	/* length of ai_addr */
12855163Sshin	char	*ai_canonname;	/* canonical name for hostname */
12955163Sshin	struct	sockaddr *ai_addr;	/* binary address */
13055163Sshin	struct	addrinfo *ai_next;	/* next structure in linked list */
13155163Sshin};
13255163Sshin
1331539Srgrimes/*
1341539Srgrimes * Error return codes from gethostbyname() and gethostbyaddr()
135126243Sgreen * (left in h_errno).
1361539Srgrimes */
1371539Srgrimes
13810132Speter#define	NETDB_INTERNAL	-1	/* see errno */
13910132Speter#define	NETDB_SUCCESS	0	/* no problem */
1401539Srgrimes#define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
14113771Smpp#define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */
1421539Srgrimes#define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
1431539Srgrimes#define	NO_DATA		4 /* Valid name, no data record of requested type */
1441539Srgrimes#define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
1451539Srgrimes
14655163Sshin/*
14755163Sshin * Error return codes from getaddrinfo()
14855163Sshin */
149121430Sume#if 0
150121430Sume/* obsoleted */
15155163Sshin#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
152121430Sume#endif
15355163Sshin#define	EAI_AGAIN	 2	/* temporary failure in name resolution */
15455163Sshin#define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
15555163Sshin#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
15655163Sshin#define	EAI_FAMILY	 5	/* ai_family not supported */
15755163Sshin#define	EAI_MEMORY	 6	/* memory allocation failure */
158121430Sume#if 0
159121430Sume/* obsoleted */
16055163Sshin#define	EAI_NODATA	 7	/* no address associated with hostname */
161121430Sume#endif
16255163Sshin#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
16355163Sshin#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
16455163Sshin#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
16555163Sshin#define	EAI_SYSTEM	11	/* system error returned in errno */
166158790Sume#define	EAI_BADHINTS	12	/* invalid value for hints */
167158790Sume#define	EAI_PROTOCOL	13	/* resolved protocol is unknown */
168158790Sume#define	EAI_OVERFLOW	14	/* argument buffer overflow */
169158790Sume#define	EAI_MAX		15
17055163Sshin
17155163Sshin/*
17255163Sshin * Flag values for getaddrinfo()
17355163Sshin */
17455163Sshin#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
17555163Sshin#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
176140908Sume#define	AI_NUMERICHOST	0x00000004 /* prevent host name resolution */
177140908Sume#define	AI_NUMERICSERV	0x00000008 /* prevent service name resolution */
178140908Sume/* valid flags for addrinfo (not a standard def, apps should not use it) */
17972693Sume#define AI_MASK \
180140908Sume    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
181140908Sume    AI_ADDRCONFIG)
18255163Sshin
18355163Sshin#define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
18455163Sshin#define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */
18555163Sshin#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
18655163Sshin#define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */
18755163Sshin/* special recommended flags for getipnodebyname */
18855163Sshin#define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
18955163Sshin
19055163Sshin/*
19155163Sshin * Constants for getnameinfo()
19255163Sshin */
19355163Sshin#define	NI_MAXHOST	1025
19455163Sshin#define	NI_MAXSERV	32
19555163Sshin
19655163Sshin/*
19755163Sshin * Flag values for getnameinfo()
19855163Sshin */
19955163Sshin#define	NI_NOFQDN	0x00000001
20055163Sshin#define	NI_NUMERICHOST	0x00000002
20155163Sshin#define	NI_NAMEREQD	0x00000004
20255163Sshin#define	NI_NUMERICSERV	0x00000008
20355163Sshin#define	NI_DGRAM	0x00000010
204146690Sume#if 0 /* obsolete */
20555163Sshin#define NI_WITHSCOPEID	0x00000020
206121316Sume#endif
20755163Sshin
20855163Sshin/*
20955163Sshin * Scope delimit character
21055163Sshin */
21157033Sshin#define	SCOPE_DELIMITER	'%'
21255163Sshin
2131539Srgrimes__BEGIN_DECLS
21493032Simpvoid		endhostent(void);
21593032Simpvoid		endnetent(void);
21693032Simpvoid		endprotoent(void);
21793032Simpvoid		endservent(void);
218189826Sdas#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112)
219189826Sdasstruct hostent	*gethostbyaddr(const void *, socklen_t, int);
220189826Sdasstruct hostent	*gethostbyname(const char *);
221189826Sdas#endif
222189826Sdasstruct hostent	*gethostent(void);
223189826Sdasstruct netent	*getnetbyaddr(uint32_t, int);
224189826Sdasstruct netent	*getnetbyname(const char *);
225189826Sdasstruct netent	*getnetent(void);
226189826Sdasstruct protoent	*getprotobyname(const char *);
227189826Sdasstruct protoent	*getprotobynumber(int);
228189826Sdasstruct protoent	*getprotoent(void);
229189826Sdasstruct servent	*getservbyname(const char *, const char *);
230189826Sdasstruct servent	*getservbyport(int, const char *);
231189826Sdasstruct servent	*getservent(void);
232189826Sdasvoid		sethostent(int);
233189826Sdas/* void		sethostfile(const char *); */
234189826Sdasvoid		setnetent(int);
235189826Sdasvoid		setprotoent(int);
236189826Sdasint		getaddrinfo(const char *, const char *,
237189826Sdas			    const struct addrinfo *, struct addrinfo **);
238189826Sdasint		getnameinfo(const struct sockaddr *, socklen_t, char *,
239189826Sdas			    size_t, char *, size_t, int);
240189826Sdasvoid		freeaddrinfo(struct addrinfo *);
241189826Sdasconst char	*gai_strerror(int);
242189826Sdasvoid		setservent(int);
243189826Sdas
244189826Sdas#if __BSD_VISIBLE
245189826Sdasvoid		endnetgrent(void);
24693032Simpvoid		freehostent(struct hostent *);
247158477Sumeint		gethostbyaddr_r(const void *, socklen_t, int, struct hostent *,
248158477Sume    char *, size_t, struct hostent **, int *);
249157779Sumeint		gethostbyname_r(const char *, struct hostent *, char *, size_t,
250157779Sume    struct hostent **, int *);
25193032Simpstruct hostent	*gethostbyname2(const char *, int);
252157779Sumeint		gethostbyname2_r(const char *, int, struct hostent *, char *,
253157779Sume    size_t, struct hostent **, int *);
254157779Sumeint		gethostent_r(struct hostent *, char *, size_t,
255157779Sume    struct hostent **, int *);
25693032Simpstruct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
25793032Simpstruct hostent	*getipnodebyname(const char *, int, int, int *);
258157779Sumeint		getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t,
259157779Sume    struct netent**, int *);
260157779Sumeint		getnetbyname_r(const char *, struct netent *, char *, size_t,
261157779Sume    struct netent **, int *);
262157779Sumeint		getnetent_r(struct netent *, char *, size_t, struct netent **,
263157779Sume    int *);
26493032Simpint		getnetgrent(char **, char **, char **);
265157779Sumeint		getprotobyname_r(const char *, struct protoent *, char *,
266157779Sume    size_t, struct protoent **);
267157779Sumeint		getprotobynumber_r(int, struct protoent *, char *, size_t,
268157779Sume    struct protoent **);
269157779Sumeint		getprotoent_r(struct protoent *, char *, size_t,
270157779Sume    struct protoent **);
271157779Sumeint		getservbyname_r(const char *, const char *, struct servent *,
272157779Sume    char *, size_t, struct servent **);
273157779Sumeint		getservbyport_r(int, const char *, struct servent *, char *,
274157779Sume    size_t, struct servent **);
275157779Sumeint		getservent_r(struct servent *, char *, size_t,
276157779Sume    struct servent **);
27793032Simpvoid		herror(const char *);
27893032Simp__const char	*hstrerror(int);
27993032Simpint		innetgr(const char *, const char *, const char *, const char *);
28093032Simpvoid		setnetgrent(const char *);
281189826Sdas#endif
28217902Speter
283189826Sdas
28417902Speter/*
28517902Speter * PRIVATE functions specific to the FreeBSD implementation
28617902Speter */
28717902Speter
28817902Speter/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */
289156960Sumeint	* __h_errno(void);
2901539Srgrimes__END_DECLS
2911539Srgrimes
2921539Srgrimes#endif /* !_NETDB_H_ */
293