xref: /illumos-gate/usr/src/head/netdb.h (revision b4203d757c7c247e39c94c09a94021a3a8121062)
1 /*
2  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
3  *
4  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
5  * Use is subject to license terms.
6  */
7 
8 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
9 /*	  All Rights Reserved	*/
10 
11 /*
12  * BIND 4.9.3:
13  *
14  * Copyright (c) 1980, 1983, 1988, 1993
15  *	The Regents of the University of California.  All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
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.
32  *
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
43  * SUCH DAMAGE.
44  * -
45  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
46  *
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.
53  *
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
61  * SOFTWARE.
62  * --Copyright--
63  *
64  * End BIND 4.9.3
65  */
66 
67 /*
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).
71  */
72 
73 #ifndef _NETDB_H
74 #define	_NETDB_H
75 
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>
82 
83 #ifdef	__cplusplus
84 extern "C" {
85 #endif
86 
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"
95 
96 struct	hostent {
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 */
103 };
104 
105 
106 /*
107  * addrinfo introduced with IPv6 for Protocol-Independent Hostname
108  * and Service Name Translation.
109  */
110 
111 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
112 struct addrinfo {
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 */
117 #ifdef __sparcv9
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 */
124 };
125 
126 /*
127  * The flag 0x8000 is currently reserved for private use between libnsl and
128  * libsocket. See lib/libsocket/inet/getaddrinfo.c for more information.
129  */
130 /* addrinfo flags */
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 */
135 
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 */
140 
141 
142 /*
143  * These were defined in RFC 2553 but not SUSv3
144  * or RFC 3493 which obsoleted 2553.
145  */
146 #if !defined(_XPG6) || defined(__EXTENSIONS__)
147 #define	AI_DEFAULT	(AI_V4MAPPED | AI_ADDRCONFIG)
148 
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
164 #define	EAI_MAX		14
165 
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
172 
173 #if !defined(_XPG6) || defined(__EXTENSIONS__)
174 /* Not listed in any standards document */
175 #define	NI_WITHSCOPEID  0x0020
176 #define	NI_NUMERICSCOPE 0x0040
177 
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__) */
183 
184 /*
185  * Scope delimit character
186  */
187 #define	SCOPE_DELIMITER	'%'
188 
189 
190 /*
191  * Algorithm entry for /etc/inet/ipsecalgs which defines IPsec protocols
192  * and algorithms.
193  */
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 */
205 } ipsecalgent_t;
206 
207 /* well-known IPsec protocol numbers */
208 
209 #define	IPSEC_PROTO_AH		2
210 #define	IPSEC_PROTO_ESP		3
211 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
212 
213 /*
214  * Assumption here is that a network number
215  * fits in 32 bits -- probably a poor one.
216  */
217 struct	netent {
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 # */
222 };
223 
224 struct	protoent {
225 	char	*p_name;	/* official protocol name */
226 	char	**p_aliases;	/* alias list */
227 	int	p_proto;	/* protocol # */
228 };
229 
230 struct	servent {
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 */
235 };
236 
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);
246 
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);
252 
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);
257 
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);
263 
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__) */
267 
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);
280 
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);
284 #else
285 struct hostent	*gethostbyaddr(const void *, size_t, int);
286 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
287 
288 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
289 int endhostent(void);
290 int endnetent(void);
291 int endprotoent(void);
292 int endservent(void);
293 int sethostent(int);
294 int setnetent(int);
295 int setprotoent(int);
296 int setservent(int);
297 #else
298 void endhostent(void);
299 void endnetent(void);
300 void endprotoent(void);
301 void endservent(void);
302 void sethostent(int);
303 void setnetent(int);
304 void setprotoent(int);
305 void setservent(int);
306 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
307 
308 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
309 
310 #ifdef	_XPG6
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 */
316 #endif	/* _XPG6 */
317 
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__) */
328 
329 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
330 int getnetgrent(char **, char **, char **);
331 int setnetgrent(const char *);
332 int endnetgrent(void);
333 int rcmd(char **, unsigned short,
334 	const char *, const char *, const char *, int *);
335 int rcmd_af(char **, unsigned short,
336 	const char *, const char *, const char *, int *, int);
337 int rresvport_af(int *, int);
338 int rresvport_addr(int *, struct sockaddr_storage *);
339 int rexec(char **, unsigned short,
340 	const char *, const char *, const char *, int *);
341 int rexec_af(char **, unsigned short,
342 	const char *, const char *, const char *, int *, int);
343 int rresvport(int *);
344 int ruserok(const char *, int, const char *, const char *);
345 /* BIND */
346 struct hostent	*gethostbyname2(const char *, int);
347 void		herror(const char *);
348 const char	*hstrerror(int);
349 /* End BIND */
350 
351 /* IPsec algorithm prototype definitions */
352 struct ipsecalgent *getipsecalgbyname(const char *, int, int *);
353 struct ipsecalgent *getipsecalgbynum(int, int, int *);
354 int getipsecprotobyname(const char *doi_name);
355 char *getipsecprotobynum(int doi_domain);
356 void freeipsecalgent(struct ipsecalgent *ptr);
357 /* END IPsec algorithm prototype definitions */
358 
359 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
360 
361 /*
362  * Error return codes from gethostbyname() and gethostbyaddr()
363  * (when using the resolver)
364  */
365 
366 extern  int h_errno;
367 
368 #ifdef	_REENTRANT
369 extern int	*__h_errno(void);
370 
371 /* Only #define h_errno if there is no conflict with other use */
372 #ifdef	H_ERRNO_IS_FUNCTION
373 #define	h_errno	(*__h_errno())
374 #endif	/* NO_H_ERRNO_DEFINE */
375 #endif	/* _REENTRANT */
376 
377 /*
378  * Error return codes from gethostbyname() and gethostbyaddr()
379  * (left in extern int h_errno).
380  */
381 #define	HOST_NOT_FOUND	1 /* Authoritive Answer Host not found */
382 #define	TRY_AGAIN	2 /* Non-Authoritive Host not found, or SERVERFAIL */
383 #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
384 #define	NO_DATA		4 /* Valid name, no data record of requested type */
385 
386 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
387 #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
388 
389 /* BIND */
390 #define	NETDB_INTERNAL	-1	/* see errno */
391 #define	NETDB_SUCCESS	0	/* no problem */
392 /* End BIND */
393 
394 #define	MAXHOSTNAMELEN	256
395 
396 #define	MAXALIASES	35
397 #define	MAXADDRS	35
398 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
399 
400 #ifdef	__cplusplus
401 }
402 #endif
403 
404 #endif	/* _NETDB_H */
405