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