netdb.h revision 93032
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 93032 2002-03-23 17:24:55Z imp $
5936888Speter */
6036888Speter
611539Srgrimes#ifndef _NETDB_H_
621539Srgrimes#define _NETDB_H_
631539Srgrimes
6484463Sbde#include <sys/cdefs.h>
6572510Sume#include <machine/ansi.h>
6621055Speter
6772510Sume#ifdef	_BSD_SIZE_T_
6872510Sumetypedef	_BSD_SIZE_T_	size_t;
6972510Sume#undef	_BSD_SIZE_T_
7072510Sume#endif
7172510Sume
7284463Sbde#ifdef	_BSD_SOCKLEN_T_
7384463Sbdetypedef	_BSD_SOCKLEN_T_	socklen_t;
7484463Sbde#undef	_BSD_SOCKLEN_T_
7584463Sbde#endif
7684463Sbde
7736888Speter#ifndef _PATH_HEQUIV
7836888Speter# define	_PATH_HEQUIV	"/etc/hosts.equiv"
7936888Speter#endif
801539Srgrimes#define	_PATH_HOSTS	"/etc/hosts"
811539Srgrimes#define	_PATH_NETWORKS	"/etc/networks"
821539Srgrimes#define	_PATH_PROTOCOLS	"/etc/protocols"
831539Srgrimes#define	_PATH_SERVICES	"/etc/services"
841539Srgrimes
8510132Speterextern int h_errno;
8610132Speter
871539Srgrimes/*
881539Srgrimes * Structures returned by network data base library.  All addresses are
891539Srgrimes * supplied in host order, and returned in network order (suitable for
901539Srgrimes * use in system calls).
911539Srgrimes */
9283047Sobrienstruct hostent {
931539Srgrimes	char	*h_name;	/* official name of host */
941539Srgrimes	char	**h_aliases;	/* alias list */
951539Srgrimes	int	h_addrtype;	/* host address type */
961539Srgrimes	int	h_length;	/* length of address */
971539Srgrimes	char	**h_addr_list;	/* list of addresses from name server */
9813771Smpp#define	h_addr	h_addr_list[0]	/* address, for backward compatibility */
991539Srgrimes};
1001539Srgrimes
1011539Srgrimes/*
1021539Srgrimes * Assumption here is that a network number
1031539Srgrimes * fits in an unsigned long -- probably a poor one.
1041539Srgrimes */
10583047Sobrienstruct netent {
1061539Srgrimes	char		*n_name;	/* official name of net */
1071539Srgrimes	char		**n_aliases;	/* alias list */
1081539Srgrimes	int		n_addrtype;	/* net address type */
1091539Srgrimes	unsigned long	n_net;		/* network # */
1101539Srgrimes};
1111539Srgrimes
11283047Sobrienstruct servent {
1131539Srgrimes	char	*s_name;	/* official service name */
1141539Srgrimes	char	**s_aliases;	/* alias list */
1151539Srgrimes	int	s_port;		/* port # */
1161539Srgrimes	char	*s_proto;	/* protocol to use */
1171539Srgrimes};
1181539Srgrimes
11983047Sobrienstruct protoent {
1201539Srgrimes	char	*p_name;	/* official protocol name */
1211539Srgrimes	char	**p_aliases;	/* alias list */
1221539Srgrimes	int	p_proto;	/* protocol # */
1231539Srgrimes};
1241539Srgrimes
12555163Sshinstruct addrinfo {
12655163Sshin	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
12755163Sshin	int	ai_family;	/* PF_xxx */
12855163Sshin	int	ai_socktype;	/* SOCK_xxx */
12955163Sshin	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
13055163Sshin	size_t	ai_addrlen;	/* length of ai_addr */
13155163Sshin	char	*ai_canonname;	/* canonical name for hostname */
13255163Sshin	struct	sockaddr *ai_addr;	/* binary address */
13355163Sshin	struct	addrinfo *ai_next;	/* next structure in linked list */
13455163Sshin};
13555163Sshin
1361539Srgrimes/*
1371539Srgrimes * Error return codes from gethostbyname() and gethostbyaddr()
1381539Srgrimes * (left in extern int h_errno).
1391539Srgrimes */
1401539Srgrimes
14110132Speter#define	NETDB_INTERNAL	-1	/* see errno */
14210132Speter#define	NETDB_SUCCESS	0	/* no problem */
1431539Srgrimes#define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
14413771Smpp#define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */
1451539Srgrimes#define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
1461539Srgrimes#define	NO_DATA		4 /* Valid name, no data record of requested type */
1471539Srgrimes#define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
1481539Srgrimes
14955163Sshin/*
15055163Sshin * Error return codes from getaddrinfo()
15155163Sshin */
15255163Sshin#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
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 */
15855163Sshin#define	EAI_NODATA	 7	/* no address associated with hostname */
15955163Sshin#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
16055163Sshin#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
16155163Sshin#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
16255163Sshin#define	EAI_SYSTEM	11	/* system error returned in errno */
16355163Sshin#define	EAI_BADHINTS	12
16455163Sshin#define	EAI_PROTOCOL	13
16574393Sume#define	EAI_MAX		14
16655163Sshin
16755163Sshin/*
16855163Sshin * Flag values for getaddrinfo()
16955163Sshin */
17055163Sshin#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
17155163Sshin#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
17255163Sshin#define	AI_NUMERICHOST	0x00000004 /* prevent name resolution */
17355163Sshin/* valid flags for addrinfo */
17472693Sume#define AI_MASK \
17572693Sume    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
17655163Sshin
17755163Sshin#define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
17855163Sshin#define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */
17955163Sshin#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
18055163Sshin#define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */
18155163Sshin/* special recommended flags for getipnodebyname */
18255163Sshin#define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
18355163Sshin
18455163Sshin/*
18555163Sshin * Constants for getnameinfo()
18655163Sshin */
18755163Sshin#define	NI_MAXHOST	1025
18855163Sshin#define	NI_MAXSERV	32
18955163Sshin
19055163Sshin/*
19155163Sshin * Flag values for getnameinfo()
19255163Sshin */
19355163Sshin#define	NI_NOFQDN	0x00000001
19455163Sshin#define	NI_NUMERICHOST	0x00000002
19555163Sshin#define	NI_NAMEREQD	0x00000004
19655163Sshin#define	NI_NUMERICSERV	0x00000008
19755163Sshin#define	NI_DGRAM	0x00000010
19855163Sshin#define NI_WITHSCOPEID	0x00000020
19955163Sshin
20055163Sshin/*
20155163Sshin * Scope delimit character
20255163Sshin */
20357033Sshin#define	SCOPE_DELIMITER	'%'
20455163Sshin
2051539Srgrimes__BEGIN_DECLS
20693032Simpvoid		endhostent(void);
20793032Simpvoid		endnetent(void);
20893032Simpvoid		endnetgrent(void);
20993032Simpvoid		endprotoent(void);
21093032Simpvoid		endservent(void);
21193032Simpvoid		freehostent(struct hostent *);
21293032Simpstruct hostent	*gethostbyaddr(const char *, int, int);
21393032Simpstruct hostent	*gethostbyname(const char *);
21493032Simpstruct hostent	*gethostbyname2(const char *, int);
21593032Simpstruct hostent	*gethostent(void);
21693032Simpstruct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
21793032Simpstruct hostent	*getipnodebyname(const char *, int, int, int *);
21893032Simpstruct netent	*getnetbyaddr(unsigned long, int);
21993032Simpstruct netent	*getnetbyname(const char *);
22093032Simpstruct netent	*getnetent(void);
22193032Simpint		getnetgrent(char **, char **, char **);
22293032Simpstruct protoent	*getprotobyname(const char *);
22393032Simpstruct protoent	*getprotobynumber(int);
22493032Simpstruct protoent	*getprotoent(void);
22593032Simpstruct servent	*getservbyname(const char *, const char *);
22693032Simpstruct servent	*getservbyport(int, const char *);
22793032Simpstruct servent	*getservent(void);
22893032Simpvoid		herror(const char *);
22993032Simp__const char	*hstrerror(int);
23093032Simpint		innetgr(const char *, const char *, const char *, const char *);
23193032Simpvoid		sethostent(int);
23293032Simp/* void		sethostfile(const char *); */
23393032Simpvoid		setnetent(int);
23493032Simpvoid		setprotoent(int);
23593032Simpint		getaddrinfo(const char *, const char *,
23693032Simp			    const struct addrinfo *, struct addrinfo **);
23793032Simpint		getnameinfo(const struct sockaddr *, socklen_t, char *,
23893032Simp			    size_t, char *, size_t, int);
23993032Simpvoid		freeaddrinfo(struct addrinfo *);
24093032Simpchar		*gai_strerror(int);
24193032Simpvoid		setnetgrent(const char *);
24293032Simpvoid		setservent(int);
24317902Speter
24417902Speter/*
24517902Speter * PRIVATE functions specific to the FreeBSD implementation
24617902Speter */
24717902Speter
24817902Speter/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */
24993032Simpvoid	_sethosthtent(int);
25093032Simpvoid	_endhosthtent(void);
25193032Simpvoid	_sethostdnsent(int);
25293032Simpvoid	_endhostdnsent(void);
25393032Simpvoid	_setnethtent(int);
25493032Simpvoid	_endnethtent(void);
25593032Simpvoid	_setnetdnsent(int);
25693032Simpvoid	_endnetdnsent(void);
25793032Simpstruct hostent * _gethostbynisname(const char *, int);
25893032Simpstruct hostent * _gethostbynisaddr(const char *, int, int);
25993032Simpvoid _map_v4v6_address(const char *, char *);
26093032Simpvoid _map_v4v6_hostent(struct hostent *, char **, int *);
2611539Srgrimes__END_DECLS
2621539Srgrimes
2631539Srgrimes#endif /* !_NETDB_H_ */
264