ahci: Whitespace and line length cleanup only.
[haiku.git] / headers / posix / netdb.h
blob7e1455443fd74745833947ac83721d31dbf7b46f
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 #include <pthread.h>
100 #ifndef _PATH_NETWORKS
101 #define _PATH_NETWORKS "/etc/networks"
102 #endif
105 __BEGIN_DECLS
106 extern int * __h_errno(void);
107 __END_DECLS
108 #define h_errno (*__h_errno())
111 * Structures returned by network data base library. All addresses are
112 * supplied in host order, and returned in network order (suitable for
113 * use in system calls).
115 struct hostent {
116 char *h_name; /* official name of host */
117 char **h_aliases; /* alias list */
118 int h_addrtype; /* host address type */
119 int h_length; /* length of address */
120 char **h_addr_list; /* list of addresses from name server */
121 #define h_addr h_addr_list[0] /* address, for backward compatiblity */
125 * Assumption here is that a network number
126 * fits in an unsigned long -- probably a poor one.
128 struct netent {
129 char *n_name; /* official name of net */
130 char **n_aliases; /* alias list */
131 int n_addrtype; /* net address type */
132 in_addr_t n_net; /* network # */
135 struct servent {
136 char *s_name; /* official service name */
137 char **s_aliases; /* alias list */
138 int s_port; /* port # */
139 char *s_proto; /* protocol to use */
142 struct protoent {
143 char *p_name; /* official protocol name */
144 char **p_aliases; /* alias list */
145 int p_proto; /* protocol # */
148 struct addrinfo {
149 int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
150 int ai_family; /* PF_xxx */
151 int ai_socktype; /* SOCK_xxx */
152 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
153 socklen_t ai_addrlen; /* length of ai_addr */
154 char *ai_canonname; /* canonical name for hostname */
155 struct sockaddr *ai_addr; /* binary address */
156 struct addrinfo *ai_next; /* next structure in linked list */
160 * Error return codes from gethostbyname() and gethostbyaddr()
161 * (left in extern int h_errno).
163 #define NETDB_INTERNAL -1 /* see errno */
164 #define NETDB_SUCCESS 0 /* no problem */
165 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
166 #define TRY_AGAIN 2
167 /* Non-Authoritive Host not found, or SERVERFAIL */
168 #define NO_RECOVERY 3
169 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
170 #define NO_DATA 4
171 /* Valid name, no data record of requested type */
172 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
175 * Error return codes from getaddrinfo()
177 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
178 #define EAI_AGAIN 2 /* temporary failure in name resolution */
179 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
180 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
181 #define EAI_FAMILY 5 /* ai_family not supported */
182 #define EAI_MEMORY 6 /* memory allocation failure */
183 #define EAI_NODATA 7 /* no address associated with hostname */
184 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
185 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
186 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
187 #define EAI_SYSTEM 11 /* system error returned in errno */
188 #define EAI_BADHINTS 12
189 #define EAI_PROTOCOL 13
190 #define EAI_OVERFLOW 14
191 #define EAI_MAX 15
194 * Flag values for getaddrinfo()
196 #define AI_PASSIVE 0x00000001
197 #define AI_CANONNAME 0x00000002
198 #define AI_NUMERICHOST 0x00000004
199 #define AI_NUMERICSERV 0x00000008
200 #define AI_MASK \
201 (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV \
202 | AI_ADDRCONFIG)
205 * Flag values for getipnodebyname()
207 #define AI_ALL 0x00000100
208 #define AI_V4MAPPED_CFG 0x00000200
209 #define AI_ADDRCONFIG 0x00000400
210 #define AI_V4MAPPED 0x00000800
211 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
214 * Constants for getnameinfo()
216 #define NI_MAXHOST 1025
217 #define NI_MAXSERV 32
220 * Flag values for getnameinfo()
222 #define NI_NOFQDN 0x00000001
223 #define NI_NUMERICHOST 0x00000002
224 #define NI_NAMEREQD 0x00000004
225 #define NI_NUMERICSERV 0x00000008
226 #define NI_DGRAM 0x00000010
227 #define NI_WITHSCOPEID 0x00000020
228 #define NI_NUMERICSCOPE 0x00000040
231 * Scope delimit character
233 #define SCOPE_DELIMITER '%'
236 __BEGIN_DECLS
237 void endhostent(void);
238 void endnetent(void);
239 void endprotoent(void);
240 void endservent(void);
241 void freehostent(struct hostent *host);
242 struct hostent *gethostbyaddr(const char *address, socklen_t length, int type);
243 struct hostent *gethostbyname(const char *name);
244 struct hostent *gethostbyname2(const char *name, int type);
245 struct hostent *gethostent(void);
246 struct hostent *getipnodebyaddr(const void *, size_t, int, int *);
247 struct hostent *getipnodebyname(const char *, int, int, int *);
248 struct netent *getnetbyaddr(uint32_t, int);
249 struct netent *getnetbyname(const char *);
250 struct netent *getnetent(void);
251 struct protoent *getprotobyname(const char *);
252 struct protoent *getprotobynumber(int);
253 struct protoent *getprotoent(void);
254 struct servent *getservbyname(const char *, const char *);
255 struct servent *getservbyport(int, const char *);
256 struct servent *getservent(void);
257 void herror(const char *);
258 const char *hstrerror(int);
259 void sethostent(int);
260 /* void sethostfile(const char *); */
261 void setnetent(int);
262 void setprotoent(int);
263 void setservent(int);
264 int getaddrinfo(const char *, const char *,
265 const struct addrinfo *, struct addrinfo **);
266 int getnameinfo(const struct sockaddr *, socklen_t, char *,
267 socklen_t, char *, socklen_t, int);
268 struct addrinfo *allocaddrinfo(socklen_t);
269 void freeaddrinfo(struct addrinfo *);
270 const char *gai_strerror(int);
272 struct hostent *gethostent_r(struct hostent *, char *, int, int *);
273 void sethostent_r(int);
274 void endhostent_r(void);
276 struct netent *getnetbyname_r(const char *, struct netent *,
277 char *, int);
278 struct netent *getnetbyaddr_r(long, int, struct netent *,
279 char *, int);
280 struct netent *getnetent_r(struct netent *, char *, int);
281 void setnetent_r(int);
282 void endnetent_r(void);
284 struct protoent_data;
285 struct protoent *getprotobyname_r(const char *,
286 struct protoent *, struct protoent_data *);
287 struct protoent *getprotobynumber_r(int,
288 struct protoent *, struct protoent_data *);
289 struct protoent *getprotoent_r(struct protoent *, struct protoent_data *);
290 void setprotoent_r(int, struct protoent_data *);
291 void endprotoent_r(struct protoent_data *);
293 struct servent_data;
294 struct servent *getservbyname_r(const char *name, const char *,
295 struct servent *, struct servent_data *);
296 struct servent *getservbyport_r(int port, const char *,
297 struct servent *, struct servent_data *);
298 struct servent *getservent_r(struct servent *, struct servent_data *);
299 void setservent_r(int, struct servent_data *);
300 void endservent_r(struct servent_data *);
301 __END_DECLS
303 #endif /* _NETDB_H_ */