netdb.h revision 9e6f796b0d2083dcc48c062853660f96db0a3c8d
17c478bdstevel@tonic-gate/*-
27c478bdstevel@tonic-gate * Copyright (c) 1980, 1983, 1988, 1993
37c478bdstevel@tonic-gate *	The Regents of the University of California.  All rights reserved.
47c478bdstevel@tonic-gate *
57c478bdstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
67c478bdstevel@tonic-gate * modification, are permitted provided that the following conditions
77c478bdstevel@tonic-gate * are met:
87c478bdstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
97c478bdstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
107c478bdstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
117c478bdstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
127c478bdstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
137c478bdstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
147c478bdstevel@tonic-gate *    must display the following acknowledgement:
157c478bdstevel@tonic-gate *	This product includes software developed by the University of
167c478bdstevel@tonic-gate *	California, Berkeley and its contributors.
177c478bdstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors
187c478bdstevel@tonic-gate *    may be used to endorse or promote products derived from this software
197c478bdstevel@tonic-gate *    without specific prior written permission.
207c478bdstevel@tonic-gate *
217c478bdstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
227c478bdstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
237c478bdstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
247c478bdstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
257c478bdstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
267c478bdstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
277c478bdstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
287c478bdstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
297c478bdstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
307c478bdstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
317c478bdstevel@tonic-gate * SUCH DAMAGE.
327c478bdstevel@tonic-gate *
337c478bdstevel@tonic-gate * -
347c478bdstevel@tonic-gate * Portions Copyright (c) 1993 by Digital Equipment Corporation.
357c478bdstevel@tonic-gate *
367c478bdstevel@tonic-gate * Permission to use, copy, modify, and distribute this software for any
377c478bdstevel@tonic-gate * purpose with or without fee is hereby granted, provided that the above
387c478bdstevel@tonic-gate * copyright notice and this permission notice appear in all copies, and that
397c478bdstevel@tonic-gate * the name of Digital Equipment Corporation not be used in advertising or
407c478bdstevel@tonic-gate * publicity pertaining to distribution of the document or software without
417c478bdstevel@tonic-gate * specific, written prior permission.
427c478bdstevel@tonic-gate *
437c478bdstevel@tonic-gate * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
447c478bdstevel@tonic-gate * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
457c478bdstevel@tonic-gate * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
467c478bdstevel@tonic-gate * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
477c478bdstevel@tonic-gate * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
487c478bdstevel@tonic-gate * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
497c478bdstevel@tonic-gate * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
507c478bdstevel@tonic-gate * SOFTWARE.
517c478bdstevel@tonic-gate * -
527c478bdstevel@tonic-gate * --Copyright--
537c478bdstevel@tonic-gate */
547c478bdstevel@tonic-gate
557c478bdstevel@tonic-gate/*
567c478bdstevel@tonic-gate *      @(#)netdb.h	8.1 (Berkeley) 6/2/93
577c478bdstevel@tonic-gate *      From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
587c478bdstevel@tonic-gate * $FreeBSD$
597c478bdstevel@tonic-gate */
607c478bdstevel@tonic-gate
617c478bdstevel@tonic-gate#ifndef _NETDB_H_
627c478bdstevel@tonic-gate#define _NETDB_H_
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate#include <sys/cdefs.h>
657c478bdstevel@tonic-gate#include <sys/_types.h>
667c478bdstevel@tonic-gate
677c478bdstevel@tonic-gate#ifndef _SIZE_T_DECLARED
687c478bdstevel@tonic-gatetypedef	__size_t	size_t;
697c478bdstevel@tonic-gate#define	_SIZE_T_DECLARED
707c478bdstevel@tonic-gate#endif
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#ifndef _SOCKLEN_T_DECLARED
737c478bdstevel@tonic-gatetypedef	__socklen_t	socklen_t;
747c478bdstevel@tonic-gate#define	_SOCKLEN_T_DECLARED
757c478bdstevel@tonic-gate#endif
767c478bdstevel@tonic-gate
777c478bdstevel@tonic-gate#ifndef _PATH_HEQUIV
787c478bdstevel@tonic-gate# define	_PATH_HEQUIV	"/etc/hosts.equiv"
797c478bdstevel@tonic-gate#endif
807c478bdstevel@tonic-gate#define	_PATH_HOSTS	"/etc/hosts"
817c478bdstevel@tonic-gate#define	_PATH_NETWORKS	"/etc/networks"
827c478bdstevel@tonic-gate#define	_PATH_PROTOCOLS	"/etc/protocols"
837c478bdstevel@tonic-gate#define	_PATH_SERVICES	"/etc/services"
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gateextern int h_errno;
867c478bdstevel@tonic-gate
877c478bdstevel@tonic-gate/*
887c478bdstevel@tonic-gate * Structures returned by network data base library.  All addresses are
897c478bdstevel@tonic-gate * supplied in host order, and returned in network order (suitable for
907c478bdstevel@tonic-gate * use in system calls).
917c478bdstevel@tonic-gate */
927c478bdstevel@tonic-gatestruct hostent {
937c478bdstevel@tonic-gate	char	*h_name;	/* official name of host */
947c478bdstevel@tonic-gate	char	**h_aliases;	/* alias list */
957c478bdstevel@tonic-gate	int	h_addrtype;	/* host address type */
967c478bdstevel@tonic-gate	int	h_length;	/* length of address */
977c478bdstevel@tonic-gate	char	**h_addr_list;	/* list of addresses from name server */
987c478bdstevel@tonic-gate#define	h_addr	h_addr_list[0]	/* address, for backward compatibility */
997c478bdstevel@tonic-gate};
1007c478bdstevel@tonic-gate
1017c478bdstevel@tonic-gate/*
1027c478bdstevel@tonic-gate * Assumption here is that a network number
1037c478bdstevel@tonic-gate * fits in an unsigned long -- probably a poor one.
1047c478bdstevel@tonic-gate */
1057c478bdstevel@tonic-gatestruct netent {
1067c478bdstevel@tonic-gate	char		*n_name;	/* official name of net */
1077c478bdstevel@tonic-gate	char		**n_aliases;	/* alias list */
1087c478bdstevel@tonic-gate	int		n_addrtype;	/* net address type */
1097c478bdstevel@tonic-gate	unsigned long	n_net;		/* network # */
1107c478bdstevel@tonic-gate};
1117c478bdstevel@tonic-gate
1127c478bdstevel@tonic-gatestruct servent {
1137c478bdstevel@tonic-gate	char	*s_name;	/* official service name */
1147c478bdstevel@tonic-gate	char	**s_aliases;	/* alias list */
1157c478bdstevel@tonic-gate	int	s_port;		/* port # */
1167c478bdstevel@tonic-gate	char	*s_proto;	/* protocol to use */
1177c478bdstevel@tonic-gate};
1187c478bdstevel@tonic-gate
1197c478bdstevel@tonic-gatestruct protoent {
1207c478bdstevel@tonic-gate	char	*p_name;	/* official protocol name */
1217c478bdstevel@tonic-gate	char	**p_aliases;	/* alias list */
1227c478bdstevel@tonic-gate	int	p_proto;	/* protocol # */
1237c478bdstevel@tonic-gate};
1247c478bdstevel@tonic-gate
1257c478bdstevel@tonic-gatestruct addrinfo {
1267c478bdstevel@tonic-gate	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
1277c478bdstevel@tonic-gate	int	ai_family;	/* PF_xxx */
1287c478bdstevel@tonic-gate	int	ai_socktype;	/* SOCK_xxx */
1297c478bdstevel@tonic-gate	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
1307c478bdstevel@tonic-gate	size_t	ai_addrlen;	/* length of ai_addr */
1317c478bdstevel@tonic-gate	char	*ai_canonname;	/* canonical name for hostname */
1327c478bdstevel@tonic-gate	struct	sockaddr *ai_addr;	/* binary address */
1337c478bdstevel@tonic-gate	struct	addrinfo *ai_next;	/* next structure in linked list */
1347c478bdstevel@tonic-gate};
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gate/*
1377c478bdstevel@tonic-gate * Error return codes from gethostbyname() and gethostbyaddr()
1387c478bdstevel@tonic-gate * (left in extern int h_errno).
1397c478bdstevel@tonic-gate */
1407c478bdstevel@tonic-gate
1417c478bdstevel@tonic-gate#define	NETDB_INTERNAL	-1	/* see errno */
1427c478bdstevel@tonic-gate#define	NETDB_SUCCESS	0	/* no problem */
1437c478bdstevel@tonic-gate#define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
1447c478bdstevel@tonic-gate#define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */
1457c478bdstevel@tonic-gate#define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
1467c478bdstevel@tonic-gate#define	NO_DATA		4 /* Valid name, no data record of requested type */
1477c478bdstevel@tonic-gate#define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gate/*
1507c478bdstevel@tonic-gate * Error return codes from getaddrinfo()
1517c478bdstevel@tonic-gate */
1527c478bdstevel@tonic-gate#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
1537c478bdstevel@tonic-gate#define	EAI_AGAIN	 2	/* temporary failure in name resolution */
1547c478bdstevel@tonic-gate#define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
1557c478bdstevel@tonic-gate#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
1567c478bdstevel@tonic-gate#define	EAI_FAMILY	 5	/* ai_family not supported */
1577c478bdstevel@tonic-gate#define	EAI_MEMORY	 6	/* memory allocation failure */
1587c478bdstevel@tonic-gate#define	EAI_NODATA	 7	/* no address associated with hostname */
1597c478bdstevel@tonic-gate#define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
1607c478bdstevel@tonic-gate#define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
1617c478bdstevel@tonic-gate#define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
1627c478bdstevel@tonic-gate#define	EAI_SYSTEM	11	/* system error returned in errno */
1637c478bdstevel@tonic-gate#define	EAI_BADHINTS	12
1647c478bdstevel@tonic-gate#define	EAI_PROTOCOL	13
1657c478bdstevel@tonic-gate#define	EAI_MAX		14
1667c478bdstevel@tonic-gate
1677c478bdstevel@tonic-gate/*
1687c478bdstevel@tonic-gate * Flag values for getaddrinfo()
1697c478bdstevel@tonic-gate */
1707c478bdstevel@tonic-gate#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
1717c478bdstevel@tonic-gate#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
1727c478bdstevel@tonic-gate#define	AI_NUMERICHOST	0x00000004 /* prevent name resolution */
1737c478bdstevel@tonic-gate/* valid flags for addrinfo */
1747c478bdstevel@tonic-gate#define AI_MASK \
1757c478bdstevel@tonic-gate    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_ADDRCONFIG)
1767c478bdstevel@tonic-gate
1777c478bdstevel@tonic-gate#define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
1787c478bdstevel@tonic-gate#define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */
1797c478bdstevel@tonic-gate#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
1807c478bdstevel@tonic-gate#define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */
1817c478bdstevel@tonic-gate/* special recommended flags for getipnodebyname */
1827c478bdstevel@tonic-gate#define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
1837c478bdstevel@tonic-gate
1847c478bdstevel@tonic-gate/*
1857c478bdstevel@tonic-gate * Constants for getnameinfo()
1867c478bdstevel@tonic-gate */
1877c478bdstevel@tonic-gate#define	NI_MAXHOST	1025
1887c478bdstevel@tonic-gate#define	NI_MAXSERV	32
1897c478bdstevel@tonic-gate
1907c478bdstevel@tonic-gate/*
1917c478bdstevel@tonic-gate * Flag values for getnameinfo()
1927c478bdstevel@tonic-gate */
1937c478bdstevel@tonic-gate#define	NI_NOFQDN	0x00000001
1947c478bdstevel@tonic-gate#define	NI_NUMERICHOST	0x00000002
1957c478bdstevel@tonic-gate#define	NI_NAMEREQD	0x00000004
1967c478bdstevel@tonic-gate#define	NI_NUMERICSERV	0x00000008
1977c478bdstevel@tonic-gate#define	NI_DGRAM	0x00000010
1987c478bdstevel@tonic-gate#define NI_WITHSCOPEID	0x00000020
1997c478bdstevel@tonic-gate
2007c478bdstevel@tonic-gate/*
2017c478bdstevel@tonic-gate * Scope delimit character
2027c478bdstevel@tonic-gate */
2037c478bdstevel@tonic-gate#define	SCOPE_DELIMITER	'%'
2047c478bdstevel@tonic-gate
2057c478bdstevel@tonic-gate__BEGIN_DECLS
2067c478bdstevel@tonic-gatevoid		endhostent(void);
2077c478bdstevel@tonic-gatevoid		endnetent(void);
2087c478bdstevel@tonic-gatevoid		endnetgrent(void);
2097c478bdstevel@tonic-gatevoid		endprotoent(void);
2107c478bdstevel@tonic-gatevoid		endservent(void);
2117c478bdstevel@tonic-gatevoid		freehostent(struct hostent *);
2127c478bdstevel@tonic-gatestruct hostent	*gethostbyaddr(const char *, int, int);
2137c478bdstevel@tonic-gatestruct hostent	*gethostbyname(const char *);
2147c478bdstevel@tonic-gatestruct hostent	*gethostbyname2(const char *, int);
2157c478bdstevel@tonic-gatestruct hostent	*gethostent(void);
2167c478bdstevel@tonic-gatestruct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
2177c478bdstevel@tonic-gatestruct hostent	*getipnodebyname(const char *, int, int, int *);
2187c478bdstevel@tonic-gatestruct netent	*getnetbyaddr(unsigned long, int);
2197c478bdstevel@tonic-gatestruct netent	*getnetbyname(const char *);
2207c478bdstevel@tonic-gatestruct netent	*getnetent(void);
2217c478bdstevel@tonic-gateint		getnetgrent(char **, char **, char **);
2227c478bdstevel@tonic-gatestruct protoent	*getprotobyname(const char *);
2237c478bdstevel@tonic-gatestruct protoent	*getprotobynumber(int);
2247c478bdstevel@tonic-gatestruct protoent	*getprotoent(void);
2257c478bdstevel@tonic-gatestruct servent	*getservbyname(const char *, const char *);
2267c478bdstevel@tonic-gatestruct servent	*getservbyport(int, const char *);
2277c478bdstevel@tonic-gatestruct servent	*getservent(void);
2287c478bdstevel@tonic-gatevoid		herror(const char *);
2297c478bdstevel@tonic-gate__const char	*hstrerror(int);
2307c478bdstevel@tonic-gateint		innetgr(const char *, const char *, const char *, const char *);
2317c478bdstevel@tonic-gatevoid		sethostent(int);
2327c478bdstevel@tonic-gate/* void		sethostfile(const char *); */
2337c478bdstevel@tonic-gatevoid		setnetent(int);
2347c478bdstevel@tonic-gatevoid		setprotoent(int);
2357c478bdstevel@tonic-gateint		getaddrinfo(const char *, const char *,
2367c478bdstevel@tonic-gate			    const struct addrinfo *, struct addrinfo **);
2377c478bdstevel@tonic-gateint		getnameinfo(const struct sockaddr *, socklen_t, char *,
2387c478bdstevel@tonic-gate			    size_t, char *, size_t, int);
2397c478bdstevel@tonic-gatevoid		freeaddrinfo(struct addrinfo *);
2407c478bdstevel@tonic-gatechar		*gai_strerror(int);
2417c478bdstevel@tonic-gatevoid		setnetgrent(const char *);
2427c478bdstevel@tonic-gatevoid		setservent(int);
2437c478bdstevel@tonic-gate
2447c478bdstevel@tonic-gate/*
2457c478bdstevel@tonic-gate * PRIVATE functions specific to the FreeBSD implementation
2467c478bdstevel@tonic-gate */
2477c478bdstevel@tonic-gate
2487c478bdstevel@tonic-gate/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */
2497c478bdstevel@tonic-gatevoid	_sethosthtent(int);
2507c478bdstevel@tonic-gatevoid	_endhosthtent(void);
2517c478bdstevel@tonic-gatevoid	_sethostdnsent(int);
2527c478bdstevel@tonic-gatevoid	_endhostdnsent(void);
2537c478bdstevel@tonic-gatevoid	_setnethtent(int);
2547c478bdstevel@tonic-gatevoid	_endnethtent(void);
2557c478bdstevel@tonic-gatevoid	_setnetdnsent(int);
2567c478bdstevel@tonic-gatevoid	_endnetdnsent(void);
2577c478bdstevel@tonic-gatestruct hostent * _gethostbynisname(const char *, int);
2587c478bdstevel@tonic-gatestruct hostent * _gethostbynisaddr(const char *, int, int);
2597c478bdstevel@tonic-gatevoid _map_v4v6_address(const char *, char *);
2607c478bdstevel@tonic-gatevoid _map_v4v6_hostent(struct hostent *, char **, char **);
2617c478bdstevel@tonic-gate__END_DECLS
2627c478bdstevel@tonic-gate
2637c478bdstevel@tonic-gate#endif /* !_NETDB_H_ */
2647c478bdstevel@tonic-gate