2 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
4 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5 * Use is subject to license terms.
8 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
9 /* All Rights Reserved */
14 * Copyright (c) 1980, 1983, 1988, 1993
15 * The Regents of the University of California. All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. All advertising materials mentioning features or use of this software
26 * must display the following acknowledgement:
27 * This product includes software developed by the University of
28 * California, Berkeley and its contributors.
29 * 4. Neither the name of the University nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
47 * Permission to use, copy, modify, and distribute this software for any
48 * purpose with or without fee is hereby granted, provided that the above
49 * copyright notice and this permission notice appear in all copies, and that
50 * the name of Digital Equipment Corporation not be used in advertising or
51 * publicity pertaining to distribution of the document or software without
52 * specific, written prior permission.
54 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
55 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
57 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
58 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
59 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
60 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
68 * Structures returned by network data base library.
69 * All addresses are supplied in host order, and
70 * returned in network order (suitable for use in system calls).
76 #include <sys/types.h>
77 #include <netinet/in.h>
78 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
79 #include <sys/socket.h>
80 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
81 #include <sys/feature_tests.h>
87 #define _PATH_HEQUIV "/etc/hosts.equiv"
88 #define _PATH_HOSTS "/etc/hosts"
89 #define _PATH_IPNODES "/etc/inet/ipnodes"
90 #define _PATH_IPSECALGS "/etc/inet/ipsecalgs"
91 #define _PATH_NETMASKS "/etc/netmasks"
92 #define _PATH_NETWORKS "/etc/networks"
93 #define _PATH_PROTOCOLS "/etc/protocols"
94 #define _PATH_SERVICES "/etc/services"
97 char *h_name
; /* official name of host */
98 char **h_aliases
; /* alias list */
99 int h_addrtype
; /* host address type */
100 int h_length
; /* length of address */
101 char **h_addr_list
; /* list of addresses from name server */
102 #define h_addr h_addr_list[0] /* address, for backward compatiblity */
107 * addrinfo introduced with IPv6 for Protocol-Independent Hostname
108 * and Service Name Translation.
111 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
113 int ai_flags
; /* AI_PASSIVE, AI_CANONNAME, ... */
114 int ai_family
; /* PF_xxx */
115 int ai_socktype
; /* SOCK_xxx */
116 int ai_protocol
; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
118 int _ai_pad
; /* for backwards compat with old size_t */
119 #endif /* __sparcv9 */
120 socklen_t ai_addrlen
;
121 char *ai_canonname
; /* canonical name for hostname */
122 struct sockaddr
*ai_addr
; /* binary address */
123 struct addrinfo
*ai_next
; /* next structure in linked list */
127 * The flag 0x8000 is currently reserved for private use between libnsl and
128 * libsocket. See lib/libsocket/inet/getaddrinfo.c for more information.
131 #define AI_PASSIVE 0x0008 /* intended for bind() + listen() */
132 #define AI_CANONNAME 0x0010 /* return canonical version of host */
133 #define AI_NUMERICHOST 0x0020 /* use numeric node address string */
134 #define AI_NUMERICSERV 0x0040 /* servname is assumed numeric */
136 /* getipnodebyname() flags */
137 #define AI_V4MAPPED 0x0001 /* IPv4 mapped addresses if no IPv6 */
138 #define AI_ALL 0x0002 /* IPv6 and IPv4 mapped addresses */
139 #define AI_ADDRCONFIG 0x0004 /* AAAA or A records only if IPv6/IPv4 cnfg'd */
143 * These were defined in RFC 2553 but not SUSv3
144 * or RFC 3493 which obsoleted 2553.
146 #if !defined(_XPG6) || defined(__EXTENSIONS__)
147 #define AI_DEFAULT (AI_V4MAPPED | AI_ADDRCONFIG)
149 /* addrinfo errors */
150 #define EAI_ADDRFAMILY 1 /* address family not supported */
151 #define EAI_NODATA 7 /* no address */
152 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
153 #define EAI_AGAIN 2 /* DNS temporary failure */
154 #define EAI_BADFLAGS 3 /* invalid ai_flags */
155 #define EAI_FAIL 4 /* DNS non-recoverable failure */
156 #define EAI_FAMILY 5 /* ai_family not supported */
157 #define EAI_MEMORY 6 /* memory allocation failure */
158 #define EAI_NONAME 8 /* host/servname not known */
159 #define EAI_SERVICE 9 /* servname not supported for ai_socktype */
160 #define EAI_SOCKTYPE 10 /* ai_socktype not supported */
161 #define EAI_SYSTEM 11 /* system error in errno */
162 #define EAI_OVERFLOW 12 /* argument buffer overflow */
163 #define EAI_PROTOCOL 13
166 /* getnameinfo flags */
167 #define NI_NOFQDN 0x0001
168 #define NI_NUMERICHOST 0x0002 /* return numeric form of address */
169 #define NI_NAMEREQD 0x0004 /* request DNS name */
170 #define NI_NUMERICSERV 0x0008
171 #define NI_DGRAM 0x0010
173 #if !defined(_XPG6) || defined(__EXTENSIONS__)
174 /* Not listed in any standards document */
175 #define NI_WITHSCOPEID 0x0020
176 #define NI_NUMERICSCOPE 0x0040
178 /* getnameinfo max sizes as defined in RFC 2553 obsoleted in RFC 3493 */
179 #define NI_MAXHOST 1025
180 #define NI_MAXSERV 32
181 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
182 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
185 * Scope delimit character
187 #define SCOPE_DELIMITER '%'
191 * Algorithm entry for /etc/inet/ipsecalgs which defines IPsec protocols
194 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
195 typedef struct ipsecalgent
{
196 char **a_names
; /* algorithm names */
197 int a_proto_num
; /* protocol number */
198 int a_alg_num
; /* algorithm number */
199 char *a_mech_name
; /* encryption framework mechanism name */
200 int *a_block_sizes
; /* supported block sizes */
201 int *a_key_sizes
; /* supported key sizes */
202 int a_key_increment
; /* key size increment */
203 int *a_mech_params
; /* mechanism specific parameters */
204 int a_alg_flags
; /* algorithm flags */
207 /* well-known IPsec protocol numbers */
209 #define IPSEC_PROTO_AH 2
210 #define IPSEC_PROTO_ESP 3
211 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
214 * Assumption here is that a network number
215 * fits in 32 bits -- probably a poor one.
218 char *n_name
; /* official name of net */
219 char **n_aliases
; /* alias list */
220 int n_addrtype
; /* net address type */
221 in_addr_t n_net
; /* network # */
225 char *p_name
; /* official protocol name */
226 char **p_aliases
; /* alias list */
227 int p_proto
; /* protocol # */
231 char *s_name
; /* official service name */
232 char **s_aliases
; /* alias list */
233 int s_port
; /* port # */
234 char *s_proto
; /* protocol to use */
237 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
238 struct hostent
*gethostbyname_r
239 (const char *, struct hostent
*, char *, int, int *h_errnop
);
240 struct hostent
*gethostbyaddr_r
241 (const char *, int, int, struct hostent
*, char *, int, int *h_errnop
);
242 struct hostent
*getipnodebyname(const char *, int, int, int *);
243 struct hostent
*getipnodebyaddr(const void *, size_t, int, int *);
244 void freehostent(struct hostent
*);
245 struct hostent
*gethostent_r(struct hostent
*, char *, int, int *h_errnop
);
247 struct servent
*getservbyname_r
248 (const char *name
, const char *, struct servent
*, char *, int);
249 struct servent
*getservbyport_r
250 (int port
, const char *, struct servent
*, char *, int);
251 struct servent
*getservent_r(struct servent
*, char *, int);
253 struct netent
*getnetbyname_r
254 (const char *, struct netent
*, char *, int);
255 struct netent
*getnetbyaddr_r(long, int, struct netent
*, char *, int);
256 struct netent
*getnetent_r(struct netent
*, char *, int);
258 struct protoent
*getprotobyname_r
259 (const char *, struct protoent
*, char *, int);
260 struct protoent
*getprotobynumber_r
261 (int, struct protoent
*, char *, int);
262 struct protoent
*getprotoent_r(struct protoent
*, char *, int);
264 int getnetgrent_r(char **, char **, char **, char *, int);
265 int innetgr(const char *, const char *, const char *, const char *);
266 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
268 /* Old interfaces that return a pointer to a static area; MT-unsafe */
269 struct hostent
*gethostbyname(const char *);
270 struct hostent
*gethostent(void);
271 struct netent
*getnetbyaddr(in_addr_t
, int);
272 struct netent
*getnetbyname(const char *);
273 struct netent
*getnetent(void);
274 struct protoent
*getprotobyname(const char *);
275 struct protoent
*getprotobynumber(int);
276 struct protoent
*getprotoent(void);
277 struct servent
*getservbyname(const char *, const char *);
278 struct servent
*getservbyport(int, const char *);
279 struct servent
*getservent(void);
281 /* gethostbyaddr() second argument is a size_t only in unix95/unix98 */
282 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
283 struct hostent
*gethostbyaddr(const void *, socklen_t
, int);
285 struct hostent
*gethostbyaddr(const void *, size_t, int);
286 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
288 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
289 int endhostent(void);
291 int endprotoent(void);
292 int endservent(void);
295 int setprotoent(int);
298 void endhostent(void);
299 void endnetent(void);
300 void endprotoent(void);
301 void endservent(void);
302 void sethostent(int);
304 void setprotoent(int);
305 void setservent(int);
306 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
308 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
311 #ifdef __PRAGMA_REDEFINE_EXTNAME
312 #pragma redefine_extname getaddrinfo __xnet_getaddrinfo
313 #else /* __PRAGMA_REDEFINE_EXTNAME */
314 #define getaddrinfo __xnet_getaddrinfo
315 #endif /* __PRAGMA_REDEFINE_EXTNAME */
318 int getaddrinfo(const char *_RESTRICT_KYWD
,
319 const char *_RESTRICT_KYWD
,
320 const struct addrinfo
*_RESTRICT_KYWD
,
321 struct addrinfo
**_RESTRICT_KYWD
);
322 void freeaddrinfo(struct addrinfo
*);
323 const char *gai_strerror(int);
324 int getnameinfo(const struct sockaddr
*_RESTRICT_KYWD
,
325 socklen_t
, char *_RESTRICT_KYWD
, socklen_t
,
326 char *_RESTRICT_KYWD
, socklen_t
, int);
327 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
329 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
330 int getnetgrent(char **, char **, char **);
331 int setnetgrent(const char *);
332 int endnetgrent(void);
334 struct hostent
*gethostbyname2(const char *, int);
335 void herror(const char *);
336 const char *hstrerror(int);
339 /* IPsec algorithm prototype definitions */
340 struct ipsecalgent
*getipsecalgbyname(const char *, int, int *);
341 struct ipsecalgent
*getipsecalgbynum(int, int, int *);
342 int getipsecprotobyname(const char *doi_name
);
343 char *getipsecprotobynum(int doi_domain
);
344 void freeipsecalgent(struct ipsecalgent
*ptr
);
345 /* END IPsec algorithm prototype definitions */
347 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
350 * Error return codes from gethostbyname() and gethostbyaddr()
351 * (when using the resolver)
356 extern int *__h_errno(void);
358 /* Only #define h_errno if there is no conflict with other use */
359 #ifdef H_ERRNO_IS_FUNCTION
360 #define h_errno (*__h_errno())
361 #endif /* NO_H_ERRNO_DEFINE */
364 * Error return codes from gethostbyname() and gethostbyaddr()
365 * (left in extern int h_errno).
367 #define HOST_NOT_FOUND 1 /* Authoritive Answer Host not found */
368 #define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
369 #define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
370 #define NO_DATA 4 /* Valid name, no data record of requested type */
372 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
373 #define NO_ADDRESS NO_DATA /* no address, look for MX record */
376 #define NETDB_INTERNAL -1 /* see errno */
377 #define NETDB_SUCCESS 0 /* no problem */
380 #define MAXHOSTNAMELEN 256
382 #define MAXALIASES 35
384 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
390 #endif /* _NETDB_H */