xref: /titanic_41/usr/src/head/netdb.h (revision bbf6f00c25b6a2bed23c35eac6d62998ecdb338c)
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 /* addrinfo flags */
124 #define	AI_PASSIVE	0x0008	/* intended for bind() + listen() */
125 #define	AI_CANONNAME	0x0010	/* return canonical version of host */
126 #define	AI_NUMERICHOST	0x0020	/* use numeric node address string */
127 #define	AI_NUMERICSERV	0x0040	/* servname is assumed numeric */
128 
129 /* getipnodebyname() flags */
130 #define	AI_V4MAPPED	0x0001	/* IPv4 mapped addresses if no IPv6 */
131 #define	AI_ALL		0x0002	/* IPv6 and IPv4 mapped addresses */
132 #define	AI_ADDRCONFIG	0x0004	/* AAAA or A records only if IPv6/IPv4 cnfg'd */
133 
134 /*
135  * These were defined in RFC 2553 but not SUSv3
136  * or RFC 3493 which obsoleted 2553.
137  */
138 #if !defined(_XPG6) || defined(__EXTENSIONS__)
139 #define	AI_DEFAULT	(AI_V4MAPPED | AI_ADDRCONFIG)
140 
141 /* addrinfo errors */
142 #define	EAI_ADDRFAMILY	1	/* address family not supported */
143 #define	EAI_NODATA	7	/* no address */
144 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
145 #define	EAI_AGAIN	2	/* DNS temporary failure */
146 #define	EAI_BADFLAGS	3	/* invalid ai_flags */
147 #define	EAI_FAIL	4	/* DNS non-recoverable failure */
148 #define	EAI_FAMILY	5	/* ai_family not supported */
149 #define	EAI_MEMORY	6	/* memory allocation failure */
150 #define	EAI_NONAME	8	/* host/servname not known */
151 #define	EAI_SERVICE	9	/* servname not supported for ai_socktype */
152 #define	EAI_SOCKTYPE	10	/* ai_socktype not supported */
153 #define	EAI_SYSTEM	11	/* system error in errno */
154 #define	EAI_OVERFLOW	12	/* argument buffer overflow */
155 
156 /* getnameinfo flags */
157 #define	NI_NOFQDN	0x0001
158 #define	NI_NUMERICHOST	0x0002	/* return numeric form of address */
159 #define	NI_NAMEREQD	0x0004	/* request DNS name */
160 #define	NI_NUMERICSERV	0x0008
161 #define	NI_DGRAM	0x0010
162 
163 #if !defined(_XPG6) || defined(__EXTENSIONS__)
164 /* Not listed in any standards document */
165 #define	NI_WITHSCOPEID  0x0020
166 #define	NI_NUMERICSCOPE 0x0040
167 
168 /* getnameinfo max sizes as defined in RFC 2553 obsoleted in RFC 3493 */
169 #define	NI_MAXHOST	1025
170 #define	NI_MAXSERV	32
171 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
172 #endif /* !defined(_XPG4_2) || defined(_XPG6) || defined(__EXTENSIONS__) */
173 
174 /*
175  * Algorithm entry for /etc/inet/ipsecalgs which defines IPsec protocols
176  * and algorithms.
177  */
178 #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
179 typedef struct ipsecalgent {
180 	char **a_names;		/* algorithm names */
181 	int a_proto_num;	/* protocol number */
182 	int a_alg_num;		/* algorithm number */
183 	char *a_mech_name;	/* encryption framework mechanism name */
184 	int *a_block_sizes;	/* supported block sizes */
185 	int *a_key_sizes;	/* supported key sizes */
186 	int a_key_increment;	/* key size increment */
187 	int *a_mech_params;	/* mechanism specific parameters */
188 	int a_alg_flags;	/* algorithm flags */
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