xref: /titanic_41/usr/src/lib/libresolv2/include/port_after.h (revision 6185db853e024a486ff8837e6784dd290d866112)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 #ifndef	PORT_AFTER_H
9 #define	PORT_AFTER_H
10 #include "os_version.h"
11 
12 #undef HAVE_SA_LEN
13 #define	USE_POSIX
14 #define	POSIX_SIGNALS
15 #define	NETREAD_BROKEN
16 #define	USE_WAITPID
17 #define	HAVE_FCHMOD
18 #define	NEED_PSELECT
19 #define	SETGRENT_VOID
20 #define	SETPWENT_VOID
21 #define	SIOCGIFCONF_ADDR
22 #define	IP_OPT_BUF_SIZE 40
23 #define	HAVE_CHROOT
24 #define	CAN_CHANGE_ID
25 #define	POSIX_GETPWNAM_R
26 #define	POSIX_GETPWUID_R
27 #define	POSIX_GETGRGID_R
28 #define	POSIX_GETGRNAM_R
29 #define	NEED_SECURE_DIRECTORY
30 #define	HAVE_DEV_RANDOM
31 #define	NO_MSG_CONTROL
32 
33 #define	PORT_NONBLOCK	O_NONBLOCK
34 #define	PORT_WOULDBLK	EWOULDBLOCK
35 #define	WAIT_T		int
36 #ifndef	SUNW_LIBNSL
37 #define	INADDR_NONE	0xffffffff
38 #endif
39 
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <sys/param.h>
43 #if (!defined(BSD)) || (BSD < 199306)
44 #include <sys/bitypes.h>
45 #endif
46 #include <sys/time.h>
47 
48 #ifndef MIN
49 #define	MIN(x, y)	((x > y) ?y :x)
50 #endif
51 #ifndef MAX
52 #define	MAX(x, y)	((x > y) ?x :y)
53 #endif
54 
55 /*
56  * We need to know the IPv6 address family number even on IPv4-only systems.
57  * Note that this is NOT a protocol constant, and that if the system has its
58  * own AF_INET6, different from ours below, all of BIND's libraries and
59  * executables will need to be recompiled after the system <sys/socket.h>
60  * has had this type added.  The type number below is correct on most BSD-
61  * derived systems for which AF_INET6 is defined.
62  */
63 #ifndef AF_INET6
64 #define	AF_INET6	24
65 #endif
66 
67 #ifndef	PF_INET6
68 #define	PF_INET6	AF_INET6
69 #endif
70 #include <port_ipv6.h>
71 
72 #ifndef HAS_INET6_STRUCTS
73 /* Replace with structure from later rev of O/S if known. */
74 struct in6_addr {
75 	u_int8_t	s6_addr[16];
76 };
77 
78 /* Replace with structure from later rev of O/S if known. */
79 struct sockaddr_in6 {
80 #ifdef	HAVE_SA_LEN
81 	u_int8_t	sin6_len;	/* length of this struct */
82 	u_int8_t	sin6_family;	/* AF_INET6 */
83 #else
84 	u_int16_t	sin6_family;	/* AF_INET6 */
85 #endif
86 	u_int16_t	sin6_port;	/* transport layer port # */
87 	u_int32_t	sin6_flowinfo;	/* IPv6 flow information */
88 	struct in6_addr	sin6_addr;	/* IPv6 address */
89 	u_int32_t	sin6_scope_id;	/* set of interfaces for a scope */
90 };
91 
92 #ifndef IN6ADDR_ANY_INIT
93 #define	IN6ADDR_ANY_INIT	{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}
94 #endif
95 #ifndef IN6ADDR_LOOPBACK_INIT
96 #define	IN6ADDR_LOOPBACK_INIT	{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}
97 #endif
98 #endif	/* HAS_INET6_STRUCTS */
99 
100 #if defined(NEED_SOCKADDR_STORAGE) || !defined(HAS_INET6_STRUCTS)
101 #define	__SS_MAXSIZE 128
102 #define	__SS_ALLIGSIZE (sizeof (long))
103 
104 struct sockaddr_storage {
105 #ifdef  HAVE_SA_LEN
106 	u_int8_t	ss_len;	/* address length */
107 	u_int8_t	ss_family;	/* address family */
108 	char		__ss_pad1[__SS_ALLIGSIZE - 2 * sizeof (u_int8_t)];
109 	long		__ss_align;
110 	char		__ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
111 #else
112 	u_int16_t	ss_family;	/* address family */
113 	char		__ss_pad1[__SS_ALLIGSIZE - sizeof (u_int16_t)];
114 	long		__ss_align;
115 	char		__ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
116 #endif
117 };
118 #endif
119 
120 
121 #if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY)
122 #define	in6addr_any isc_in6addr_any
123 extern const struct in6_addr in6addr_any;
124 #endif
125 
126 #ifndef IN6_ARE_ADDR_EQUAL
127 #define	IN6_ARE_ADDR_EQUAL(a, b) \
128     (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof (struct in6_addr)) == 0)
129 #endif
130 
131 #ifndef IN6_IS_ADDR_UNSPECIFIED
132 #define	IN6_IS_ADDR_UNSPECIFIED(a)      \
133 	IN6_ARE_ADDR_EQUAL(a, &in6addr_any)
134 #endif
135 
136 #ifndef IN6_IS_ADDR_LOOPBACK
137 extern const struct in6_addr isc_in6addr_loopback;
138 #define	IN6_IS_ADDR_LOOPBACK(a)		\
139 	IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback)
140 #endif
141 
142 #ifndef IN6_IS_ADDR_V4COMPAT
143 #define	IN6_IS_ADDR_V4COMPAT(a)		\
144 	((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
145 	(a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
146 	(a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
147 	(a)->s6_addr[6] == 0x00 && (a)->s6_addr[7] == 0x00 && \
148 	(a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
149 	(a)->s6_addr[10] == 0x00 && (a)->s6_addr[11] == 0x00 && \
150 	((a)->s6_addr[12] != 0x00 || (a)->s6_addr[13] != 0x00 || \
151 	(a)->s6_addr[14] != 0x00 || \
152 	((a)->s6_addr[15] != 0x00 && (a)->s6_addr[15] != 1)))
153 #endif
154 
155 #ifndef IN6_IS_ADDR_V4MAPPED
156 #define	IN6_IS_ADDR_V4MAPPED(a)		\
157 	((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
158 	(a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
159 	(a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
160 	(a)->s6_addr[6] == 0x00 && (a)->s6_addr[7] == 0x00 && \
161 	(a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
162 	(a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
163 #endif
164 
165 #ifndef IN6_IS_ADDR_SITELOCAL
166 #define	IN6_IS_ADDR_SITELOCAL(a)        \
167 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
168 #endif
169 
170 #ifndef IN6_IS_ADDR_LINKLOCAL
171 #define	IN6_IS_ADDR_LINKLOCAL(a)	\
172 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
173 #endif
174 
175 #ifndef IN6_IS_ADDR_MULTICAST
176 #define	IN6_IS_ADDR_MULTICAST(a)	((a)->s6_addr[0] == 0xff)
177 #endif
178 
179 #ifndef __IPV6_ADDR_MC_SCOPE
180 #define	__IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
181 #endif
182 
183 #ifndef __IPV6_ADDR_SCOPE_SITELOCAL
184 #define	__IPV6_ADDR_SCOPE_SITELOCAL 0x05
185 #endif
186 
187 #ifndef __IPV6_ADDR_SCOPE_ORGLOCAL
188 #define	__IPV6_ADDR_SCOPE_ORGLOCAL  0x08
189 #endif
190 
191 #ifndef IN6_IS_ADDR_MC_SITELOCAL
192 #define	IN6_IS_ADDR_MC_SITELOCAL(a)     \
193 	(IN6_IS_ADDR_MULTICAST(a) &&    \
194 	(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
195 #endif
196 
197 #ifndef IN6_IS_ADDR_MC_ORGLOCAL
198 #define	IN6_IS_ADDR_MC_ORGLOCAL(a)      \
199 	(IN6_IS_ADDR_MULTICAST(a) &&    \
200 	(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
201 #endif
202 
203 #ifndef INET6_ADDRSTRLEN
204 #define	INET6_ADDRSTRLEN 46
205 #endif
206 
207 /*
208  * Prior to 2.6, Solaris needs a prototype for gethostname().
209  */
210 #if (OS_MAJOR == 5 && OS_MINOR < 6)
211 extern int gethostname(char *, size_t);
212 #endif
213 /*
214  * gethostid() was not available until 2.5
215  * setsockopt(SO_REUSEADDR) fails on unix domain sockets before 2.5
216  * use ioctl(FIONBIO) rather than fcntl() calls to set/clear non-blocking i/o.
217  */
218 #if (OS_MAJOR == 5 && OS_MINOR < 5)
219 #define	GET_HOST_ID_MISSING
220 #define	NO_UNIX_REUSEADDR
221 #define	USE_FIONBIO_IOCTL
222 #endif
223 
224 #define	NEED_STRSEP
225 extern char *strsep(char **, const char *);
226 
227 #define	NEED_DAEMON
228 int daemon(int nochdir, int noclose);
229 
230 /*
231  * Solaris defines this in <netdb.h> instead of in <sys/param.h>.  We don't
232  * define it in our <netdb.h>, so we define it here.
233  */
234 #ifndef	MAXHOSTNAMELEN
235 #define	MAXHOSTNAMELEN 256
236 #endif
237 
238 /*
239  * Solaris 2.5 and later have getrlimit(), setrlimit() and getrusage().
240  */
241 #if (OS_MAJOR > 5 || (OS_MAJOR == 5 && OS_MINOR >= 5))
242 #include <sys/resource.h>
243 #define	HAVE_GETRUSAGE
244 #define	RLIMIT_TYPE rlim_t
245 #define	RLIMIT_FILE_INFINITY
246 #endif
247 
248 #include <resolv_mt.h>
249 #include <netdb_private.h>
250 #include <inet_private.h>
251 #include <ctype.h>
252 #include <sunw_dst_init.h>
253 #include <sunw_irs_init.h>
254 
255 #ifdef	ORIGINAL_ISC_CODE
256 const char *isc_strerror(int errnum);
257 #define	strerror isc_strerror
258 #endif
259 
260 #ifndef ISC_FACILITY
261 #define	ISC_FACILITY LOG_DAEMON
262 #endif
263 
264 /* res_mkquery.c refers explicitly to __putlong and __putshort */
265 #define	__putlong	putlong
266 #define	__putshort	putshort
267 
268 /*
269  * If one wanted to use isc__gettimeofday for Solaris, they would
270  * need to define NEED_GETTIMEOFDAY (common/bsd/gettimeofday.c),
271  * which is not defined for Solaris. Hence there is no reason to
272  * change the current definition of gettimeofday which currently
273  * comes from libc and we comment the following out.
274  */
275 #ifdef	ORIGINAL_ISC_CODE
276 int isc__gettimeofday(struct timeval *, struct timezone *);
277 #define	gettimeofday isc__gettimeofday
278 #endif
279 
280 /*
281  * Solaris 8 has if_nametoindex().
282  */
283 #if (OS_MAJOR > 5 || (OS_MAJOR == 5 && OS_MINOR >= 8))
284 #define USE_IFNAMELINKID
285 #endif
286 
287 #define	UNUSED(x) (x) = (x)
288 #define	DE_CONST(konst, var) \
289 	do { \
290 		union { const void *k; void *v; } _u; \
291 		_u.k = konst; \
292 		var = _u.v; \
293 	} while (0)
294 
295 #ifndef ALIGN
296 #if (OS_MAJOR == 5 && OS_MINOR > 8)
297 #define ALIGN(x) (((uintptr_t)(x) + (sizeof(char*) - 1UL)) & ~(sizeof(char*) - 1UL))
298 #else
299 #define ALIGN(x) (((unsigned long)(x) + (sizeof(char*) - 1UL)) & ~(sizeof(char*) - 1UL))
300 #endif
301 #endif
302 
303 #endif /* ! PORT_AFTER_H */
304