xref: /titanic_50/usr/src/head/netdb.h (revision 29e83d4b25fd82feb8e0e0fbe89f7e2a8438533d)
1 /*
2  * Copyright 2003 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
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 /* 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  * These were defined in RFC 2553 but not SUSv3
138  * or RFC 3493 which obsoleted 2553.
139  */
140 #if !defined(_XPG6) || defined(__EXTENSIONS__)
141 #define	AI_DEFAULT	(AI_V4MAPPED | AI_ADDRCONFIG)
142 
143 /* addrinfo errors */
144 #define	EAI_ADDRFAMILY	1	/* address family not supported */
145 #define	EAI_NODATA	7	/* no address */
146 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
147 #define	EAI_AGAIN	2	/* DNS temporary failure */
148 #define	EAI_BADFLAGS	3	/* invalid ai_flags */
149 #define	EAI_FAIL	4	/* DNS non-recoverable failure */
150 #define	EAI_FAMILY	5	/* ai_family not supported */
151 #define	EAI_MEMORY	6	/* memory allocation failure */
152 #define	EAI_NONAME	8	/* host/servname not known */
153 #define	EAI_SERVICE	9	/* servname not supported for ai_socktype */
154 #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
155 #define	EAI_SYSTEM	11	/* system error in errno */
156 #define	EAI_OVERFLOW	12	/* argument buffer overflow */
157 
158 /* getnameinfo flags */
159 #define	NI_NOFQDN	0x0001
160 #define	NI_NUMERICHOST	0x0002	/* return numeric form of address */
161 #define	NI_NAMEREQD	0x0004	/* request DNS name */
162 #define	NI_NUMERICSERV	0x0008
163 #define	NI_DGRAM	0x0010
164 
165 #if !defined(_XPG6) || defined(__EXTENSIONS__)
166 /* Not listed in any standards document */
167 #define	NI_WITHSCOPEID  0x0020
168 #define	NI_NUMERICSCOPE 0x0040
169 
170 /* getnameinfo max sizes as defined in RFC 2553 obsoleted in RFC 3493 */
171 #define	NI_MAXHOST	1025
172 #define	NI_MAXSERV	32
173 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
174 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
175 
176 /*
177  * Algorithm entry for /etc/inet/ipsecalgs which defines IPsec protocols
178  * and algorithms.
179  */
180 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
181 typedef struct ipsecalgent {
182 	char **a_names;		/* algorithm names */
183 	int a_proto_num;	/* protocol number */
184 	int a_alg_num;		/* algorithm number */
185 	char *a_mech_name;	/* encryption framework mechanism name */
186 	int *a_block_sizes;	/* supported block sizes */
187 	int *a_key_sizes;	/* supported key sizes */
188 	int a_key_increment;	/* key size increment */
189 } ipsecalgent_t;
190 
191 /* well-known IPsec protocol numbers */
192 
193 #define	IPSEC_PROTO_AH		2
194 #define	IPSEC_PROTO_ESP		3
195 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
196 
197 /*
198  * Assumption here is that a network number
199  * fits in 32 bits -- probably a poor one.
200  */
201 struct	netent {
202 	char		*n_name;	/* official name of net */
203 	char		**n_aliases;	/* alias list */
204 	int		n_addrtype;	/* net address type */
205 	in_addr_t	n_net;		/* network # */
206 };
207 
208 struct	protoent {
209 	char	*p_name;	/* official protocol name */
210 	char	**p_aliases;	/* alias list */
211 	int	p_proto;	/* protocol # */
212 };
213 
214 struct	servent {
215 	char	*s_name;	/* official service name */
216 	char	**s_aliases;	/* alias list */
217 	int	s_port;		/* port # */
218 	char	*s_proto;	/* protocol to use */
219 };
220 
221 #ifdef	__STDC__
222 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
223 struct hostent	*gethostbyname_r
224 	(const char *, struct hostent *, char *, int, int *h_errnop);
225 struct hostent	*gethostbyaddr_r
226 	(const char *, int, int, struct hostent *, char *, int, int *h_errnop);
227 struct hostent	*getipnodebyname(const char *, int, int, int *);
228 struct hostent	*getipnodebyaddr(const void *, size_t, int, int *);
229 void		freehostent(struct hostent *);
230 struct hostent	*gethostent_r(struct hostent *, char *, int, int *h_errnop);
231 
232 struct servent	*getservbyname_r
233 	(const char *name, const char *, struct servent *, char *, int);
234 struct servent	*getservbyport_r
235 	(int port, const char *, struct servent *, char *, int);
236 struct servent	*getservent_r(struct	servent *, char *, int);
237 
238 struct netent	*getnetbyname_r
239 	(const char *, struct netent *, char *, int);
240 struct netent	*getnetbyaddr_r(long, int, struct netent *, char *, int);
241 struct netent	*getnetent_r(struct netent *, char *, int);
242 
243 struct protoent	*getprotobyname_r
244 	(const char *, struct protoent *, char *, int);
245 struct protoent	*getprotobynumber_r
246 	(int, struct protoent *, char *, int);
247 struct protoent	*getprotoent_r(struct protoent *, char *, int);
248 
249 int getnetgrent_r(char **, char **, char **, char *, int);
250 int innetgr(const char *, const char *, const char *, const char *);
251 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
252 
253 /* Old interfaces that return a pointer to a static area;  MT-unsafe */
254 struct hostent	*gethostbyname(const char *);
255 struct hostent	*gethostent(void);
256 struct netent	*getnetbyaddr(in_addr_t, int);
257 struct netent	*getnetbyname(const char *);
258 struct netent	*getnetent(void);
259 struct protoent	*getprotobyname(const char *);
260 struct protoent	*getprotobynumber(int);
261 struct protoent	*getprotoent(void);
262 struct servent	*getservbyname(const char *, const char *);
263 struct servent	*getservbyport(int, const char *);
264 struct servent	*getservent(void);
265 
266 /* gethostbyaddr() second argument is a size_t only in unix95/unix98 */
267 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
268 struct hostent	*gethostbyaddr(const void *, socklen_t, int);
269 #else
270 struct hostent	*gethostbyaddr(const void *, size_t, int);
271 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
272 
273 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
274 int endhostent(void);
275 int endnetent(void);
276 int endprotoent(void);
277 int endservent(void);
278 int sethostent(int);
279 int setnetent(int);
280 int setprotoent(int);
281 int setservent(int);
282 #else
283 void endhostent(void);
284 void endnetent(void);
285 void endprotoent(void);
286 void endservent(void);
287 void sethostent(int);
288 void setnetent(int);
289 void setprotoent(int);
290 void setservent(int);
291 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
292 
293 #if !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__)
294 
295 #ifdef	_XPG6
296 #ifdef	__PRAGMA_REDEFINE_EXTNAME
297 #pragma redefine_extname getaddrinfo __xnet_getaddrinfo
298 #else	/* __PRAGMA_REDEFINE_EXTNAME */
299 #define	getaddrinfo __xnet_getaddrinfo
300 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
301 #endif	/* _XPG6 */
302 
303 int		getaddrinfo(const char *_RESTRICT_KYWD,
304 			const char *_RESTRICT_KYWD,
305 			const struct addrinfo *_RESTRICT_KYWD,
306 			struct addrinfo **_RESTRICT_KYWD);
307 void		freeaddrinfo(struct addrinfo *);
308 const char	*gai_strerror(int);
309 int		getnameinfo(const struct sockaddr *_RESTRICT_KYWD,
310 			socklen_t, char *_RESTRICT_KYWD, socklen_t,
311 			char *_RESTRICT_KYWD, socklen_t, int);
312 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
313 
314 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
315 int getnetgrent(char **, char **, char **);
316 int setnetgrent(const char *);
317 int endnetgrent(void);
318 int rcmd(char **, unsigned short,
319 	const char *, const char *, const char *, int *);
320 int rcmd_af(char **, unsigned short,
321 	const char *, const char *, const char *, int *, int);
322 int rresvport_af(int *, int);
323 int rresvport_addr(int *, struct sockaddr_storage *);
324 int rexec(char **, unsigned short,
325 	const char *, const char *, const char *, int *);
326 int rexec_af(char **, unsigned short,
327 	const char *, const char *, const char *, int *, int);
328 int rresvport(int *);
329 int ruserok(const char *, int, const char *, const char *);
330 /* BIND */
331 struct hostent	*gethostbyname2(const char *, int);
332 void		herror(const char *);
333 const char	*hstrerror(int);
334 /* End BIND */
335 
336 /* IPsec algorithm prototype definitions */
337 struct ipsecalgent *getipsecalgbyname(const char *, int, int *);
338 struct ipsecalgent *getipsecalgbynum(int, int, int *);
339 int getipsecprotobyname(const char *doi_name);
340 char *getipsecprotobynum(int doi_domain);
341 void freeipsecalgent(struct ipsecalgent *ptr);
342 /* END IPsec algorithm prototype definitions */
343 
344 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
345 #else	/* __STDC__ */
346 struct hostent	*gethostbyname_r();
347 struct hostent	*gethostbyaddr_r();
348 struct hostent	*getipnodebyname();
349 struct hostent	*getipnodebyaddr();
350 void		 freehostent();
351 struct hostent	*gethostent_r();
352 struct servent	*getservbyname_r();
353 struct servent	*getservbyport_r();
354 struct servent	*getservent_r();
355 struct netent	*getnetbyname_r();
356 struct netent	*getnetbyaddr_r();
357 struct netent	*getnetent_r();
358 struct protoent	*getprotobyname_r();
359 struct protoent	*getprotobynumber_r();
360 struct protoent	*getprotoent_r();
361 int		 getnetgrent_r();
362 int		 innetgr();
363 
364 /* Old interfaces that return a pointer to a static area;  MT-unsafe */
365 struct hostent	*gethostbyname();
366 struct hostent	*gethostbyaddr();
367 struct hostent	*gethostent();
368 struct netent	*getnetbyname();
369 struct netent	*getnetbyaddr();
370 struct netent	*getnetent();
371 struct servent	*getservbyname();
372 struct servent	*getservbyport();
373 struct servent	*getservent();
374 struct protoent	*getprotobyname();
375 struct protoent	*getprotobynumber();
376 struct protoent	*getprotoent();
377 int		 getnetgrent();
378 
379 int sethostent();
380 int endhostent();
381 int setnetent();
382 int endnetent();
383 int setservent();
384 int endservent();
385 int setprotoent();
386 int endprotoent();
387 int setnetgrent();
388 int endnetgrent();
389 int rcmd();
390 int rcmd_af();
391 int rexec();
392 int rexec_af();
393 int rresvport();
394 int rresvport_af();
395 int rresvport_addr();
396 int ruserok();
397 /* BIND */
398 struct hostent	*gethostbyname2();
399 void		herror();
400 char		*hstrerror();
401 /* IPv6 prototype definitons */
402 int		getaddrinfo();
403 void		freeaddrinfo();
404 const char	*gai_strerror();
405 int		getnameinfo();
406 /* END IPv6 prototype definitions */
407 /* End BIND */
408 
409 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
410 /* IPsec algorithm prototype definitions */
411 struct ipsecalgent *getalgbyname();
412 struct ipsecalgent *getalgbydoi();
413 int getdoidomainbyname();
414 const char *getdoidomainbynum();
415 void freealgent();
416 /* END IPsec algorithm prototype definitions */
417 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
418 
419 #endif	/* __STDC__ */
420 
421 /*
422  * Error return codes from gethostbyname() and gethostbyaddr()
423  * (when using the resolver)
424  */
425 
426 extern  int h_errno;
427 
428 #ifdef	_REENTRANT
429 #ifdef	__STDC__
430 extern int	*__h_errno(void);
431 #else
432 extern int	*__h_errno();
433 #endif	/* __STDC__ */
434 
435 /* Only #define h_errno if there is no conflict with other use */
436 #ifdef	H_ERRNO_IS_FUNCTION
437 #define	h_errno	(*__h_errno())
438 #endif	/* NO_H_ERRNO_DEFINE */
439 #endif	/* _REENTRANT */
440 
441 #define	HOST_NOT_FOUND	1 /* Authoritive Answer Host not found */
442 #define	TRY_AGAIN	2 /* Non-Authoritive Host not found, or SERVERFAIL */
443 #define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
444 #define	NO_DATA		4 /* Valid name, no data record of requested type */
445 
446 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
447 #define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */
448 
449 /* BIND */
450 #define	NETDB_INTERNAL	-1	/* see errno */
451 #define	NETDB_SUCCESS	0	/* no problem */
452 /* End BIND */
453 
454 #define	MAXHOSTNAMELEN	256
455 
456 #define	MAXALIASES	35
457 #define	MAXADDRS	35
458 #endif /* !defined(_XPG4_2) || defined(__EXTENSIONS__) */
459 
460 #ifdef	__cplusplus
461 }
462 #endif
463 
464 #endif	/* _NETDB_H */
465