vfs: check userland buffers before reading them.
[haiku.git] / headers / posix / netdb.h
blob8efd82f3ba96c68e964b83578f9f6f3bf399d180
1 /*
2 * Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 /*
7 * Copyright (c) 1980, 1983, 1988, 1993
8 * The Regents of the University of California. All rights reserved.
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.
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.
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.
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.
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.
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.
87 #ifndef _NETDB_H_
88 #define _NETDB_H_
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>
98 #ifndef _PATH_NETWORKS
99 #define _PATH_NETWORKS "/etc/networks"
100 #endif
103 __BEGIN_DECLS
104 extern int * __h_errno(void);
105 __END_DECLS
106 #define h_errno (*__h_errno())
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).
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 compatiblity */
123 * Assumption here is that a network number
124 * fits in an unsigned long -- probably a poor one.
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 # */
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 */
140 struct protoent {
141 char *p_name; /* official protocol name */
142 char **p_aliases; /* alias list */
143 int p_proto; /* protocol # */
146 struct addrinfo {
147 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
148 int ai_family; /* PF_xxx */
149 int ai_socktype; /* SOCK_xxx */
150 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
151 socklen_t ai_addrlen; /* length of ai_addr */
152 char *ai_canonname; /* canonical name for hostname */
153 struct sockaddr *ai_addr; /* binary address */
154 struct addrinfo *ai_next; /* next structure in linked list */
158 * Error return codes from gethostbyname() and gethostbyaddr()
159 * (left in extern int h_errno).
161 #define NETDB_INTERNAL -1 /* see errno */
162 #define NETDB_SUCCESS 0 /* no problem */
163 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
164 #define TRY_AGAIN 2
165 /* Non-Authoritive Host not found, or SERVERFAIL */
166 #define NO_RECOVERY 3
167 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
168 #define NO_DATA 4
169 /* Valid name, no data record of requested type */
170 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
173 * Error return codes from getaddrinfo()
175 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
176 #define EAI_AGAIN 2 /* temporary failure in name resolution */
177 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
178 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
179 #define EAI_FAMILY 5 /* ai_family not supported */
180 #define EAI_MEMORY 6 /* memory allocation failure */
181 #define EAI_NODATA 7 /* no address associated with hostname */
182 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
183 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
184 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
185 #define EAI_SYSTEM 11 /* system error returned in errno */
186 #define EAI_BADHINTS 12
187 #define EAI_PROTOCOL 13
188 #define EAI_OVERFLOW 14
189 #define EAI_MAX 15
192 * Flag values for getaddrinfo()
194 #define AI_PASSIVE 0x00000001
195 #define AI_CANONNAME 0x00000002
196 #define AI_NUMERICHOST 0x00000004
197 #define AI_NUMERICSERV 0x00000008
198 #define AI_MASK \
199 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV \
200 | AI_ADDRCONFIG)
203 * Flag values for getipnodebyname()
205 #define AI_ALL 0x00000100
206 #define AI_V4MAPPED_CFG 0x00000200
207 #define AI_ADDRCONFIG 0x00000400
208 #define AI_V4MAPPED 0x00000800
209 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
212 * Constants for getnameinfo()
214 #define NI_MAXHOST 1025
215 #define NI_MAXSERV 32
218 * Flag values for getnameinfo()
220 #define NI_NOFQDN 0x00000001
221 #define NI_NUMERICHOST 0x00000002
222 #define NI_NAMEREQD 0x00000004
223 #define NI_NUMERICSERV 0x00000008
224 #define NI_DGRAM 0x00000010
225 #define NI_WITHSCOPEID 0x00000020
226 #define NI_NUMERICSCOPE 0x00000040
229 * Scope delimit character
231 #define SCOPE_DELIMITER '%'
234 __BEGIN_DECLS
235 void endhostent(void);
236 void endnetent(void);
237 void endprotoent(void);
238 void endservent(void);
239 void freehostent(struct hostent *host);
240 struct hostent *gethostbyaddr(const char *address, socklen_t length, int type);
241 struct hostent *gethostbyname(const char *name);
242 struct hostent *gethostbyname2(const char *name, int type);
243 struct hostent *gethostent(void);
244 struct hostent *getipnodebyaddr(const void *, size_t, int, int *);
245 struct hostent *getipnodebyname(const char *, int, int, int *);
246 struct netent *getnetbyaddr(uint32_t, int);
247 struct netent *getnetbyname(const char *);
248 struct netent *getnetent(void);
249 struct protoent *getprotobyname(const char *);
250 struct protoent *getprotobynumber(int);
251 struct protoent *getprotoent(void);
252 struct servent *getservbyname(const char *, const char *);
253 struct servent *getservbyport(int, const char *);
254 struct servent *getservent(void);
255 void herror(const char *);
256 const char *hstrerror(int);
257 void sethostent(int);
258 /* void sethostfile(const char *); */
259 void setnetent(int);
260 void setprotoent(int);
261 void setservent(int);
262 int getaddrinfo(const char *, const char *,
263 const struct addrinfo *, struct addrinfo **);
264 int getnameinfo(const struct sockaddr *, socklen_t, char *,
265 socklen_t, char *, socklen_t, int);
266 struct addrinfo *allocaddrinfo(socklen_t);
267 void freeaddrinfo(struct addrinfo *);
268 const char *gai_strerror(int);
270 struct hostent *gethostent_r(struct hostent *, char *, int, int *);
271 void sethostent_r(int);
272 void endhostent_r(void);
274 struct netent *getnetbyname_r(const char *, struct netent *,
275 char *, int);
276 struct netent *getnetbyaddr_r(long, int, struct netent *,
277 char *, int);
278 struct netent *getnetent_r(struct netent *, char *, int);
279 void setnetent_r(int);
280 void endnetent_r(void);
282 struct protoent_data;
283 struct protoent *getprotobyname_r(const char *,
284 struct protoent *, struct protoent_data *);
285 struct protoent *getprotobynumber_r(int,
286 struct protoent *, struct protoent_data *);
287 struct protoent *getprotoent_r(struct protoent *, struct protoent_data *);
288 void setprotoent_r(int, struct protoent_data *);
289 void endprotoent_r(struct protoent_data *);
291 struct servent_data;
292 struct servent *getservbyname_r(const char *name, const char *,
293 struct servent *, struct servent_data *);
294 struct servent *getservbyport_r(int port, const char *,
295 struct servent *, struct servent_data *);
296 struct servent *getservent_r(struct servent *, struct servent_data *);
297 void setservent_r(int, struct servent_data *);
298 void endservent_r(struct servent_data *);
299 __END_DECLS
301 #endif /* _NETDB_H_ */