xref: /titanic_41/usr/src/head/netdb.h (revision c037192b037119c9fd354732fc29b38ce097d356)
1 /*
2  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * BIND 4.9.3:
11  *
12  * Copyright (c) 1980, 1983, 1988, 1993
13  *	The Regents of the University of California.  All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  * 3. All advertising materials mentioning features or use of this software
24  *    must display the following acknowledgement:
25  *	This product includes software developed by the University of
26  *	California, Berkeley and its contributors.
27  * 4. Neither the name of the University nor the names of its contributors
28  *    may be used to endorse or promote products derived from this software
29  *    without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
32  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
39  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
40  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41  * SUCH DAMAGE.
42  * -
43  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
44  *
45  * Permission to use, copy, modify, and distribute this software for any
46  * purpose with or without fee is hereby granted, provided that the above
47  * copyright notice and this permission notice appear in all copies, and that
48  * the name of Digital Equipment Corporation not be used in advertising or
49  * publicity pertaining to distribution of the document or software without
50  * specific, written prior permission.
51  *
52  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
53  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
54  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
55  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
56  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
57  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
58  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
59  * SOFTWARE.
60  * --Copyright--
61  *
62  * End BIND 4.9.3
63  */
64 
65 /*
66  * Structures returned by network data base library.
67  * All addresses are supplied in host order, and
68  * returned in network order (suitable for use in system calls).
69  */
70 
71 #ifndef _NETDB_H
72 #define	_NETDB_H
73 
74 #include <sys/types.h>
75 #include <netinet/in.h>
76 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
77 #include <sys/socket.h>
78 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
79 #include <sys/feature_tests.h>
80 
81 #ifdef	__cplusplus
82 extern "C" {
83 #endif
84 
85 #define	_PATH_HEQUIV	"/etc/hosts.equiv"
86 #define	_PATH_HOSTS	"/etc/hosts"
87 #define	_PATH_IPNODES	"/etc/inet/ipnodes"
88 #define	_PATH_IPSECALGS	"/etc/inet/ipsecalgs"
89 #define	_PATH_NETMASKS	"/etc/netmasks"
90 #define	_PATH_NETWORKS	"/etc/networks"
91 #define	_PATH_PROTOCOLS	"/etc/protocols"
92 #define	_PATH_SERVICES	"/etc/services"
93 
94 struct	hostent {
95 	char	*h_name;	/* official name of host */
96 	char	**h_aliases;	/* alias list */
97 	int	h_addrtype;	/* host address type */
98 	int	h_length;	/* length of address */
99 	char	**h_addr_list;	/* list of addresses from name server */
100 #define	h_addr	h_addr_list[0]	/* address, for backward compatiblity */
101 };
102 
103 
104 /*
105  * addrinfo introduced with IPv6 for Protocol-Independent Hostname
106  * and Service Name Translation.
107  */
108 
109 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
110 struct addrinfo {
111 	int ai_flags;		/* AI_PASSIVE, AI_CANONNAME, ... */
112 	int ai_family;		/* PF_xxx */
113 	int ai_socktype;	/* SOCK_xxx */
114 	int ai_protocol;	/* 0 or IPPROTO_xxx for IPv4 and IPv6 */
115 #ifdef __sparcv9
116 	int _ai_pad;		/* for backwards compat with old size_t */
117 #endif /* __sparcv9 */
118 	socklen_t ai_addrlen;
119 	char *ai_canonname;	/* canonical name for hostname */
120 	struct sockaddr *ai_addr;	/* binary address */
121 	struct addrinfo *ai_next;	/* next structure in linked list */
122 };
123 
124 
125 /* addrinfo flags */
126 #define	AI_PASSIVE	0x0008	/* intended for bind() + listen() */
127 #define	AI_CANONNAME	0x0010	/* return canonical version of host */
128 #define	AI_NUMERICHOST	0x0020	/* use numeric node address string */
129 #define	AI_NUMERICSERV	0x0040	/* servname is assumed numeric */
130 
131 /* getipnodebyname() flags */
132 #define	AI_V4MAPPED	0x0001	/* IPv4 mapped addresses if no IPv6 */
133 #define	AI_ALL		0x0002	/* IPv6 and IPv4 mapped addresses */
134 #define	AI_ADDRCONFIG	0x0004	/* AAAA or A records only if IPv6/IPv4 cnfg'd */
135 
136 
137 /*
138  * These were defined in RFC 2553 but not SUSv3
139  * or RFC 3493 which obsoleted 2553.
140  */
141 #if !defined(_XPG6) || defined(__EXTENSIONS__)
142 #define	AI_DEFAULT	(AI_V4MAPPED | AI_ADDRCONFIG)
143 
144 /* addrinfo errors */
145 #define	EAI_ADDRFAMILY	1	/* address family not supported */
146 #define	EAI_NODATA	7	/* no address */
147 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
148 #define	EAI_AGAIN	2	/* DNS temporary failure */
149 #define	EAI_BADFLAGS	3	/* invalid ai_flags */
150 #define	EAI_FAIL	4	/* DNS non-recoverable failure */
151 #define	EAI_FAMILY	5	/* ai_family not supported */
152 #define	EAI_MEMORY	6	/* memory allocation failure */
153 #define	EAI_NONAME	8	/* host/servname not known */
154 #define	EAI_SERVICE	9	/* servname not supported for ai_socktype */
155 #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
156 #define	EAI_SYSTEM	11	/* system error in errno */
157 #define	EAI_OVERFLOW	12	/* argument buffer overflow */
158 #define	EAI_PROTOCOL	13
159 #define	EAI_MAX		14
160 
161 /* getnameinfo flags */
162 #define	NI_NOFQDN	0x0001
163 #define	NI_NUMERICHOST	0x0002	/* return numeric form of address */
164 #define	NI_NAMEREQD	0x0004	/* request DNS name */
165 #define	NI_NUMERICSERV	0x0008
166 #define	NI_DGRAM	0x0010
167 
168 #if !defined(_XPG6) || defined(__EXTENSIONS__)
169 /* Not listed in any standards document */
170 #define	NI_WITHSCOPEID  0x0020
171 #define	NI_NUMERICSCOPE 0x0040
172 
173 /* getnameinfo max sizes as defined in RFC 2553 obsoleted in RFC 3493 */
174 #define	NI_MAXHOST	1025
175 #define	NI_MAXSERV	32
176 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
177 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
178 
179 /*
180  * Scope delimit character
181  */
182 #define	SCOPE_DELIMITER	'%'
183 
184 
185 /*
186  * Algorithm entry for /etc/inet/ipsecalgs which defines IPsec protocols
187  * and algorithms.
188  */
189 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
190 typedef struct ipsecalgent {
191 	char **a_names;		/* algorithm names */
192 	int a_proto_num;	/* protocol number */
193 	int a_alg_num;		/* algorithm number */
194 	char *a_mech_name;	/* encryption framework mechanism name */
195 	int *a_block_sizes;	/* supported block sizes */
196 	int *a_key_sizes;	/* supported key sizes */
197 	int a_key_increment;	/* key size increment */
198 	int *a_mech_params;	/* mechanism specific parameters */
199 	int a_alg_flags;	/* algorithm flags */
200 } ipsecalgent_t;
201 
202 /* well-known IPsec protocol numbers */
203 
204 #define	IPSEC_PROTO_AH		2
205 #define	IPSEC_PROTO_ESP		3
206 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
207 
208 /*
209  * Assumption here is that a network number
210  * fits in 32 bits -- probably a poor one.
211  */
212 struct	netent {
213 	char		*n_name;	/* official name of net */
214 	char		**n_aliases;	/* alias list */
215 	int		n_addrtype;	/* net address type */
216 	in_addr_t	n_net;		/* network # */
217 };
218 
219 struct	protoent {
220 	char	*p_name;	/* official protocol name */
221 	char	**p_aliases;	/* alias list */
222 	int	p_proto;	/* protocol # */
223 };
224 
225 struct	servent {
226 	char	*s_name;	/* official service name */
227 	char	**s_aliases;	/* alias list */
228 	int	s_port;		/* port # */
229 	char	*s_proto;	/* protocol to use */
230 };
231 
232 #ifdef	__STDC__
233 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
234 struct hostent	*gethostbyname_r
235 	(const char *, struct hostent *, char *, int, int *h_errnop);
236 struct hostent	*gethostbyaddr_r
237 	(const char *, int, int, struct hostent *, char *, int, int *h_errnop);
238 struct hostent	*getipnodebyname(const char *, int, int, int *);
239 struct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
240 void		freehostent(struct hostent *);
241 struct hostent	*gethostent_r(struct hostent *, char *, int, int *h_errnop);
242 
243 struct servent	*getservbyname_r
244 	(const char *name, const char *, struct servent *, char *, int);
245 struct servent	*getservbyport_r
246 	(int port, const char *, struct servent *, char *, int);
247 struct servent	*getservent_r(struct	servent *, char *, int);
248 
249 struct netent	*getnetbyname_r
250 	(const char *, struct netent *, char *, int);
251 struct netent	*getnetbyaddr_r(long, int, struct netent *, char *, int);
252 struct netent	*getnetent_r(struct netent *, char *, int);
253 
254 struct protoent	*getprotobyname_r
255 	(const char *, struct protoent *, char *, int);
256 struct protoent	*getprotobynumber_r
257 	(int, struct protoent *, char *, int);
258 struct protoent	*getprotoent_r(struct protoent *, char *, int);
259 
260 int getnetgrent_r(char **, char **, char **, char *, int);
261 int innetgr(const char *, const char *, const char *, const char *);
262 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
263 
264 /* Old interfaces that return a pointer to a static area;  MT-unsafe */
265 struct hostent	*gethostbyname(const char *);
266 struct hostent	*gethostent(void);
267 struct netent	*getnetbyaddr(in_addr_t, int);
268 struct netent	*getnetbyname(const char *);
269 struct netent	*getnetent(void);
270 struct protoent	*getprotobyname(const char *);
271 struct protoent	*getprotobynumber(int);
272 struct protoent	*getprotoent(void);
273 struct servent	*getservbyname(const char *, const char *);
274 struct servent	*getservbyport(int, const char *);
275 struct servent	*getservent(void);
276 
277 /* gethostbyaddr() second argument is a size_t only in unix95/unix98 */
278 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
279 struct hostent	*gethostbyaddr(const void *, socklen_t, int);
280 #else
281 struct hostent	*gethostbyaddr(const void *, size_t, int);
282 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
283 
284 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
285 int endhostent(void);
286 int endnetent(void);
287 int endprotoent(void);
288 int endservent(void);
289 int sethostent(int);
290 int setnetent(int);
291 int setprotoent(int);
292 int setservent(int);
293 #else
294 void endhostent(void);
295 void endnetent(void);
296 void endprotoent(void);
297 void endservent(void);
298 void sethostent(int);
299 void setnetent(int);
300 void setprotoent(int);
301 void setservent(int);
302 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
303 
304 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
305 
306 #ifdef	_XPG6
307 #ifdef	__PRAGMA_REDEFINE_EXTNAME
308 #pragma redefine_extname getaddrinfo __xnet_getaddrinfo
309 #else	/* __PRAGMA_REDEFINE_EXTNAME */
310 #define	getaddrinfo __xnet_getaddrinfo
311 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
312 #endif	/* _XPG6 */
313 
314 int		getaddrinfo(const char *_RESTRICT_KYWD,
315 			const char *_RESTRICT_KYWD,
316 			const struct addrinfo *_RESTRICT_KYWD,
317 			struct addrinfo **_RESTRICT_KYWD);
318 void		freeaddrinfo(struct addrinfo *);
319 const char	*gai_strerror(int);
320 int		getnameinfo(const struct sockaddr *_RESTRICT_KYWD,
321 			socklen_t, char *_RESTRICT_KYWD, socklen_t,
322 			char *_RESTRICT_KYWD, socklen_t, int);
323 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
324 
325 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
326 int getnetgrent(char **, char **, char **);
327 int setnetgrent(const char *);
328 int endnetgrent(void);
329 int rcmd(char **, unsigned short,
330 	const char *, const char *, const char *, int *);
331 int rcmd_af(char **, unsigned short,
332 	const char *, const char *, const char *, int *, int);
333 int rresvport_af(int *, int);
334 int rresvport_addr(int *, struct sockaddr_storage *);
335 int rexec(char **, unsigned short,
336 	const char *, const char *, const char *, int *);
337 int rexec_af(char **, unsigned short,
338 	const char *, const char *, const char *, int *, int);
339 int rresvport(int *);
340 int ruserok(const char *, int, const char *, const char *);
341 /* BIND */
342 struct hostent	*gethostbyname2(const char *, int);
343 void		herror(const char *);
344 const char	*hstrerror(int);
345 /* End BIND */
346 
347 /* IPsec algorithm prototype definitions */
348 struct ipsecalgent *getipsecalgbyname(const char *, int, int *);
349 struct ipsecalgent *getipsecalgbynum(int, int, int *);
350 int getipsecprotobyname(const char *doi_name);
351 char *getipsecprotobynum(int doi_domain);
352 void freeipsecalgent(struct ipsecalgent *ptr);
353 /* END IPsec algorithm prototype definitions */
354 
355 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
356 #else	/* __STDC__ */
357 struct hostent	*gethostbyname_r();
358 struct hostent	*gethostbyaddr_r();
359 struct hostent	*getipnodebyname();
360 struct hostent	*getipnodebyaddr();
361 void		 freehostent();
362 struct hostent	*gethostent_r();
363 struct servent	*getservbyname_r();
364 struct servent	*getservbyport_r();
365 struct servent	*getservent_r();
366 struct netent	*getnetbyname_r();
367 struct netent	*getnetbyaddr_r();
368 struct netent	*getnetent_r();
369 struct protoent	*getprotobyname_r();
370 struct protoent	*getprotobynumber_r();
371 struct protoent	*getprotoent_r();
372 int		 getnetgrent_r();
373 int		 innetgr();
374 
375 /* Old interfaces that return a pointer to a static area;  MT-unsafe */
376 struct hostent	*gethostbyname();
377 struct hostent	*gethostbyaddr();
378 struct hostent	*gethostent();
379 struct netent	*getnetbyname();
380 struct netent	*getnetbyaddr();
381 struct netent	*getnetent();
382 struct servent	*getservbyname();
383 struct servent	*getservbyport();
384 struct servent	*getservent();
385 struct protoent	*getprotobyname();
386 struct protoent	*getprotobynumber();
387 struct protoent	*getprotoent();
388 int		 getnetgrent();
389 
390 int sethostent();
391 int endhostent();
392 int setnetent();
393 int endnetent();
394 int setservent();
395 int endservent();
396 int setprotoent();
397 int endprotoent();
398 int setnetgrent();
399 int endnetgrent();
400 int rcmd();
401 int rcmd_af();
402 int rexec();
403 int rexec_af();
404 int rresvport();
405 int rresvport_af();
406 int rresvport_addr();
407 int ruserok();
408 /* BIND */
409 struct hostent	*gethostbyname2();
410 void		herror();
411 char		*hstrerror();
412 /* IPv6 prototype definitons */
413 int		getaddrinfo();
414 void		freeaddrinfo();
415 const char	*gai_strerror();
416 int		getnameinfo();
417 /* END IPv6 prototype definitions */
418 /* End BIND */
419 
420 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
421 /* IPsec algorithm prototype definitions */
422 struct ipsecalgent *getalgbyname();
423 struct ipsecalgent *getalgbydoi();
424 int getdoidomainbyname();
425 const char *getdoidomainbynum();
426 void freealgent();
427 /* END IPsec algorithm prototype definitions */
428 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
429 
430 #endif	/* __STDC__ */
431 
432 /*
433  * Error return codes from gethostbyname() and gethostbyaddr()
434  * (when using the resolver)
435  */
436 
437 extern  int h_errno;
438 
439 #ifdef	_REENTRANT
440 #ifdef	__STDC__
441 extern int	*__h_errno(void);
442 #else
443 extern int	*__h_errno();
444 #endif	/* __STDC__ */
445 
446 /* Only #define h_errno if there is no conflict with other use */
447 #ifdef	H_ERRNO_IS_FUNCTION
448 #define	h_errno	(*__h_errno())
449 #endif	/* NO_H_ERRNO_DEFINE */
450 #endif	/* _REENTRANT */
451 
452 /*
453  * Error return codes from gethostbyname() and gethostbyaddr()
454  * (left in extern int h_errno).
455  */
456 #define	HOST_NOT_FOUND	1 /* Authoritive Answer Host not found */
457 #define	TRY_AGAIN	2 /* Non-Authoritive Host not found, or SERVERFAIL */
458 #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
459 #define	NO_DATA		4 /* Valid name, no data record of requested type */
460 
461 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
462 #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
463 
464 /* BIND */
465 #define	NETDB_INTERNAL	-1	/* see errno */
466 #define	NETDB_SUCCESS	0	/* no problem */
467 /* End BIND */
468 
469 #define	MAXHOSTNAMELEN	256
470 
471 #define	MAXALIASES	35
472 #define	MAXADDRS	35
473 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
474 
475 #ifdef	__cplusplus
476 }
477 #endif
478 
479 #endif	/* _NETDB_H */
480