Fix typo.
[dragonfly.git] / lib / libbind / port_after.h
1 /* $DragonFly: src/lib/libbind/port_after.h,v 1.2 2006/09/20 21:48:39 victor Exp $ */
2 #ifndef port_after_h
3 #define port_after_h
4
5 #include <stdio.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <sys/param.h>
9 #if (!defined(BSD)) || (BSD < 199306)
10 #include <sys/bitypes.h>
11 #endif
12 #ifdef HAVE_INTTYPES_H
13 #include <inttypes.h>
14 #endif
15
16 #define NEED_PSELECT
17 #define HAVE_SA_LEN 1
18 #define HAVE_MINIMUM_IFREQ 1
19 #undef NEED_DAEMON
20 #undef NEED_STRSEP
21 #undef NEED_STRERROR
22 #define HAS_INET6_STRUCTS 1
23 #define HAVE_SIN6_SCOPE_ID 1
24 #undef NEED_IN6ADDR_ANY
25 #undef HAS_IN_ADDR6
26 #define HAVE_SOCKADDR_STORAGE 1
27 #undef NEED_GETTIMEOFDAY
28 #undef HAVE_STRNDUP
29 #undef USE_FIONBIO_IOCTL
30 #undef USE_SYSERROR_LIST
31 #undef INNETGR_ARGS
32 #undef SETNETGRENT_ARGS
33 #define USE_IFNAMELINKID 1
34 #define PORT_NONBLOCK O_NONBLOCK
35
36 /*
37  * We need to know the IPv6 address family number even on IPv4-only systems.
38  * Note that this is NOT a protocol constant, and that if the system has its
39  * own AF_INET6, different from ours below, all of BIND's libraries and
40  * executables will need to be recompiled after the system <sys/socket.h>
41  * has had this type added.  The type number below is correct on most BSD-
42  * derived systems for which AF_INET6 is defined.
43  */
44 #ifndef AF_INET6
45 #define AF_INET6        24
46 #endif
47
48 #ifndef PF_INET6
49 #define PF_INET6        AF_INET6
50 #endif
51
52 #ifdef HAS_IN_ADDR6
53 /* Map to pre-RFC structure. */
54 #define in6_addr in_addr6
55 #endif
56
57 #ifndef HAS_INET6_STRUCTS
58 /* Replace with structure from later rev of O/S if known. */
59 struct in6_addr {
60         u_int8_t        s6_addr[16];
61 };
62
63 #define IN6ADDR_ANY_INIT \
64         {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
65            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
66
67 #define IN6ADDR_LOOPBACK_INIT \
68         {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
69            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
70
71 /* Replace with structure from later rev of O/S if known. */
72 struct sockaddr_in6 {
73 #ifdef  HAVE_SA_LEN
74         u_int8_t        sin6_len;       /* length of this struct */
75         u_int8_t        sin6_family;    /* AF_INET6 */
76 #else
77         u_int16_t       sin6_family;    /* AF_INET6 */
78 #endif
79         u_int16_t       sin6_port;      /* transport layer port # */
80         u_int32_t       sin6_flowinfo;  /* IPv6 flow information */
81         struct in6_addr sin6_addr;      /* IPv6 address */
82         u_int32_t       sin6_scope_id;  /* set of interfaces for a scope */
83 };
84 #endif  /* HAS_INET6_STRUCTS */
85
86 #ifdef BROKEN_IN6ADDR_INIT_MACROS
87 #undef IN6ADDR_ANY_INIT
88 #undef IN6ADDR_LOOPBACK_INIT
89 #endif
90
91 #ifdef _AIX
92 #ifndef IN6ADDR_ANY_INIT
93 #define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0 }}}
94 #endif
95 #ifndef IN6ADDR_LOOPBACK_INIT
96 #if BYTE_ORDER == BIG_ENDIAN
97 #define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 1 }}}
98 #else
99 #define IN6ADDR_LOOPBACK_INIT {{{0, 0, 0, 0x01000000}}}
100 #endif
101 #endif
102 #endif
103
104 #ifndef IN6ADDR_ANY_INIT
105 #ifdef s6_addr
106 #define IN6ADDR_ANY_INIT \
107         {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
108             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
109 #else
110 #define IN6ADDR_ANY_INIT \
111         {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
112            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
113 #endif
114
115 #endif
116 #ifndef IN6ADDR_LOOPBACK_INIT
117 #ifdef s6_addr
118 #define IN6ADDR_LOOPBACK_INIT \
119         {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
120             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
121 #else
122 #define IN6ADDR_LOOPBACK_INIT \
123         {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
124            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
125 #endif
126 #endif
127
128 #ifndef HAVE_SOCKADDR_STORAGE
129 #define __SS_MAXSIZE 128 
130 #define __SS_ALLIGSIZE (sizeof (long)) 
131
132 struct sockaddr_storage {
133 #ifdef  HAVE_SA_LEN
134         u_int8_t        ss_len;       /* address length */
135         u_int8_t        ss_family;    /* address family */
136         char            __ss_pad1[__SS_ALLIGSIZE - 2 * sizeof(u_int8_t)];
137         long            __ss_align;
138         char            __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
139 #else   
140         u_int16_t       ss_family;    /* address family */
141         char            __ss_pad1[__SS_ALLIGSIZE - sizeof(u_int16_t)];
142         long            __ss_align;
143         char            __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
144 #endif
145 };
146 #endif
147
148
149 #if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY)
150 #define in6addr_any isc_in6addr_any
151 extern const struct in6_addr in6addr_any;
152 #endif
153
154 /*
155  * IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_V4COMPAT and
156  * IN6_IS_ADDR_V4MAPPED are broken in glibc 2.1.
157  */
158 #ifdef __GLIBC__
159 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2)
160 #undef IN6_ARE_ADDR_EQUAL
161 #undef IN6_IS_ADDR_UNSPECIFIED
162 #undef IN6_IS_ADDR_V4COMPAT
163 #undef IN6_IS_ADDR_V4MAPPED
164 #endif
165 #endif
166
167 #ifndef IN6_ARE_ADDR_EQUAL
168 #define IN6_ARE_ADDR_EQUAL(a,b) \
169    (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
170 #endif
171
172 #ifndef IN6_IS_ADDR_UNSPECIFIED
173 #define IN6_IS_ADDR_UNSPECIFIED(a)      \
174         IN6_ARE_ADDR_EQUAL(a, &in6addr_any)
175 #endif
176
177 #ifndef IN6_IS_ADDR_LOOPBACK
178 extern const struct in6_addr isc_in6addr_loopback;
179 #define IN6_IS_ADDR_LOOPBACK(a) \
180         IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback)
181 #endif
182
183 #ifndef IN6_IS_ADDR_V4MAPPED
184 #define IN6_IS_ADDR_V4MAPPED(a) \
185         ((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
186         (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
187         (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
188         (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \
189         (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
190         (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
191 #endif
192
193 #ifndef IN6_IS_ADDR_SITELOCAL
194 #define IN6_IS_ADDR_SITELOCAL(a)        \
195         (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
196 #endif
197
198 #ifndef IN6_IS_ADDR_LINKLOCAL
199 #define IN6_IS_ADDR_LINKLOCAL(a)        \
200         (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
201 #endif
202
203 #ifndef IN6_IS_ADDR_MULTICAST
204 #define IN6_IS_ADDR_MULTICAST(a)        ((a)->s6_addr[0] == 0xff)
205 #endif
206
207 #ifndef __IPV6_ADDR_MC_SCOPE
208 #define __IPV6_ADDR_MC_SCOPE(a)         ((a)->s6_addr[1] & 0x0f)
209 #endif
210
211 #ifndef __IPV6_ADDR_SCOPE_SITELOCAL
212 #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
213 #endif
214 #ifndef __IPV6_ADDR_SCOPE_ORGLOCAL
215 #define __IPV6_ADDR_SCOPE_ORGLOCAL  0x08
216 #endif
217
218 #ifndef IN6_IS_ADDR_MC_SITELOCAL
219 #define IN6_IS_ADDR_MC_SITELOCAL(a)     \
220         (IN6_IS_ADDR_MULTICAST(a) &&    \
221          (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
222 #endif
223
224 #ifndef IN6_IS_ADDR_MC_ORGLOCAL
225 #define IN6_IS_ADDR_MC_ORGLOCAL(a)      \
226         (IN6_IS_ADDR_MULTICAST(a) &&    \
227          (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
228 #endif
229
230 #ifndef INADDR_NONE
231 #define INADDR_NONE 0xffffffff
232 #endif
233
234 #ifndef MAXHOSTNAMELEN
235 #define MAXHOSTNAMELEN 256
236 #endif
237
238 #ifndef INET6_ADDRSTRLEN
239 /* sizeof("aaaa:bbbb:cccc:dddd:eeee:ffff:123.123.123.123") */
240 #define INET6_ADDRSTRLEN 46
241 #endif
242
243 #ifndef MIN
244 #define MIN(x,y) (((x) <= (y)) ? (x) : (y))
245 #endif
246
247 #ifndef MAX
248 #define MAX(x,y) (((x) >= (y)) ? (x) : (y))
249 #endif
250
251 #ifdef NEED_DAEMON
252 int daemon(int nochdir, int noclose);
253 #endif
254   
255 #ifdef NEED_STRSEP
256 char * strsep(char **stringp, const char *delim);
257 #endif
258
259 #ifndef ALIGN
260 #define ALIGN(p) (((uintptr_t)(p) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
261 #endif
262
263 #ifdef NEED_SETGROUPENT
264 int setgroupent(int stayopen);
265 #endif
266
267 #ifdef NEED_GETGROUPLIST
268 int getgrouplist(GETGROUPLIST_ARGS);
269 #endif
270
271 #ifdef POSIX_GETGRNAM_R
272 int
273 __posix_getgrnam_r(const char *, struct group *, char *, int, struct group **);
274 #endif
275
276 #ifdef NEED_GETGRNAM_R
277 int
278 getgrnam_r(const char *,  struct group *, char *, size_t, struct group **);
279 #endif
280
281 #ifdef POSIX_GETGRGID_R
282 int
283 __posix_getgrgid_r(gid_t, struct group *, char *, int, struct group **) ;
284 #endif
285
286 #ifdef NEED_GETGRGID_R
287 int
288 getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
289 #endif
290
291 #ifdef NEED_GETGRENT_R
292 GROUP_R_RETURN getgrent_r(struct group *gptr, GROUP_R_ARGS);
293 #endif
294
295 #ifdef NEED_SETGRENT_R
296 GROUP_R_SET_RETURN setgrent_r(GROUP_R_ENT_ARGS);
297 #endif
298
299 #ifdef NEED_ENDGRENT_R
300 GROUP_R_END_RETURN endgrent_r(GROUP_R_ENT_ARGS);
301 #endif
302
303 #if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN)
304 NGR_R_RETURN
305 innetgr_r(const char *, const char *, const char *, const char *);
306 #endif
307
308 #ifdef NEED_SETNETGRENT_R
309 #ifdef NGR_R_ENT_ARGS
310 NGR_R_SET_RETURN setnetgrent_r(const char *netgroup, NGR_R_ENT_ARGS);
311 #else
312 NGR_R_SET_RETURN setnetgrent_r(const char *netgroup);
313 #endif
314 #endif
315
316 #ifdef NEED_ENDNETGRENT_R
317 #ifdef NGR_R_ENT_ARGS
318 NGR_R_END_RETURN endnetgrent_r(NGR_R_ENT_ARGS);
319 #else
320 NGR_R_END_RETURN endnetgrent_r(void);
321 #endif
322 #endif
323
324 #ifdef POSIX_GETPWNAM_R
325 int
326 __posix_getpwnam_r(const char *login,  struct passwd *pwptr,
327                 char *buf, size_t buflen, struct passwd **result);
328 #endif
329
330 #ifdef NEED_GETPWNAM_R
331 int
332 getpwnam_r(const char *login,  struct passwd *pwptr,
333                 char *buf, size_t buflen, struct passwd **result);
334 #endif
335
336 #ifdef POSIX_GETPWUID_R
337 int
338 __posix_getpwuid_r(uid_t uid, struct passwd *pwptr,
339                 char *buf, int buflen, struct passwd **result);
340 #endif
341
342 #ifdef NEED_GETPWUID_R
343 int
344 getpwuid_r(uid_t uid, struct passwd *pwptr,
345                 char *buf, size_t buflen, struct passwd **result);
346 #endif
347
348 #ifdef NEED_SETPWENT_R
349 #ifdef PASS_R_ENT_ARGS
350 PASS_R_SET_RETURN setpwent_r(PASS_R_ENT_ARGS);
351 #else
352 PASS_R_SET_RETURN setpwent_r(void);
353 #endif
354
355 #endif
356
357 #ifdef NEED_SETPASSENT_R
358 #ifdef PASS_R_ENT_ARGS
359 PASS_R_SET_RETURN setpassent_r(int stayopen, PASS_R_ENT_ARGS);
360 #else
361 PASS_R_SET_RETURN setpassent_r(int stayopen);
362 #endif
363 #endif
364
365 #ifdef NEED_GETPWENT_R
366 PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS);
367 #endif
368
369 #ifdef NEED_ENDPWENT_R
370 void endpwent_r(void);
371 #endif
372
373 #ifdef NEED_SETPASSENT
374 int setpassent(int stayopen);
375 #endif
376
377 #define gettimeofday isc__gettimeofday
378 #ifdef NEED_GETTIMEOFDAY
379 int isc__gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp);
380 #else
381 int isc__gettimeofday(struct timeval *tp, struct timezone *tzp);
382 #endif
383
384 int getnetgrent(char **machinep, char **userp, char **domainp);
385
386 #ifdef NGR_R_ARGS
387 int getnetgrent_r(char **machinep, char **userp, char **domainp, NGR_R_ARGS);
388 #endif
389
390 #ifdef SETNETGRENT_ARGS
391 void setnetgrent(SETNETGRENT_ARGS);
392 #else
393 void setnetgrent(const char *netgroup);
394 #endif
395
396 void endnetgrent(void);
397
398 #ifdef INNETGR_ARGS
399 int innetgr(INNETGR_ARGS);
400 #else
401 int innetgr(const char *netgroup, const char *machine,
402             const char *user, const char *domain);
403 #endif
404
405 #ifdef NGR_R_ENT_ARGS
406 NGR_R_SET_RETURN
407 setnetgrent_r(const char *netgroup, NGR_R_ENT_ARGS);
408 #else
409 NGR_R_SET_RETURN
410 setnetgrent_r(const char *netgroup);
411 #endif
412 #endif