2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
26 * ++Copyright++ 1980, 1983, 1988, 1993
28 * Copyright (c) 1980, 1983, 1988, 1993
29 * The Regents of the University of California. All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
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.
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
59 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
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.
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
81 * @(#)netdb.h 8.1 (Berkeley) 6/2/93
87 #include <sys/param.h>
88 #include <sys/cdefs.h>
89 #include <sys/socket.h>
91 #define _PATH_HEQUIV "/etc/hosts.equiv"
92 #define _PATH_HOSTS "/etc/hosts"
93 #define _PATH_NETWORKS "/etc/networks"
94 #define _PATH_PROTOCOLS "/etc/protocols"
95 #define _PATH_SERVICES "/etc/services"
100 * Structures returned by network data base library. All addresses are
101 * supplied in host order, and returned in network order (suitable for
102 * use in system calls).
105 char *h_name
; /* official name of host */
106 char **h_aliases
; /* alias list */
107 int h_addrtype
; /* host address type */
108 int h_length
; /* length of address */
109 char **h_addr_list
; /* list of addresses from name server */
110 #define h_addr h_addr_list[0] /* address, for backward compatiblity */
114 * Assumption here is that a network number
115 * fits in an unsigned long -- probably a poor one.
118 char *n_name
; /* official name of net */
119 char **n_aliases
; /* alias list */
120 int n_addrtype
; /* net address type */
121 unsigned long n_net
; /* network # */
125 char *s_name
; /* official service name */
126 char **s_aliases
; /* alias list */
127 int s_port
; /* port # */
128 char *s_proto
; /* protocol to use */
132 char *p_name
; /* official protocol name */
133 char **p_aliases
; /* alias list */
134 int p_proto
; /* protocol # */
138 int ai_flags
; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
139 int ai_family
; /* PF_xxx */
140 int ai_socktype
; /* SOCK_xxx */
141 int ai_protocol
; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
142 size_t ai_addrlen
; /* length of ai_addr */
143 char *ai_canonname
; /* canonical name for hostname */
144 struct sockaddr
*ai_addr
; /* binary address */
145 struct addrinfo
*ai_next
; /* next structure in linked list */
149 char *r_name
; /* name of server for this rpc program */
150 char **r_aliases
; /* alias list */
151 int r_number
; /* rpc program number */
155 * Error return codes from gethostbyname() and gethostbyaddr()
156 * (left in extern int h_errno).
159 #define NETDB_INTERNAL -1 /* see errno */
160 #define NETDB_SUCCESS 0 /* no problem */
161 #define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
162 #define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
163 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
164 #define NO_DATA 4 /* Valid name, no data record of requested type */
165 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
168 * Error return codes from getaddrinfo()
170 #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
171 #define EAI_AGAIN 2 /* temporary failure in name resolution */
172 #define EAI_BADFLAGS 3 /* invalid value for ai_flags */
173 #define EAI_FAIL 4 /* non-recoverable failure in name resolution */
174 #define EAI_FAMILY 5 /* ai_family not supported */
175 #define EAI_MEMORY 6 /* memory allocation failure */
176 #define EAI_NODATA 7 /* no address associated with hostname */
177 #define EAI_NONAME 8 /* hostname nor servname provided, or not known */
178 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
179 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
180 #define EAI_SYSTEM 11 /* system error returned in errno */
181 #define EAI_BADHINTS 12
182 #define EAI_PROTOCOL 13
186 * Flag values for getaddrinfo()
188 #define AI_PASSIVE 0x00000001 /* get address to use bind() */
189 #define AI_CANONNAME 0x00000002 /* fill ai_canonname */
190 #define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
191 /* valid flags for addrinfo */
192 #define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
194 #define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
195 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
196 #define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
197 #define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
198 /* special recommended flags for getipnodebyname */
199 #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
202 * Constants for getnameinfo()
204 #define NI_MAXHOST 1025
205 #define NI_MAXSERV 32
208 * Flag values for getnameinfo()
210 #define NI_NOFQDN 0x00000001
211 #define NI_NUMERICHOST 0x00000002
212 #define NI_NAMEREQD 0x00000004
213 #define NI_NUMERICSERV 0x00000008
214 #define NI_DGRAM 0x00000010
215 #define NI_WITHSCOPEID 0x00000020
218 * Scope delimit character
220 #define SCOPE_DELIMITER '%'
223 void endhostent(void);
224 void endnetent(void);
225 void endprotoent(void);
226 void endservent(void);
227 void freehostent(struct hostent
*);
228 struct hostent
*gethostbyaddr(const char *, int, int);
229 struct hostent
*gethostbyname(const char *);
230 struct hostent
*gethostbyname2(const char *, int);
231 struct hostent
*gethostent(void);
232 struct hostent
*getipnodebyaddr(const void *, size_t, int, int *);
233 struct hostent
*getipnodebyname(const char *, int, int, int *);
234 struct netent
*getnetbyaddr(long, int);
235 struct netent
*getnetbyname(const char *);
236 struct netent
*getnetent(void);
237 struct protoent
*getprotobyname(const char *);
238 struct protoent
*getprotobynumber(int);
239 struct protoent
*getprotoent(void);
240 struct servent
*getservbyname(const char *, const char *);
241 struct servent
*getservbyport(int, const char *);
242 struct servent
*getservent(void);
243 struct rpcent
*getrpcbyname(const char *name
);
244 struct rpcent
*getrpcbynumber(long number
);
245 struct rpcent
*getrpcent(void);
246 void setrpcent(int stayopen
);
247 void endrpcent(void);
249 void herror(const char *);
250 const char *hstrerror(int);
251 int innetgr(const char *, const char *, const char *, const char *);
252 void sethostent(int);
253 /* void sethostfile(const char *); */
255 void setprotoent(int);
256 void setservent(int);
257 const char *gai_strerror(int);
258 void freeaddrinfo(struct addrinfo
*);
259 int getaddrinfo(const char *, const char *, const struct addrinfo
*, struct addrinfo
**);
260 int getnameinfo(const struct sockaddr
*, socklen_t
, char *, size_t, char *, size_t, int);
263 #endif /* !_NETDB_H_ */