]> git.saurik.com Git - apple/libc.git/blame - include/netdb.h
Libc-262.2.12.tar.gz
[apple/libc.git] / include / netdb.h
CommitLineData
5b2abdfb
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
734aad71 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
5b2abdfb 7 *
734aad71
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
5b2abdfb
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
734aad71
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
5b2abdfb
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * ++Copyright++ 1980, 1983, 1988, 1993
27 * -
28 * Copyright (c) 1980, 1983, 1988, 1993
29 * The Regents of the University of California. All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 * -
59 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
60 *
61 * Permission to use, copy, modify, and distribute this software for any
62 * purpose with or without fee is hereby granted, provided that the above
63 * copyright notice and this permission notice appear in all copies, and that
64 * the name of Digital Equipment Corporation not be used in advertising or
65 * publicity pertaining to distribution of the document or software without
66 * specific, written prior permission.
67 *
68 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
69 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
70 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
71 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
72 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
73 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
74 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
75 * SOFTWARE.
76 * -
77 * --Copyright--
78 */
79
80/*
81 * @(#)netdb.h 8.1 (Berkeley) 6/2/93
82 */
83
84#ifndef _NETDB_H_
85#define _NETDB_H_
86
87#include <sys/param.h>
88#include <sys/cdefs.h>
89
90#define _PATH_HEQUIV "/etc/hosts.equiv"
91#define _PATH_HOSTS "/etc/hosts"
92#define _PATH_NETWORKS "/etc/networks"
93#define _PATH_PROTOCOLS "/etc/protocols"
94#define _PATH_SERVICES "/etc/services"
95
96extern int h_errno;
97
98/*
99 * Structures returned by network data base library. All addresses are
100 * supplied in host order, and returned in network order (suitable for
101 * use in system calls).
102 */
103struct hostent {
104 char *h_name; /* official name of host */
105 char **h_aliases; /* alias list */
106 int h_addrtype; /* host address type */
107 int h_length; /* length of address */
108 char **h_addr_list; /* list of addresses from name server */
109#define h_addr h_addr_list[0] /* address, for backward compatiblity */
110};
111
112/*
113 * Assumption here is that a network number
114 * fits in an unsigned long -- probably a poor one.
115 */
116struct netent {
117 char *n_name; /* official name of net */
118 char **n_aliases; /* alias list */
119 int n_addrtype; /* net address type */
120 unsigned long n_net; /* network # */
121};
122
123struct servent {
124 char *s_name; /* official service name */
125 char **s_aliases; /* alias list */
126 int s_port; /* port # */
127 char *s_proto; /* protocol to use */
128};
129
130struct protoent {
131 char *p_name; /* official protocol name */
132 char **p_aliases; /* alias list */
133 int p_proto; /* protocol # */
134};
135
136struct addrinfo {
137 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
138 int ai_family; /* PF_xxx */
139 int ai_socktype; /* SOCK_xxx */
140 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
141 size_t ai_addrlen; /* length of ai_addr */
142 char *ai_canonname; /* canonical name for hostname */
143 struct sockaddr *ai_addr; /* binary address */
144 struct addrinfo *ai_next; /* next structure in linked list */
145};
146
147struct rpcent {
148 char *r_name; /* name of server for this rpc program */
149 char **r_aliases; /* alias list */
150 int r_number; /* rpc program number */
151};
152
153/*
154 * Error return codes from gethostbyname() and gethostbyaddr()
155 * (left in extern int h_errno).
156 */
157
158#define NETDB_INTERNAL -1 /* see errno */
159#define NETDB_SUCCESS 0 /* no problem */
160#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
161#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
162#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
163#define NO_DATA 4 /* Valid name, no data record of requested type */
164#define NO_ADDRESS NO_DATA /* no address, look for MX record */
165
166/*
167 * Error return codes from getaddrinfo()
168 */
169#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
170#define EAI_AGAIN 2 /* temporary failure in name resolution */
171#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
172#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
173#define EAI_FAMILY 5 /* ai_family not supported */
174#define EAI_MEMORY 6 /* memory allocation failure */
175#define EAI_NODATA 7 /* no address associated with hostname */
176#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
177#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
178#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
179#define EAI_SYSTEM 11 /* system error returned in errno */
180#define EAI_BADHINTS 12
181#define EAI_PROTOCOL 13
182#define EAI_MAX 14
183
184/*
185 * Flag values for getaddrinfo()
186 */
187#define AI_PASSIVE 0x00000001 /* get address to use bind() */
188#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
189#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
190/* valid flags for addrinfo */
191#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
192
193#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
194#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
195#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
196#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
197/* special recommended flags for getipnodebyname */
198#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
199
200/*
201 * Constants for getnameinfo()
202 */
203#define NI_MAXHOST 1025
204#define NI_MAXSERV 32
205
206/*
207 * Flag values for getnameinfo()
208 */
209#define NI_NOFQDN 0x00000001
210#define NI_NUMERICHOST 0x00000002
211#define NI_NAMEREQD 0x00000004
212#define NI_NUMERICSERV 0x00000008
213#define NI_DGRAM 0x00000010
214#define NI_WITHSCOPEID 0x00000020
215
216/*
217 * Scope delimit character
218 */
219#define SCOPE_DELIMITER '%'
220
221__BEGIN_DECLS
222void endhostent __P((void));
223void endnetent __P((void));
224void endprotoent __P((void));
225void endservent __P((void));
226void freehostent __P((struct hostent *));
227struct hostent *gethostbyaddr __P((const char *, int, int));
228struct hostent *gethostbyname __P((const char *));
229struct hostent *gethostbyname2 __P((const char *, int));
230struct hostent *gethostent __P((void));
231struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *));
232struct hostent *getipnodebyname __P((const char *, int, int, int *));
233struct netent *getnetbyaddr __P((long, int));
234struct netent *getnetbyname __P((const char *));
235struct netent *getnetent __P((void));
236struct protoent *getprotobyname __P((const char *));
237struct protoent *getprotobynumber __P((int));
238struct protoent *getprotoent __P((void));
239struct servent *getservbyname __P((const char *, const char *));
240struct servent *getservbyport __P((int, const char *));
241struct servent *getservent __P((void));
242struct rpcent *getrpcbyname __P((const char *name));
243struct rpcent *getrpcbynumber __P((long number));
244struct rpcent *getrpcent __P((void));
245void setrpcent __P((int stayopen));
246void endrpcent __P((void));
247
248void herror __P((const char *));
249char *hstrerror __P((int));
250void sethostent __P((int));
251/* void sethostfile __P((const char *)); */
252void setnetent __P((int));
253void setprotoent __P((int));
254void setservent __P((int));
255
256char *gai_strerror __P((int));
257void freeaddrinfo __P((struct addrinfo *));
258int getaddrinfo __P((const char *, const char *, const struct addrinfo *, struct addrinfo **));
259int getnameinfo __P((const struct sockaddr *, size_t, char *, size_t, char *, size_t, int));
260__END_DECLS
261
262#endif /* !_NETDB_H_ */