netdb.h revision 1.34 1 /* $NetBSD: netdb.h,v 1.34 2004/03/20 18:22:22 christos Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * 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. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 /*-
33 * Copyright (c) 1980, 1983, 1988, 1993
34 * The Regents of the University of California. All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)netdb.h 8.1 (Berkeley) 6/2/93
61 * Id: netdb.h,v 4.9.1.2 1993/05/17 09:59:01 vixie Exp
62 * -
63 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
64 *
65 * Permission to use, copy, modify, and distribute this software for any
66 * purpose with or without fee is hereby granted, provided that the above
67 * copyright notice and this permission notice appear in all copies, and that
68 * the name of Digital Equipment Corporation not be used in advertising or
69 * publicity pertaining to distribution of the document or software without
70 * specific, written prior permission.
71 *
72 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
73 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
74 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
75 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
76 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
77 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
78 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
79 * SOFTWARE.
80 * -
81 * --Copyright--
82 */
83
84 #ifndef _NETDB_H_
85 #define _NETDB_H_
86
87 #include <machine/ansi.h>
88 #include <sys/ansi.h>
89 #include <sys/cdefs.h>
90 #include <sys/featuretest.h>
91 #include <inttypes.h>
92
93 /*
94 * Data types
95 */
96 #ifndef socklen_t
97 typedef __socklen_t socklen_t;
98 #define socklen_t __socklen_t
99 #endif
100
101 #ifdef _BSD_SIZE_T_
102 typedef _BSD_SIZE_T_ size_t;
103 #undef _BSD_SIZE_T_
104 #endif
105
106 #if defined(_NETBSD_SOURCE)
107 #define _PATH_HEQUIV "/etc/hosts.equiv"
108 #define _PATH_HOSTS "/etc/hosts"
109 #define _PATH_NETWORKS "/etc/networks"
110 #define _PATH_PROTOCOLS "/etc/protocols"
111 #define _PATH_SERVICES "/etc/services"
112 #endif
113
114 extern int h_errno;
115
116 /*
117 * Structures returned by network data base library. All addresses are
118 * supplied in host order, and returned in network order (suitable for
119 * use in system calls).
120 */
121 struct hostent {
122 char *h_name; /* official name of host */
123 char **h_aliases; /* alias list */
124 int h_addrtype; /* host address type */
125 int h_length; /* length of address */
126 char **h_addr_list; /* list of addresses from name server */
127 #define h_addr h_addr_list[0] /* address, for backward compatibility */
128 };
129
130 /*
131 * Assumption here is that a network number
132 * fits in an unsigned long -- probably a poor one.
133 */
134 struct netent {
135 char *n_name; /* official name of net */
136 char **n_aliases; /* alias list */
137 int n_addrtype; /* net address type */
138 unsigned long n_net; /* network # XXX */
139 };
140
141 struct servent {
142 char *s_name; /* official service name */
143 char **s_aliases; /* alias list */
144 int s_port; /* port # */
145 char *s_proto; /* protocol to use */
146 };
147
148 struct protoent {
149 char *p_name; /* official protocol name */
150 char **p_aliases; /* alias list */
151 int p_proto; /* protocol # */
152 };
153
154 /*
155 * Note: ai_addrlen used to be a size_t, per RFC 2553.
156 * In XNS5.2, and subsequently in POSIX-2001 and
157 * draft-ietf-ipngwg-rfc2553bis-02.txt it was changed to a socklen_t.
158 * To accomodate for this while preserving binary compatibility with the
159 * old interface, we prepend or append 32 bits of padding, depending on
160 * the (LP64) architecture's endianness.
161 *
162 * This should be deleted the next time the libc major number is
163 * incremented.
164 */
165 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
166 defined(_NETBSD_SOURCE)
167 struct addrinfo {
168 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
169 int ai_family; /* PF_xxx */
170 int ai_socktype; /* SOCK_xxx */
171 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
172 #if defined(__sparc64__)
173 int __ai_pad0;
174 #endif
175 socklen_t ai_addrlen; /* length of ai_addr */
176 #if defined(__alpha__) || (defined(__i386__) && defined(_LP64))
177 int __ai_pad0;
178 #endif
179 char *ai_canonname; /* canonical name for hostname */
180 struct sockaddr *ai_addr; /* binary address */
181 struct addrinfo *ai_next; /* next structure in linked list */
182 };
183 #endif
184
185 /*
186 * Error return codes from gethostbyname() and gethostbyaddr()
187 * (left in extern int h_errno).
188 */
189
190 #if defined(_NETBSD_SOURCE)
191 #define NETDB_INTERNAL -1 /* see errno */
192 #define NETDB_SUCCESS 0 /* no problem */
193 #endif
194 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
195 #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
196 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
197 #define NO_DATA 4 /* Valid name, no data record of requested type */
198 #if defined(_NETBSD_SOURCE)
199 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
200 #endif
201
202 /*
203 * Error return codes from getaddrinfo()
204 */
205 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
206 defined(_NETBSD_SOURCE)
207 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
208 #define EAI_AGAIN 2 /* temporary failure in name resolution */
209 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
210 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
211 #define EAI_FAMILY 5 /* ai_family not supported */
212 #define EAI_MEMORY 6 /* memory allocation failure */
213 #define EAI_NODATA 7 /* no address associated with hostname */
214 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
215 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
216 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
217 #define EAI_SYSTEM 11 /* system error returned in errno */
218 #define EAI_BADHINTS 12
219 #define EAI_PROTOCOL 13
220 #define EAI_MAX 14
221 #endif /* _POSIX_C_SOURCE >= 200112 || _XOPEN_SOURCE >= 520 || _NETBSD_SOURCE */
222
223 /*
224 * Flag values for getaddrinfo()
225 */
226 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
227 defined(_NETBSD_SOURCE)
228 #define AI_PASSIVE 0x00000001 /* get address to use bind() */
229 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
230 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
231 /* valid flags for addrinfo */
232 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
233 #endif
234
235 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
236 defined(_NETBSD_SOURCE)
237 /*
238 * Constants for getnameinfo()
239 */
240 #if defined(_NETBSD_SOURCE)
241 #define NI_MAXHOST 1025
242 #define NI_MAXSERV 32
243 #endif
244
245 /*
246 * Flag values for getnameinfo()
247 */
248 #define NI_NOFQDN 0x00000001
249 #define NI_NUMERICHOST 0x00000002
250 #define NI_NAMEREQD 0x00000004
251 #define NI_NUMERICSERV 0x00000008
252 #define NI_DGRAM 0x00000010
253 #if defined(_NETBSD_SOURCE)
254 #define NI_WITHSCOPEID 0x00000020 /*KAME extension*/
255 #endif
256
257 /*
258 * Scope delimit character
259 */
260 #if defined(_NETBSD_SOURCE)
261 #define SCOPE_DELIMITER '%' /*KAME extension*/
262 #endif
263 #endif /* (_POSIX_C_SOURCE - 0) >= 200112L || ... */
264
265 __BEGIN_DECLS
266 void endhostent __P((void));
267 void endnetent __P((void));
268 void endprotoent __P((void));
269 void endservent __P((void));
270 #if (_XOPEN_SOURCE - 0) >= 500 && (_XOPEN_SOURCE - 0) < 600 || \
271 defined(_NETBSD_SOURCE)
272 void freehostent __P((struct hostent *));
273 #endif
274 struct hostent *gethostbyaddr __P((const char *, socklen_t, int));
275 struct hostent *gethostbyname __P((const char *));
276 #if defined(_NETBSD_SOURCE)
277 struct hostent *gethostbyname2 __P((const char *, int));
278 #endif
279 struct hostent *gethostent __P((void));
280 #if (_XOPEN_SOURCE - 0) >= 520 && (_XOPEN_SOURCE - 0) < 600 || \
281 defined(_NETBSD_SOURCE)
282 #if 0 /* we do not ship these */
283 struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
284 struct hostent *getipnodebyname __P((const char *, int, int, int *));
285 #endif
286 #endif
287 struct netent *getnetbyaddr __P((unsigned long, int));
288 struct netent *getnetbyname __P((const char *));
289 struct netent *getnetent __P((void));
290 struct protoent *getprotobyname __P((const char *));
291 struct protoent *getprotobynumber __P((int));
292 struct protoent *getprotoent __P((void));
293 struct servent *getservbyname __P((const char *, const char *));
294 struct servent *getservbyport __P((int, const char *));
295 struct servent *getservent __P((void));
296 #if defined(_NETBSD_SOURCE)
297 void herror __P((const char *));
298 const char *hstrerror __P((int));
299 #endif
300 void sethostent __P((int));
301 #if defined(_NETBSD_SOURCE)
302 /* void sethostfile __P((const char *)); */
303 #endif
304 void setnetent __P((int));
305 void setprotoent __P((int));
306 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 520 || \
307 defined(_NETBSD_SOURCE)
308 int getaddrinfo __P((const char *, const char *,
309 const struct addrinfo *, struct addrinfo **));
310 int getnameinfo __P((const struct sockaddr *, socklen_t, char *,
311 socklen_t, char *, socklen_t, int));
312 void freeaddrinfo __P((struct addrinfo *));
313 char *gai_strerror __P((int));
314 #endif
315 void setservent __P((int));
316
317 #if defined(_NETBSD_SOURCE) && defined(_LIBC)
318
319 struct protoent_data {
320 FILE *fp;
321 struct protoent proto;
322 char **aliases;
323 size_t maxaliases;
324 int stayopen;
325 char *line;
326 void *dummy;
327 };
328
329 struct protoent *getprotoent_r __P((struct protoent *, struct protoent_data *));
330 struct protoent *getprotobyname_r __P((const char *,
331 struct protoent *, struct protoent_data *));
332 struct protoent *getprotobynumber_r __P((int,
333 struct protoent *, struct protoent_data *));
334 struct protoent *getprotoent_r __P((struct protoent *, struct protoent_data *));
335 void setprotoent_r __P((int, struct protoent_data *));
336 void endprotoent_r __P((struct protoent_data *));
337
338 struct servent_data {
339 FILE *fp;
340 struct servent serv;
341 char **aliases;
342 size_t maxaliases;
343 int stayopen;
344 char *line;
345 void *dummy;
346 };
347
348 struct servent *getservent_r __P((struct servent *, struct servent_data *));
349 struct servent *getservbyname_r __P((const char *, const char *,
350 struct servent *, struct servent_data *));
351 struct servent *getservbyport_r __P((int, const char *,
352 struct servent *, struct servent_data *));
353 void setservent_r __P((int, struct servent_data *));
354 void endservent_r __P((struct servent_data *));
355
356 #endif /* _NETBSD_SOURCE && _LIBC */
357 __END_DECLS
358
359 #endif /* !_NETDB_H_ */
360