xref: /haiku/headers/posix/netdb.h (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 /*
2  * ++Copyright++ 1980, 1983, 1988, 1993
3  * -
4  * Copyright (c) 1980, 1983, 1988, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  * -
35  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
36  *
37  * Permission to use, copy, modify, and distribute this software for any
38  * purpose with or without fee is hereby granted, provided that the above
39  * copyright notice and this permission notice appear in all copies, and that
40  * the name of Digital Equipment Corporation not be used in advertising or
41  * publicity pertaining to distribution of the document or software without
42  * specific, written prior permission.
43  *
44  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
45  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
46  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
47  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
48  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
49  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
50  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
51  * SOFTWARE.
52  * -
53  * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
54  * All rights reserved.
55  *
56  * Redistribution and use in source and binary forms, with or without
57  * modification, are permitted provided that the following conditions
58  * are met:
59  * 1. Redistributions of source code must retain the above copyright
60  *    notice, this list of conditions and the following disclaimer.
61  * 2. Redistributions in binary form must reproduce the above copyright
62  *    notice, this list of conditions and the following disclaimer in the
63  *    documentation and/or other materials provided with the distribution.
64  * 3. All advertising materials mentioning features or use of this software
65  *    must display the following acknowledgement:
66  *    This product includes software developed by WIDE Project and
67  *    its contributors.
68  * 4. Neither the name of the project nor the names of its contributors
69  *    may be used to endorse or promote products derived from this software
70  *    without specific prior written permission.
71  *
72  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
73  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
75  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
76  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
77  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
78  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
80  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
81  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
82  * SUCH DAMAGE.
83  * -
84  * --Copyright--
85  */
86 
87 /*
88  *      @(#)netdb.h	8.1 (Berkeley) 6/2/93
89  *	$Id: netdb.h,v 1.7 2004/04/15 15:54:33 wkornew Exp $
90  */
91 
92 #ifndef _NETDB_H_
93 #define _NETDB_H_
94 
95 #include <sys/param.h>
96 #include <sys/types.h>
97 #if (!defined(BSD)) || (BSD < 199306)
98 # include <sys/bitypes.h>
99 #endif
100 #include <sys/cdefs.h>
101 #include <sys/socket.h>
102 #include <netinet/in.h>
103 #include <stdio.h>
104 
105 #ifndef _PATH_HEQUIV
106 #define _PATH_HEQUIV	"/etc/hosts.equiv"
107 #endif
108 #ifndef _PATH_HOSTS
109 #define	_PATH_HOSTS	"/etc/hosts"
110 #endif
111 #ifndef _PATH_NETWORKS
112 #define	_PATH_NETWORKS	"/etc/networks"
113 #endif
114 #ifndef _PATH_PROTOCOLS
115 #define	_PATH_PROTOCOLS	"/etc/protocols"
116 #endif
117 #ifndef _PATH_SERVICES
118 #define	_PATH_SERVICES	"/etc/services"
119 #endif
120 
121 __BEGIN_DECLS
122 extern int * __h_errno __P((void));
123 __END_DECLS
124 #define	h_errno (*__h_errno())
125 
126 /*
127  * Structures returned by network data base library.  All addresses are
128  * supplied in host order, and returned in network order (suitable for
129  * use in system calls).
130  */
131 struct	hostent {
132 	char	*h_name;	/* official name of host */
133 	char	**h_aliases;	/* alias list */
134 	int	h_addrtype;	/* host address type */
135 	int	h_length;	/* length of address */
136 	char	**h_addr_list;	/* list of addresses from name server */
137 #define	h_addr	h_addr_list[0]	/* address, for backward compatiblity */
138 };
139 
140 /*
141  * Assumption here is that a network number
142  * fits in an unsigned long -- probably a poor one.
143  */
144 struct	netent {
145 	char		*n_name;	/* official name of net */
146 	char		**n_aliases;	/* alias list */
147 	int		n_addrtype;	/* net address type */
148 	unsigned long	n_net;		/* network # */
149 };
150 
151 struct	servent {
152 	char	*s_name;	/* official service name */
153 	char	**s_aliases;	/* alias list */
154 	int	s_port;		/* port # */
155 	char	*s_proto;	/* protocol to use */
156 };
157 
158 struct	protoent {
159 	char	*p_name;	/* official protocol name */
160 	char	**p_aliases;	/* alias list */
161 	int	p_proto;	/* protocol # */
162 };
163 
164 struct	addrinfo {
165 	int		ai_flags;	/* AI_PASSIVE, AI_CANONNAME */
166 	int		ai_family;	/* PF_xxx */
167 	int		ai_socktype;	/* SOCK_xxx */
168 	int		ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
169 	size_t		ai_addrlen;	/* length of ai_addr */
170 	char		*ai_canonname;	/* canonical name for hostname */
171 	struct sockaddr	*ai_addr; 	/* binary address */
172 	struct addrinfo	*ai_next; 	/* next structure in linked list */
173 };
174 
175 /*
176  * Error return codes from gethostbyname() and gethostbyaddr()
177  * (left in extern int h_errno).
178  */
179 
180 #define	NETDB_INTERNAL	-1	/* see errno */
181 #define	NETDB_SUCCESS	0	/* no problem */
182 #define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */
183 #define	TRY_AGAIN	2 /* Non-Authoritive Host not found, or SERVERFAIL */
184 #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
185 #define	NO_DATA		4 /* Valid name, no data record of requested type */
186 #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
187 
188 /*
189  * Error return codes from getaddrinfo()
190  */
191 #define	EAI_ADDRFAMILY	 1	/* address family for hostname not supported */
192 #define	EAI_AGAIN	 2	/* temporary failure in name resolution */
193 #define	EAI_BADFLAGS	 3	/* invalid value for ai_flags */
194 #define	EAI_FAIL	 4	/* non-recoverable failure in name resolution */
195 #define	EAI_FAMILY	 5	/* ai_family not supported */
196 #define	EAI_MEMORY	 6	/* memory allocation failure */
197 #define	EAI_NODATA	 7	/* no address associated with hostname */
198 #define	EAI_NONAME	 8	/* hostname nor servname provided, or not known */
199 #define	EAI_SERVICE	 9	/* servname not supported for ai_socktype */
200 #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
201 #define	EAI_SYSTEM	11	/* system error returned in errno */
202 #define EAI_BADHINTS	12
203 #define EAI_PROTOCOL	13
204 #define EAI_MAX		14
205 
206 /*
207  * Flag values for getaddrinfo()
208  */
209 #define	AI_PASSIVE	0x00000001
210 #define	AI_CANONNAME	0x00000002
211 #define AI_NUMERICHOST	0x00000004
212 #define	AI_MASK		0x00000007
213 
214 /*
215  * Flag values for getipnodebyname()
216  */
217 #define AI_V4MAPPED	0x00000008
218 #define AI_ALL		0x00000010
219 #define AI_ADDRCONFIG	0x00000020
220 #define AI_DEFAULT	(AI_V4MAPPED|AI_ADDRCONFIG)
221 
222 /*
223  * Constants for getnameinfo()
224  */
225 #define	NI_MAXHOST	1025
226 #define	NI_MAXSERV	32
227 
228 /*
229  * Flag values for getnameinfo()
230  */
231 #define	NI_NOFQDN	0x00000001
232 #define	NI_NUMERICHOST	0x00000002
233 #define	NI_NAMEREQD	0x00000004
234 #define	NI_NUMERICSERV	0x00000008
235 #define	NI_DGRAM	0x00000010
236 #define	NI_WITHSCOPEID	0x00000020
237 #define NI_NUMERICSCOPE	0x00000040
238 
239 /*
240  * Scope delimit character
241  */
242 #define SCOPE_DELIMITER	'%'
243 
244 
245 #if defined (__hpux) || defined(__osf__) || defined(_AIX)
246 #define	_MAXALIASES	35
247 #define	_MAXLINELEN	1024
248 #define	_MAXADDRS	35
249 #define	_HOSTBUFSIZE	(BUFSIZ + 1)
250 
251 struct hostent_data {
252 	struct in_addr	host_addr;
253 	char		*h_addr_ptrs[_MAXADDRS + 1];
254 	char		hostaddr[_MAXADDRS];
255 	char		hostbuf[_HOSTBUFSIZE];
256 	char		*host_aliases[_MAXALIASES];
257 	char		*host_addrs[2];
258 	FILE		*hostf;
259 #ifdef __osf__
260 	int		svc_gethostflag;
261 	int		svc_gethostbind;
262 #endif
263 #ifdef __hpux
264 	short		_nsw_src;
265 	short		_flags;
266 	char		*current;
267 	int		currentlen;
268 #endif
269 };
270 
271 struct  netent_data {
272 	FILE	*net_fp;
273 #ifdef __osf__
274 	char	line[_MAXLINELEN];
275 #endif
276 #ifdef __hpux
277 	char	line[_MAXLINELEN+1];
278 #endif
279 	char	*net_aliases[_MAXALIASES];
280 #ifdef __osf__
281 	int	_net_stayopen;
282 	int	svc_getnetflag;
283 #endif
284 #ifdef __hpux
285 	short	_nsw_src;
286 	short	_flags;
287 	char	*current;
288 	int	currentlen;
289 #endif
290 };
291 
292 struct	protoent_data {
293 	FILE	*proto_fp;
294 #ifdef __osf__
295 	char	line[1024];
296 #endif
297 #ifdef __hpux
298 	char	line[_MAXLINELEN+1];
299 #endif
300 	char	*proto_aliases[_MAXALIASES];
301 #ifdef __osf__
302 	int	_proto_stayopen;
303 	int	svc_getprotoflag;
304 #endif
305 #ifdef __hpux
306 	short	_nsw_src;
307 	short	_flags;
308 	char	*current;
309 	int	currentlen;
310 #endif
311 };
312 
313 struct	servent_data {
314 	FILE	*serv_fp;
315 #ifdef __osf__
316 	char	line[_MAXLINELEN];
317 #endif
318 #ifdef __hpux
319 	char	line[_MAXLINELEN+1];
320 #endif
321 	char	*serv_aliases[_MAXALIASES];
322 #ifdef __osf__
323 	int	_serv_stayopen;
324 	int	svc_getservflag;
325 #endif
326 #ifdef __hpux
327 	short	_nsw_src;
328 	short	_flags;
329 	char	*current;
330 	int	currentlen;
331 #endif
332 };
333 #endif
334 
335 __BEGIN_DECLS
336 void		endhostent __P((void));
337 void		endnetent __P((void));
338 void		endprotoent __P((void));
339 void		endservent __P((void));
340 void		freehostent __P((struct hostent *));
341 struct hostent	*gethostbyaddr __P((const char *, int, int));
342 struct hostent	*gethostbyname __P((const char *));
343 struct hostent	*gethostbyname2 __P((const char *, int));
344 struct hostent	*gethostent __P((void));
345 struct hostent	*getipnodebyaddr __P((const void *, size_t, int, int *));
346 struct hostent	*getipnodebyname __P((const char *, int, int, int *));
347 struct netent	*getnetbyaddr __P((unsigned long, int));
348 struct netent	*getnetbyname __P((const char *));
349 struct netent	*getnetent __P((void));
350 struct protoent	*getprotobyname __P((const char *));
351 struct protoent	*getprotobynumber __P((int));
352 struct protoent	*getprotoent __P((void));
353 struct servent	*getservbyname __P((const char *, const char *));
354 struct servent	*getservbyport __P((int, const char *));
355 struct servent	*getservent __P((void));
356 void		herror __P((const char *));
357 const char	*hstrerror __P((int));
358 void		sethostent __P((int));
359 /* void		sethostfile __P((const char *)); */
360 void		setnetent __P((int));
361 void		setprotoent __P((int));
362 void		setservent __P((int));
363 int		getaddrinfo __P((const char *, const char *,
364 				 const struct addrinfo *, struct addrinfo **));
365 int		getnameinfo __P((const struct sockaddr *, size_t, char *,
366 				 size_t, char *, size_t, int));
367 void		freeaddrinfo __P((struct addrinfo *));
368 const char	*gai_strerror __P((int));
369 struct hostent  *getipnodebyname __P((const char *, int, int, int *));
370 struct hostent	*getipnodebyaddr __P((const void *, size_t, int, int *));
371 void		freehostent __P((struct hostent *));
372 
373 
374 struct hostent	*gethostbyaddr_r __P((const char *, int, int, struct hostent *,
375 					char *, int, int *));
376 struct hostent	*gethostbyname_r __P((const char *, struct hostent *,
377 					char *, int, int *));
378 struct hostent	*gethostent_r __P((struct hostent *, char *, int, int *));
379 void		sethostent_r __P((int));
380 void		endhostent_r __P((void));
381 
382 struct netent	*getnetbyname_r __P((const char *, struct netent *,
383 					char *, int));
384 struct netent	*getnetbyaddr_r __P((long, int, struct netent *,
385 					char *, int));
386 struct netent	*getnetent_r __P((struct netent *, char *, int));
387 void		setnetent_r __P((int));
388 void		endnetent_r __P((void));
389 
390 struct protoent	*getprotobyname_r __P((const char *,
391 				struct protoent *, char *, int));
392 struct protoent	*getprotobynumber_r __P((int,
393 				struct protoent *, char *, int));
394 struct protoent	*getprotoent_r __P((struct protoent *, char *, int));
395 void		setprotoent_r __P((int));
396 void		endprotoent_r __P((void));
397 
398 struct servent	*getservbyname_r __P((const char *name, const char *,
399 					struct servent *, char *, int));
400 struct servent	*getservbyport_r __P((int port, const char *,
401 					struct servent *, char *, int));
402 struct servent	*getservent_r __P((struct servent *, char *, int));
403 void		setservent_r __P((int));
404 void		endservent_r __P((void));
405 __END_DECLS
406 
407 /* This is nec'y to make this include file properly replace the sun version. */
408 #ifdef sun
409 #ifdef __GNU_LIBRARY__
410 #include <rpc/netdb.h>
411 #else
412 struct rpcent {
413 	char	*r_name;	/* name of server for this rpc program */
414 	char	**r_aliases;	/* alias list */
415 	int	r_number;	/* rpc program number */
416 };
417 struct rpcent	*getrpcbyname(), *getrpcbynumber(), *getrpcent();
418 #endif /* __GNU_LIBRARY__ */
419 #endif /* sun */
420 
421 #endif /* !_NETDB_H_ */
422