xref: /haiku/headers/posix/netdb.h (revision 220d04022750f40f8bac8f01fa551211e28d04f2)
1 /*
2  * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 /*
7  * Copyright (c) 1980, 1983, 1988, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  * -
38  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
39  *
40  * Permission to use, copy, modify, and distribute this software for any
41  * purpose with or without fee is hereby granted, provided that the above
42  * copyright notice and this permission notice appear in all copies, and that
43  * the name of Digital Equipment Corporation not be used in advertising or
44  * publicity pertaining to distribution of the document or software without
45  * specific, written prior permission.
46  *
47  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
48  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
49  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
50  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
51  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
52  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
53  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
54  * SOFTWARE.
55  * -
56  * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
57  * All rights reserved.
58  *
59  * Redistribution and use in source and binary forms, with or without
60  * modification, are permitted provided that the following conditions
61  * are met:
62  * 1. Redistributions of source code must retain the above copyright
63  *    notice, this list of conditions and the following disclaimer.
64  * 2. Redistributions in binary form must reproduce the above copyright
65  *    notice, this list of conditions and the following disclaimer in the
66  *    documentation and/or other materials provided with the distribution.
67  * 3. All advertising materials mentioning features or use of this software
68  *    must display the following acknowledgement:
69  *    This product includes software developed by WIDE Project and
70  *    its contributors.
71  * 4. Neither the name of the project nor the names of its contributors
72  *    may be used to endorse or promote products derived from this software
73  *    without specific prior written permission.
74  *
75  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
76  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
77  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
78  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
79  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
80  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
81  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
82  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
83  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
84  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
85  * SUCH DAMAGE.
86  */
87 #ifndef _NETDB_H_
88 #define _NETDB_H_
89 
90 
91 #include <sys/param.h>
92 #include <sys/types.h>
93 #include <sys/cdefs.h>
94 #include <sys/socket.h>
95 #include <netinet/in.h>
96 #include <stdio.h>
97 
98 
99 #ifndef _PATH_NETWORKS
100 #define	_PATH_NETWORKS	"/etc/networks"
101 #endif
102 
103 
104 __BEGIN_DECLS
105 extern int * __h_errno(void);
106 __END_DECLS
107 #define	h_errno (*__h_errno())
108 
109 /*
110  * Structures returned by network data base library.  All addresses are
111  * supplied in host order, and returned in network order (suitable for
112  * use in system calls).
113  */
114 struct hostent {
115 	char		*h_name;			/* official name of host */
116 	char		**h_aliases;		/* alias list */
117 	int			h_addrtype;			/* host address type */
118 	int			h_length;			/* length of address */
119 	char		**h_addr_list;		/* list of addresses from name server */
120 #define	h_addr	h_addr_list[0]		/* address, for backward compatiblity */
121 };
122 
123 /*
124  * Assumption here is that a network number
125  * fits in an unsigned long -- probably a poor one.
126  */
127 struct netent {
128 	char		*n_name;			/* official name of net */
129 	char		**n_aliases;		/* alias list */
130 	int			n_addrtype;			/* net address type */
131 	unsigned long n_net;			/* network # */
132 };
133 
134 struct servent {
135 	char		*s_name;			/* official service name */
136 	char		**s_aliases;		/* alias list */
137 	int			s_port;				/* port # */
138 	char		*s_proto;			/* protocol to use */
139 };
140 
141 struct protoent {
142 	char		*p_name;			/* official protocol name */
143 	char		**p_aliases;		/* alias list */
144 	int			p_proto;			/* protocol # */
145 };
146 
147 struct addrinfo {
148 	int			ai_flags;			/* AI_PASSIVE, AI_CANONNAME */
149 	int			ai_family;			/* PF_xxx */
150 	int			ai_socktype;		/* SOCK_xxx */
151 	int			ai_protocol;		/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
152 	socklen_t	ai_addrlen;			/* length of ai_addr */
153 	char		*ai_canonname;		/* canonical name for hostname */
154 	struct sockaddr	*ai_addr; 		/* binary address */
155 	struct addrinfo	*ai_next; 		/* next structure in linked list */
156 };
157 
158 /*
159  * Error return codes from gethostbyname() and gethostbyaddr()
160  * (left in extern int h_errno).
161  */
162 #define	NETDB_INTERNAL	-1		/* see errno */
163 #define	NETDB_SUCCESS	0		/* no problem */
164 #define	HOST_NOT_FOUND	1		/* Authoritative Answer Host not found */
165 #define	TRY_AGAIN		2
166 	/* Non-Authoritive Host not found, or SERVERFAIL */
167 #define	NO_RECOVERY		3
168 	/* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
169 #define	NO_DATA			4
170 	/* Valid name, no data record of requested type */
171 #define	NO_ADDRESS		NO_DATA	/* no address, look for MX record */
172 
173 /*
174  * Error return codes from getaddrinfo()
175  */
176 #define	EAI_ADDRFAMILY	1	/* address family for hostname not supported */
177 #define	EAI_AGAIN	 	2	/* temporary failure in name resolution */
178 #define	EAI_BADFLAGS	3	/* invalid value for ai_flags */
179 #define	EAI_FAIL		4	/* non-recoverable failure in name resolution */
180 #define	EAI_FAMILY		5	/* ai_family not supported */
181 #define	EAI_MEMORY		6	/* memory allocation failure */
182 #define	EAI_NODATA		7	/* no address associated with hostname */
183 #define	EAI_NONAME		8	/* hostname nor servname provided, or not known */
184 #define	EAI_SERVICE		9	/* servname not supported for ai_socktype */
185 #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
186 #define	EAI_SYSTEM		11	/* system error returned in errno */
187 #define EAI_BADHINTS	12
188 #define EAI_PROTOCOL	13
189 #define EAI_OVERFLOW	14
190 #define EAI_MAX			15
191 
192 /*
193  * Flag values for getaddrinfo()
194  */
195 #define	AI_PASSIVE		0x00000001
196 #define	AI_CANONNAME	0x00000002
197 #define AI_NUMERICHOST	0x00000004
198 #define AI_NUMERICSERV	0x00000008
199 #define	AI_MASK			\
200 	(AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV \
201 		| AI_ADDRCONFIG)
202 
203 /*
204  * Flag values for getipnodebyname()
205  */
206 #define AI_ALL			0x00000100
207 #define AI_V4MAPPED_CFG	0x00000200
208 #define AI_ADDRCONFIG	0x00000400
209 #define AI_V4MAPPED		0x00000800
210 #define AI_DEFAULT		(AI_V4MAPPED_CFG | AI_ADDRCONFIG)
211 
212 /*
213  * Constants for getnameinfo()
214  */
215 #define	NI_MAXHOST		1025
216 #define	NI_MAXSERV		32
217 
218 /*
219  * Flag values for getnameinfo()
220  */
221 #define	NI_NOFQDN		0x00000001
222 #define	NI_NUMERICHOST	0x00000002
223 #define	NI_NAMEREQD		0x00000004
224 #define	NI_NUMERICSERV	0x00000008
225 #define	NI_DGRAM		0x00000010
226 #define	NI_WITHSCOPEID	0x00000020
227 #define NI_NUMERICSCOPE	0x00000040
228 
229 /*
230  * Scope delimit character
231  */
232 #define SCOPE_DELIMITER	'%'
233 
234 
235 __BEGIN_DECLS
236 void			endhostent(void);
237 void			endnetent(void);
238 void			endprotoent(void);
239 void			endservent(void);
240 void			freehostent(struct hostent *host);
241 struct hostent	*gethostbyaddr(const char *address, int length, int type);
242 struct hostent	*gethostbyname(const char *name);
243 struct hostent	*gethostbyname2(const char *name, int type);
244 struct hostent	*gethostent(void);
245 struct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
246 struct hostent	*getipnodebyname(const char *, int, int, int *);
247 struct netent	*getnetbyaddr(unsigned long, int);
248 struct netent	*getnetbyname(const char *);
249 struct netent	*getnetent(void);
250 struct protoent	*getprotobyname(const char *);
251 struct protoent	*getprotobynumber(int);
252 struct protoent	*getprotoent(void);
253 struct servent	*getservbyname(const char *, const char *);
254 struct servent	*getservbyport(int, const char *);
255 struct servent	*getservent(void);
256 void			herror(const char *);
257 const char		*hstrerror(int);
258 void			sethostent(int);
259 /* void			sethostfile(const char *); */
260 void			setnetent(int);
261 void			setprotoent(int);
262 void			setservent(int);
263 int				getaddrinfo(const char *, const char *,
264 					const struct addrinfo *, struct addrinfo **);
265 int				getnameinfo(const struct sockaddr *, socklen_t, char *,
266 					socklen_t, char *, socklen_t, int);
267 void			freeaddrinfo(struct addrinfo *);
268 const char		*gai_strerror(int);
269 
270 struct hostent	*gethostbyaddr_r(const char *, int, int, struct hostent *,
271 					char *, int, int *);
272 struct hostent	*gethostbyname_r(const char *, struct hostent *,
273 					char *, int, int *);
274 struct hostent	*gethostent_r(struct hostent *, char *, int, int *);
275 void			sethostent_r(int);
276 void			endhostent_r(void);
277 
278 struct netent	*getnetbyname_r(const char *, struct netent *,
279 					char *, int);
280 struct netent	*getnetbyaddr_r(long, int, struct netent *,
281 					char *, int);
282 struct netent	*getnetent_r(struct netent *, char *, int);
283 void			setnetent_r(int);
284 void			endnetent_r(void);
285 
286 struct protoent	*getprotobyname_r(const char *,
287 				struct protoent *, char *, int);
288 struct protoent	*getprotobynumber_r(int,
289 				struct protoent *, char *, int);
290 struct protoent	*getprotoent_r(struct protoent *, char *, int);
291 void			setprotoent_r(int);
292 void			endprotoent_r(void);
293 
294 struct servent	*getservbyname_r(const char *name, const char *,
295 					struct servent *, char *, int);
296 struct servent	*getservbyport_r(int port, const char *,
297 					struct servent *, char *, int);
298 struct servent	*getservent_r(struct servent *, char *, int);
299 void			setservent_r(int);
300 void			endservent_r(void);
301 __END_DECLS
302 
303 #endif /* _NETDB_H_ */
304