xref: /openbsd-src/include/netdb.h (revision 91f110e064cd7c194e59e019b83bb7496c1c84d4)
1 /*	$OpenBSD: netdb.h,v 1.31 2012/09/15 00:47:08 guenther Exp $	*/
2 
3 /*
4  * ++Copyright++ 1980, 1983, 1988, 1993
5  * -
6  * Copyright (c) 1980, 1983, 1988, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  * -
33  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
34  *
35  * Permission to use, copy, modify, and distribute this software for any
36  * purpose with or without fee is hereby granted, provided that the above
37  * copyright notice and this permission notice appear in all copies, and that
38  * the name of Digital Equipment Corporation not be used in advertising or
39  * publicity pertaining to distribution of the document or software without
40  * specific, written prior permission.
41  *
42  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
43  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
44  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
45  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
46  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
47  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
48  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49  * SOFTWARE.
50  * -
51  * --Copyright--
52  */
53 
54 /*
55  * Copyright (c) 1995, 1996, 1997, 1998, 1999 Craig Metz. All rights reserved.
56  *
57  * Redistribution and use in source and binary forms, with or without
58  * modification, are permitted provided that the following conditions
59  * are met:
60  * 1. Redistributions of source code must retain the above copyright
61  *    notice, this list of conditions and the following disclaimer.
62  * 2. Redistributions in binary form must reproduce the above copyright
63  *    notice, this list of conditions and the following disclaimer in the
64  *    documentation and/or other materials provided with the distribution.
65  * 3. Neither the name of the author nor the names of any contributors
66  *    may be used to endorse or promote products derived from this software
67  *    without specific prior written permission.
68  *
69  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
70  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
71  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
72  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
73  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
74  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
75  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
76  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
77  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
78  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
79  * SUCH DAMAGE.
80  */
81 
82 /*
83  *      @(#)netdb.h	8.1 (Berkeley) 6/2/93
84  *	$From: netdb.h,v 8.7 1996/05/09 05:59:09 vixie Exp $
85  */
86 
87 #ifndef _NETDB_H_
88 #define _NETDB_H_
89 
90 #include <sys/cdefs.h>
91 
92 #if __BSD_VISIBLE
93 #include <sys/param.h>
94 #endif
95 #include <netinet/in.h>
96 
97 #ifndef	_SOCKLEN_T_DEFINED_
98 #define	_SOCKLEN_T_DEFINED_
99 typedef	__socklen_t	socklen_t;	/* length type for network syscalls */
100 #endif
101 
102 #define	_PATH_HEQUIV	"/etc/hosts.equiv"
103 #define	_PATH_HOSTS	"/etc/hosts"
104 #define	_PATH_NETWORKS	"/etc/networks"
105 #define	_PATH_PROTOCOLS	"/etc/protocols"
106 #define	_PATH_SERVICES	"/etc/services"
107 
108 /*
109  * Structures returned by network data base library.  All addresses are
110  * supplied in host order, and returned in network order (suitable for
111  * use in system calls).
112  */
113 struct	hostent {
114 	char	*h_name;	/* official name of host */
115 	char	**h_aliases;	/* alias list */
116 	int	h_addrtype;	/* host address type */
117 	int	h_length;	/* length of address */
118 	char	**h_addr_list;	/* list of addresses from name server */
119 #define	h_addr	h_addr_list[0]	/* address, for backward compatibility */
120 };
121 
122 /*
123  * Assumption here is that a network number
124  * fits in an in_addr_t -- probably a poor one.
125  */
126 struct	netent {
127 	char		*n_name;	/* official name of net */
128 	char		**n_aliases;	/* alias list */
129 	int		n_addrtype;	/* net address type */
130 	in_addr_t	n_net;		/* network # */
131 };
132 
133 struct	servent {
134 	char	*s_name;	/* official service name */
135 	char	**s_aliases;	/* alias list */
136 	int	s_port;		/* port # */
137 	char	*s_proto;	/* protocol to use */
138 };
139 
140 struct	protoent {
141 	char	*p_name;	/* official protocol name */
142 	char	**p_aliases;	/* alias list */
143 	int	p_proto;	/* protocol # */
144 };
145 
146 #if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
147 extern int h_errno;
148 
149 /*
150  * Error return codes from gethostbyname() and gethostbyaddr()
151  * (left in extern int h_errno).
152  */
153 
154 #define	NETDB_INTERNAL	-1	/* see errno */
155 #define	NETDB_SUCCESS	0	/* no problem */
156 #define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
157 #define	TRY_AGAIN	2 /* Non-Authoritative Host not found, or SERVERFAIL */
158 #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
159 #define	NO_DATA		4 /* Valid name, no data record of requested type */
160 #define	NO_ADDRESS	NO_DATA		/* no address */
161 #endif /* __BSD_VISIBLE || __POSIX_VISIBLE < 200809 */
162 
163 /* Values for getaddrinfo() and getnameinfo() */
164 #define AI_PASSIVE	1	/* socket address is intended for bind() */
165 #define AI_CANONNAME	2	/* request for canonical name */
166 #define AI_NUMERICHOST	4	/* don't ever try hostname lookup */
167 #define AI_EXT		8	/* enable non-portable extensions */
168 #define AI_NUMERICSERV	16	/* don't ever try servname lookup */
169 #define AI_FQDN		32	/* return the FQDN that was resolved */
170 /* valid flags for addrinfo */
171 #define AI_MASK \
172     (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_FQDN)
173 
174 #define NI_NUMERICHOST	1	/* return the host address, not the name */
175 #define NI_NUMERICSERV	2	/* return the service address, not the name */
176 #define NI_NOFQDN	4	/* return a short name if in the local domain */
177 #define NI_NAMEREQD	8	/* fail if either host or service name is unknown */
178 #define NI_DGRAM	16	/* look up datagram service instead of stream */
179 /* #define NI_NUMERICSCOPE	32	 return the scope number, not the name */
180 
181 #if __BSD_VISIBLE
182 #define NI_MAXHOST	MAXHOSTNAMELEN	/* max host name returned by getnameinfo */
183 #define NI_MAXSERV	32	/* max serv. name length returned by getnameinfo */
184 
185 /*
186  * Scope delimit character (KAME hack)
187  */
188 #define SCOPE_DELIMITER '%'
189 #endif
190 
191 #define EAI_BADFLAGS	-1	/* invalid value for ai_flags */
192 #define EAI_NONAME	-2	/* name or service is not known */
193 #define EAI_AGAIN	-3	/* temporary failure in name resolution */
194 #define EAI_FAIL	-4	/* non-recoverable failure in name resolution */
195 #define EAI_NODATA	-5	/* no address associated with name */
196 #define EAI_FAMILY	-6	/* ai_family not supported */
197 #define EAI_SOCKTYPE	-7	/* ai_socktype not supported */
198 #define EAI_SERVICE	-8	/* service not supported for ai_socktype */
199 #define EAI_ADDRFAMILY	-9	/* address family for name not supported */
200 #define EAI_MEMORY	-10	/* memory allocation failure */
201 #define EAI_SYSTEM	-11	/* system error (code indicated in errno) */
202 #define EAI_BADHINTS	-12	/* invalid value for hints */
203 #define EAI_PROTOCOL	-13	/* resolved protocol is unknown */
204 #define EAI_OVERFLOW	-14	/* argument buffer overflow */
205 
206 struct addrinfo {
207 	int ai_flags;		/* input flags */
208 	int ai_family;		/* protocol family for socket */
209 	int ai_socktype;	/* socket type */
210 	int ai_protocol;	/* protocol for socket */
211 	socklen_t ai_addrlen;	/* length of socket-address */
212 	struct sockaddr *ai_addr; /* socket-address for socket */
213 	char *ai_canonname;	/* canonical name for service location (iff req) */
214 	struct addrinfo *ai_next; /* pointer to next in list */
215 };
216 
217 #if __BSD_VISIBLE
218 /*
219  * Flags for getrrsetbyname()
220  */
221 #define RRSET_VALIDATED		1
222 
223 /*
224  * Return codes for getrrsetbyname()
225  */
226 #define ERRSET_SUCCESS		0
227 #define ERRSET_NOMEMORY		1
228 #define ERRSET_FAIL		2
229 #define ERRSET_INVAL		3
230 #define ERRSET_NONAME		4
231 #define ERRSET_NODATA		5
232 
233 /*
234  * Structures used by getrrsetbyname() and freerrset()
235  */
236 struct rdatainfo {
237 	unsigned int		rdi_length;	/* length of data */
238 	unsigned char		*rdi_data;	/* record data */
239 };
240 
241 struct rrsetinfo {
242 	unsigned int		rri_flags;	/* RRSET_VALIDATED ... */
243 	unsigned int		rri_rdclass;	/* class number */
244 	unsigned int		rri_rdtype;	/* RR type number */
245 	unsigned int		rri_ttl;	/* time to live */
246 	unsigned int		rri_nrdatas;	/* size of rdatas array */
247 	unsigned int		rri_nsigs;	/* size of sigs array */
248 	char			*rri_name;	/* canonical name */
249 	struct rdatainfo	*rri_rdatas;	/* individual records */
250 	struct rdatainfo	*rri_sigs;	/* individual signatures */
251 };
252 
253 struct servent_data {
254 	void *fp;
255 	char **aliases;
256 	int maxaliases;
257 	int stayopen;
258 	char *line;
259 };
260 
261 struct protoent_data {
262 	void *fp;
263 	char **aliases;
264 	int maxaliases;
265 	int stayopen;
266 	char *line;
267 };
268 #endif
269 
270 __BEGIN_DECLS
271 void		endhostent(void);
272 void		endnetent(void);
273 void		endprotoent(void);
274 void		endservent(void);
275 #if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
276 struct hostent	*gethostbyaddr(const void *, socklen_t, int);
277 struct hostent	*gethostbyname(const char *);
278 #endif
279 #if __BSD_VISIBLE
280 struct hostent	*gethostbyname2(const char *, int);
281 #endif
282 struct hostent	*gethostent(void);
283 struct netent	*getnetbyaddr(in_addr_t, int);
284 struct netent	*getnetbyname(const char *);
285 struct netent	*getnetent(void);
286 struct protoent	*getprotobyname(const char *);
287 struct protoent	*getprotobynumber(int);
288 struct protoent	*getprotoent(void);
289 struct servent	*getservbyname(const char *, const char *);
290 struct servent	*getservbyport(int, const char *);
291 struct servent	*getservent(void);
292 #if __BSD_VISIBLE
293 void		herror(const char *);
294 const char	*hstrerror(int);
295 #endif
296 void		sethostent(int);
297 /* void		sethostfile(const char *); */
298 void		setnetent(int);
299 void		setprotoent(int);
300 void		setservent(int);
301 
302 #if __BSD_VISIBLE
303 void		endprotoent_r(struct protoent_data *);
304 void		endservent_r(struct servent_data *);
305 int		getprotobyname_r(const char *, struct protoent *,
306 		    struct protoent_data *);
307 int		getprotobynumber_r(int, struct protoent *,
308 		    struct protoent_data *);
309 int		getservbyname_r(const char *, const char *, struct servent *,
310 		    struct servent_data *);
311 int		getservbyport_r(int, const char *, struct servent *,
312 		    struct servent_data *);
313 int		getservent_r(struct servent *, struct servent_data *);
314 int		getprotoent_r(struct protoent *, struct protoent_data *);
315 void		setprotoent_r(int, struct protoent_data *);
316 void		setservent_r(int, struct servent_data *);
317 #endif
318 
319 int		getaddrinfo(const char *, const char *,
320 		    const struct addrinfo *, struct addrinfo **);
321 void		freeaddrinfo(struct addrinfo *);
322 int		getnameinfo(const struct sockaddr *, socklen_t,
323 		    char *, size_t, char *, size_t, int);
324 const char	*gai_strerror(int);
325 
326 #if __BSD_VISIBLE
327 int		getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **);
328 void		freerrset(struct rrsetinfo *);
329 #endif
330 __END_DECLS
331 
332 #endif /* !_NETDB_H_ */
333