1a6ce65drgrimes/*-
2807d9a1pfg * SPDX-License-Identifier: (BSD-3-Clause AND ISC)
36b22553pfg *
4a6ce65drgrimes * Copyright (c) 1980, 1983, 1988, 1993
5a6ce65drgrimes *	The Regents of the University of California.  All rights reserved.
6a6ce65drgrimes *
7a6ce65drgrimes * Redistribution and use in source and binary forms, with or without
8a6ce65drgrimes * modification, are permitted provided that the following conditions
9a6ce65drgrimes * are met:
10a6ce65drgrimes * 1. Redistributions of source code must retain the above copyright
11a6ce65drgrimes *    notice, this list of conditions and the following disclaimer.
12a6ce65drgrimes * 2. Redistributions in binary form must reproduce the above copyright
13a6ce65drgrimes *    notice, this list of conditions and the following disclaimer in the
14a6ce65drgrimes *    documentation and/or other materials provided with the distribution.
157d79e30imp * 3. Neither the name of the University nor the names of its contributors
16a6ce65drgrimes *    may be used to endorse or promote products derived from this software
17a6ce65drgrimes *    without specific prior written permission.
18a6ce65drgrimes *
19a6ce65drgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20a6ce65drgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21a6ce65drgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22a6ce65drgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23a6ce65drgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24a6ce65drgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25a6ce65drgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26a6ce65drgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27a6ce65drgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28a6ce65drgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29a6ce65drgrimes * SUCH DAMAGE.
30a6ce65drgrimes *
31a6ce65drgrimes * -
32a6ce65drgrimes * Portions Copyright (c) 1993 by Digital Equipment Corporation.
332ad6f3drgrimes *
34a6ce65drgrimes * Permission to use, copy, modify, and distribute this software for any
35a6ce65drgrimes * purpose with or without fee is hereby granted, provided that the above
36a6ce65drgrimes * copyright notice and this permission notice appear in all copies, and that
37a6ce65drgrimes * the name of Digital Equipment Corporation not be used in advertising or
38a6ce65drgrimes * publicity pertaining to distribution of the document or software without
39a6ce65drgrimes * specific, written prior permission.
402ad6f3drgrimes *
41a6ce65drgrimes * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
42a6ce65drgrimes * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
43a6ce65drgrimes * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
44a6ce65drgrimes * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
45a6ce65drgrimes * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
46a6ce65drgrimes * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
47a6ce65drgrimes * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48a6ce65drgrimes * SOFTWARE.
49a6ce65drgrimes * -
50a6ce65drgrimes * --Copyright--
51a6ce65drgrimes */
52a6ce65drgrimes
53f8f1d6epeter/*
54f8f1d6epeter *      @(#)netdb.h	8.1 (Berkeley) 6/2/93
55f8f1d6epeter *      From: Id: netdb.h,v 8.9 1996/11/19 08:39:29 vixie Exp $
56d4e3ebapeter * $FreeBSD$
57f8f1d6epeter */
58f8f1d6epeter
59a6ce65drgrimes#ifndef _NETDB_H_
60a6ce65drgrimes#define _NETDB_H_
61a6ce65drgrimes
62648aae1peter#include <sys/cdefs.h>
639e6f796mike#include <sys/_types.h>
64bf66c2eume
653e4cb73ed#ifndef _IN_ADDR_T_DECLARED
663e4cb73edtypedef	__uint32_t	in_addr_t;
673e4cb73ed#define	_IN_ADDR_T_DECLARED
683e4cb73ed#endif
693e4cb73ed
703e4cb73ed#ifndef _IN_PORT_T_DECLARED
713e4cb73edtypedef	__uint16_t	in_port_t;
723e4cb73ed#define	_IN_PORT_T_DECLARED
733e4cb73ed#endif
743e4cb73ed
759e6f796mike#ifndef _SIZE_T_DECLARED
769e6f796miketypedef	__size_t	size_t;
779e6f796mike#define	_SIZE_T_DECLARED
78bf66c2eume#endif
79648aae1peter
809e6f796mike#ifndef _SOCKLEN_T_DECLARED
819e6f796miketypedef	__socklen_t	socklen_t;
829e6f796mike#define	_SOCKLEN_T_DECLARED
8318b7835bde#endif
8418b7835bde
857a6cd62ume#ifndef _UINT32_T_DECLARED
867a6cd62umetypedef	__uint32_t	uint32_t;
877a6cd62ume#define	_UINT32_T_DECLARED
887a6cd62ume#endif
897a6cd62ume
90f8f1d6epeter#ifndef _PATH_HEQUIV
91f8f1d6epeter# define	_PATH_HEQUIV	"/etc/hosts.equiv"
92f8f1d6epeter#endif
93a6ce65drgrimes#define	_PATH_HOSTS	"/etc/hosts"
94a6ce65drgrimes#define	_PATH_NETWORKS	"/etc/networks"
95a6ce65drgrimes#define	_PATH_PROTOCOLS	"/etc/protocols"
96a6ce65drgrimes#define	_PATH_SERVICES	"/etc/services"
977915a50ume#define	_PATH_SERVICES_DB "/var/db/services.db"
98a6ce65drgrimes
99b09a895ume#define	h_errno (*__h_errno())
1002dd1919peter
101a6ce65drgrimes/*
102a6ce65drgrimes * Structures returned by network data base library.  All addresses are
103a6ce65drgrimes * supplied in host order, and returned in network order (suitable for
104a6ce65drgrimes * use in system calls).
105a6ce65drgrimes */
10634ad493obrienstruct hostent {
107a6ce65drgrimes	char	*h_name;	/* official name of host */
108a6ce65drgrimes	char	**h_aliases;	/* alias list */
109a6ce65drgrimes	int	h_addrtype;	/* host address type */
110a6ce65drgrimes	int	h_length;	/* length of address */
111a6ce65drgrimes	char	**h_addr_list;	/* list of addresses from name server */
112d6779c2mpp#define	h_addr	h_addr_list[0]	/* address, for backward compatibility */
113a6ce65drgrimes};
114a6ce65drgrimes
11534ad493obrienstruct netent {
116a6ce65drgrimes	char		*n_name;	/* official name of net */
117a6ce65drgrimes	char		**n_aliases;	/* alias list */
118a6ce65drgrimes	int		n_addrtype;	/* net address type */
1197a6cd62ume	uint32_t	n_net;		/* network # */
120a6ce65drgrimes};
121a6ce65drgrimes
12234ad493obrienstruct servent {
123a6ce65drgrimes	char	*s_name;	/* official service name */
124a6ce65drgrimes	char	**s_aliases;	/* alias list */
125a6ce65drgrimes	int	s_port;		/* port # */
126a6ce65drgrimes	char	*s_proto;	/* protocol to use */
127a6ce65drgrimes};
128a6ce65drgrimes
12934ad493obrienstruct protoent {
130a6ce65drgrimes	char	*p_name;	/* official protocol name */
131a6ce65drgrimes	char	**p_aliases;	/* alias list */
132a6ce65drgrimes	int	p_proto;	/* protocol # */
133a6ce65drgrimes};
134a6ce65drgrimes
1358c2ccb5shinstruct addrinfo {
1368c2ccb5shin	int	ai_flags;	/* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
13733741c0ume	int	ai_family;	/* AF_xxx */
1388c2ccb5shin	int	ai_socktype;	/* SOCK_xxx */
1398c2ccb5shin	int	ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
1407a6cd62ume	socklen_t ai_addrlen;	/* length of ai_addr */
1418c2ccb5shin	char	*ai_canonname;	/* canonical name for hostname */
1428c2ccb5shin	struct	sockaddr *ai_addr;	/* binary address */
1438c2ccb5shin	struct	addrinfo *ai_next;	/* next structure in linked list */
1448c2ccb5shin};
1458c2ccb5shin
1463e4cb73ed#define	IPPORT_RESERVED	1024
1473e4cb73ed
148a6ce65drgrimes/*
149a6ce65drgrimes * Error return codes from gethostbyname() and gethostbyaddr()
1504045249green * (left in h_errno).
151a6ce65drgrimes */
152a6ce65drgrimes
1532dd1919peter#define	NETDB_INTERNAL	-1	/* see errno */
1542dd1919peter#define	NETDB_SUCCESS	0	/* no problem */
155a6ce65drgrimes#define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
156d6779c2mpp#define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */
157a6ce65drgrimes#define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
158a6ce65drgrimes#define	NO_DATA		4 /* Valid name, no data record of requested type */
159a6ce65drgrimes#define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
160a6ce65drgrimes
1618c2ccb5shin/*
1622c75604pfg * Error return codes from gai_strerror(3), see RFC 3493.
1638c2ccb5shin */
1647b57334ume#if 0
1652c75604pfg/* Obsoleted on RFC 2553bis-02 */
1668c2ccb5shin#define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
1677b57334ume#endif
1682c75604pfg#define	EAI_AGAIN	 2	/* name could not be resolved at this time */
1692c75604pfg#define	EAI_BADFLAGS	 3	/* flags parameter had an invalid value */
1708c2ccb5shin#define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
171cb53dcdpfg#define	EAI_FAMILY	 5	/* address family not recognized */
1728c2ccb5shin#define	EAI_MEMORY	 6	/* memory allocation failure */
1737b57334ume#if 0
1742c75604pfg/* Obsoleted on RFC 2553bis-02 */
1758c2ccb5shin#define	EAI_NODATA	 7	/* no address associated with hostname */
1767b57334ume#endif
1772c75604pfg#define	EAI_NONAME	 8	/* name does not resolve */
1782c75604pfg#define	EAI_SERVICE	 9	/* service not recognized for socket type */
1792c75604pfg#define	EAI_SOCKTYPE	10	/* intended socket type was not recognized */
1808c2ccb5shin#define	EAI_SYSTEM	11	/* system error returned in errno */
181c499297ume#define	EAI_BADHINTS	12	/* invalid value for hints */
182c499297ume#define	EAI_PROTOCOL	13	/* resolved protocol is unknown */
183c499297ume#define	EAI_OVERFLOW	14	/* argument buffer overflow */
184c499297ume#define	EAI_MAX		15
1858c2ccb5shin
1868c2ccb5shin/*
1878c2ccb5shin * Flag values for getaddrinfo()
1888c2ccb5shin */
1898c2ccb5shin#define	AI_PASSIVE	0x00000001 /* get address to use bind() */
1908c2ccb5shin#define	AI_CANONNAME	0x00000002 /* fill ai_canonname */
1914a4e55cume#define	AI_NUMERICHOST	0x00000004 /* prevent host name resolution */
1924a4e55cume#define	AI_NUMERICSERV	0x00000008 /* prevent service name resolution */
1934a4e55cume/* valid flags for addrinfo (not a standard def, apps should not use it) */
1944c12334ume#define AI_MASK \
1954a4e55cume    (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | \
196658c0fcume    AI_ADDRCONFIG | AI_ALL | AI_V4MAPPED)
1978c2ccb5shin
1988c2ccb5shin#define	AI_ALL		0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
1998c2ccb5shin#define	AI_V4MAPPED_CFG	0x00000200 /* accept IPv4-mapped if kernel supports */
2008c2ccb5shin#define	AI_ADDRCONFIG	0x00000400 /* only if any address is assigned */
2018c2ccb5shin#define	AI_V4MAPPED	0x00000800 /* accept IPv4-mapped IPv6 address */
2028c2ccb5shin/* special recommended flags for getipnodebyname */
2038c2ccb5shin#define	AI_DEFAULT	(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
2048c2ccb5shin
2058c2ccb5shin/*
2068c2ccb5shin * Constants for getnameinfo()
2078c2ccb5shin */
2088c2ccb5shin#define	NI_MAXHOST	1025
2098c2ccb5shin#define	NI_MAXSERV	32
2108c2ccb5shin
2118c2ccb5shin/*
2128c2ccb5shin * Flag values for getnameinfo()
2138c2ccb5shin */
2148c2ccb5shin#define	NI_NOFQDN	0x00000001
2158c2ccb5shin#define	NI_NUMERICHOST	0x00000002
2168c2ccb5shin#define	NI_NAMEREQD	0x00000004
2178c2ccb5shin#define	NI_NUMERICSERV	0x00000008
2188c2ccb5shin#define	NI_DGRAM	0x00000010
21943835a1ed#define	NI_NUMERICSCOPE	0x00000020
2208c2ccb5shin
2218c2ccb5shin/*
2228c2ccb5shin * Scope delimit character
2238c2ccb5shin */
22463ef3beshin#define	SCOPE_DELIMITER	'%'
2258c2ccb5shin
226a6ce65drgrimes__BEGIN_DECLS
227300518cimpvoid		endhostent(void);
228300518cimpvoid		endnetent(void);
229300518cimpvoid		endprotoent(void);
230300518cimpvoid		endservent(void);
231835b406das#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112)
232ab3eacdumestruct hostent	*gethostbyaddr(const void *, socklen_t, int);
233835b406dasstruct hostent	*gethostbyname(const char *);
234835b406das#endif
235835b406dasstruct hostent	*gethostent(void);
236835b406dasstruct netent	*getnetbyaddr(uint32_t, int);
237835b406dasstruct netent	*getnetbyname(const char *);
238835b406dasstruct netent	*getnetent(void);
239835b406dasstruct protoent	*getprotobyname(const char *);
240835b406dasstruct protoent	*getprotobynumber(int);
241835b406dasstruct protoent	*getprotoent(void);
242835b406dasstruct servent	*getservbyname(const char *, const char *);
243835b406dasstruct servent	*getservbyport(int, const char *);
244835b406dasstruct servent	*getservent(void);
245835b406dasvoid		sethostent(int);
246835b406das/* void		sethostfile(const char *); */
247835b406dasvoid		setnetent(int);
248835b406dasvoid		setprotoent(int);
249835b406dasint		getaddrinfo(const char *, const char *,
250835b406das			    const struct addrinfo *, struct addrinfo **);
251835b406dasint		getnameinfo(const struct sockaddr *, socklen_t, char *,
252835b406das			    size_t, char *, size_t, int);
253835b406dasvoid		freeaddrinfo(struct addrinfo *);
254835b406dasconst char	*gai_strerror(int);
255835b406dasvoid		setservent(int);
256835b406das
257835b406das#if __BSD_VISIBLE
258835b406dasvoid		endnetgrent(void);
259835b406dasvoid		freehostent(struct hostent *);
260ab3eacdumeint		gethostbyaddr_r(const void *, socklen_t, int, struct hostent *,
261ab3eacdume    char *, size_t, struct hostent **, int *);
262b6bb84cumeint		gethostbyname_r(const char *, struct hostent *, char *, size_t,
263b6bb84cume    struct hostent **, int *);
264300518cimpstruct hostent	*gethostbyname2(const char *, int);
265b6bb84cumeint		gethostbyname2_r(const char *, int, struct hostent *, char *,
266b6bb84cume    size_t, struct hostent **, int *);
267b6bb84cumeint		gethostent_r(struct hostent *, char *, size_t,
268b6bb84cume    struct hostent **, int *);
269300518cimpstruct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
270300518cimpstruct hostent	*getipnodebyname(const char *, int, int, int *);
271b6bb84cumeint		getnetbyaddr_r(uint32_t, int, struct netent *, char *, size_t,
272b6bb84cume    struct netent**, int *);
273b6bb84cumeint		getnetbyname_r(const char *, struct netent *, char *, size_t,
274b6bb84cume    struct netent **, int *);
275b6bb84cumeint		getnetent_r(struct netent *, char *, size_t, struct netent **,
276b6bb84cume    int *);
277300518cimpint		getnetgrent(char **, char **, char **);
2785c6d3bcmarkjint		getnetgrent_r(char **, char **, char **, char *, size_t);
279b6bb84cumeint		getprotobyname_r(const char *, struct protoent *, char *,
280b6bb84cume    size_t, struct protoent **);
281b6bb84cumeint		getprotobynumber_r(int, struct protoent *, char *, size_t,
282b6bb84cume    struct protoent **);
283b6bb84cumeint		getprotoent_r(struct protoent *, char *, size_t,
284b6bb84cume    struct protoent **);
285b6bb84cumeint		getservbyname_r(const char *, const char *, struct servent *,
286b6bb84cume    char *, size_t, struct servent **);
287b6bb84cumeint		getservbyport_r(int, const char *, struct servent *, char *,
288b6bb84cume    size_t, struct servent **);
289b6bb84cumeint		getservent_r(struct servent *, char *, size_t,
290b6bb84cume    struct servent **);
291300518cimpvoid		herror(const char *);
2920bcfe62edconst char	*hstrerror(int);
293300518cimpint		innetgr(const char *, const char *, const char *, const char *);
294300518cimpvoid		setnetgrent(const char *);
295835b406das#endif
296835b406das
297d971f8bpeter
298d971f8bpeter/*
299d971f8bpeter * PRIVATE functions specific to the FreeBSD implementation
300d971f8bpeter */
301d971f8bpeter
302d971f8bpeter/* DO NOT USE THESE, THEY ARE SUBJECT TO CHANGE AND ARE NOT PORTABLE!!! */
303b09a895umeint	* __h_errno(void);
304a6ce65drgrimes__END_DECLS
305a6ce65drgrimes
306a6ce65drgrimes#endif /* !_NETDB_H_ */
307