xref: /haiku/src/system/libnetwork/netresolv/port_after.h (revision ed24eb5ff12640d052171c6a7feba37fab8a75d1)
1 /*
2  * Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2001-2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /* $Id: port_after.h.in,v 1.60 2008/02/28 05:34:17 marka Exp $ */
19 
20 #ifndef port_after_h
21 #define port_after_h
22 
23 #ifdef __HAIKU__
24 	#ifdef _STRING_H_
25 		#include <strings.h>
26 	#endif
27 #endif
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #if (!defined(BSD)) || (BSD < 199306)
34 #include <sys/bitypes.h>
35 #endif
36 #ifdef HAVE_INTTYPES_H
37 #include <inttypes.h>
38 #endif
39 #ifdef HAVE_SYS_SELECT_H
40 #include <sys/select.h>
41 #endif /* HAVE_SYS_SELECT_H */
42 
43 #ifdef REENABLE_SEND
44 #undef send
45 #endif
46 
47 #undef NEED_PSELECT
48 #define HAVE_SA_LEN 1
49 #undef HAVE_MINIMUM_IFREQ
50 #undef NEED_DAEMON
51 	/* manual Haiku change */
52 #define NEED_STRSEP 1
53 #undef NEED_STRERROR
54 #ifdef NEED_STRERROR
55 const char *isc_strerror(int);
56 #define strerror isc_strerror
57 #endif
58 #define HAS_INET6_STRUCTS 1
59 #define HAVE_SIN6_SCOPE_ID 1
60 #undef NEED_IN6ADDR_ANY
61 #define HAS_IN_ADDR6
62 #define HAVE_SOCKADDR_STORAGE 1
63 #undef NEED_GETTIMEOFDAY
64 #define HAVE_STRNDUP 1
65 #undef USE_FIONBIO_IOCTL
66 #undef INNETGR_ARGS
67 #undef SETNETGRENT_ARGS
68 #undef USE_IFNAMELINKID
69 #define PORT_NONBLOCK O_NONBLOCK
70 
71 #ifndef _POSIX_PATH_MAX
72 #define _POSIX_PATH_MAX 255
73 #endif
74 #ifndef PATH_MAX
75 #define PATH_MAX _POSIX_PATH_MAX
76 #endif
77 
78 /*
79  * We need to know the IPv6 address family number even on IPv4-only systems.
80  * Note that this is NOT a protocol constant, and that if the system has its
81  * own AF_INET6, different from ours below, all of BIND's libraries and
82  * executables will need to be recompiled after the system <sys/socket.h>
83  * has had this type added.  The type number below is correct on most BSD-
84  * derived systems for which AF_INET6 is defined.
85  */
86 #ifndef AF_INET6
87 #define AF_INET6        24
88 #endif
89 
90 #ifndef PF_INET6
91 #define PF_INET6        AF_INET6
92 #endif
93 
94 #ifndef HAS_INET6_STRUCTS
95 /* Replace with structure from later rev of O/S if known. */
96 struct in6_addr {
97 	u_int8_t        s6_addr[16];
98 };
99 
100 #define IN6ADDR_ANY_INIT \
101 	{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
102 	   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
103 
104 #define IN6ADDR_LOOPBACK_INIT \
105 	{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
106 	   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
107 
108 /* Replace with structure from later rev of O/S if known. */
109 struct sockaddr_in6 {
110 #ifdef  HAVE_SA_LEN
111 	u_int8_t        sin6_len;       /* length of this struct */
112 	u_int8_t        sin6_family;    /* AF_INET6 */
113 #else
114 	u_int16_t       sin6_family;    /* AF_INET6 */
115 #endif
116 	u_int16_t       sin6_port;      /* transport layer port # */
117 	u_int32_t       sin6_flowinfo;  /* IPv6 flow information */
118 	struct in6_addr sin6_addr;      /* IPv6 address */
119 	u_int32_t       sin6_scope_id;  /* set of interfaces for a scope */
120 };
121 #endif  /* HAS_INET6_STRUCTS */
122 
123 #ifdef BROKEN_IN6ADDR_INIT_MACROS
124 #undef IN6ADDR_ANY_INIT
125 #undef IN6ADDR_LOOPBACK_INIT
126 #endif
127 
128 #ifdef _AIX
129 #ifndef IN6ADDR_ANY_INIT
130 #define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0 }}}
131 #endif
132 #ifndef IN6ADDR_LOOPBACK_INIT
133 #if BYTE_ORDER == BIG_ENDIAN
134 #define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 1 }}}
135 #else
136 #define IN6ADDR_LOOPBACK_INIT {{{0, 0, 0, 0x01000000}}}
137 #endif
138 #endif
139 #endif
140 
141 #ifdef __HAIKU__
142 #define isc_in6addr_any in6addr_any
143 #define isc_in6addr_loopback in6addr_loopback
144 #endif
145 
146 #ifndef IN6ADDR_ANY_INIT
147 #ifdef s6_addr
148 #define IN6ADDR_ANY_INIT \
149 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
150 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
151 #else
152 #define IN6ADDR_ANY_INIT \
153 	{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
154 	   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
155 #endif
156 
157 #endif
158 #ifndef IN6ADDR_LOOPBACK_INIT
159 #ifdef s6_addr
160 #define IN6ADDR_LOOPBACK_INIT \
161 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
162 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
163 #else
164 #define IN6ADDR_LOOPBACK_INIT \
165 	{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
166 	   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
167 #endif
168 #endif
169 
170 #ifndef HAVE_SOCKADDR_STORAGE
171 #define __SS_MAXSIZE 128
172 #define __SS_ALLIGSIZE (sizeof (long))
173 
174 struct sockaddr_storage {
175 #ifdef  HAVE_SA_LEN
176 	u_int8_t        ss_len;       /* address length */
177 	u_int8_t        ss_family;    /* address family */
178 	char            __ss_pad1[__SS_ALLIGSIZE - 2 * sizeof(u_int8_t)];
179 	long            __ss_align;
180 	char            __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
181 #else
182 	u_int16_t       ss_family;    /* address family */
183 	char            __ss_pad1[__SS_ALLIGSIZE - sizeof(u_int16_t)];
184 	long            __ss_align;
185 	char            __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
186 #endif
187 };
188 #endif
189 
190 
191 #if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY)
192 #define in6addr_any isc_in6addr_any
193 extern const struct in6_addr in6addr_any;
194 #endif
195 
196 /*
197  * IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_V4COMPAT and
198  * IN6_IS_ADDR_V4MAPPED are broken in glibc 2.1.
199  */
200 #ifdef __GLIBC__
201 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2)
202 #undef IN6_ARE_ADDR_EQUAL
203 #undef IN6_IS_ADDR_UNSPECIFIED
204 #undef IN6_IS_ADDR_V4COMPAT
205 #undef IN6_IS_ADDR_V4MAPPED
206 #endif
207 #endif
208 
209 #ifndef IN6_ARE_ADDR_EQUAL
210 #define IN6_ARE_ADDR_EQUAL(a,b) \
211    (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
212 #endif
213 
214 #ifndef IN6_IS_ADDR_UNSPECIFIED
215 #define IN6_IS_ADDR_UNSPECIFIED(a)      \
216 	IN6_ARE_ADDR_EQUAL(a, &in6addr_any)
217 #endif
218 
219 #ifndef IN6_IS_ADDR_LOOPBACK
220 extern const struct in6_addr isc_in6addr_loopback;
221 #define IN6_IS_ADDR_LOOPBACK(a) \
222 	IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback)
223 #endif
224 
225 #ifndef IN6_IS_ADDR_V4MAPPED
226 #define IN6_IS_ADDR_V4MAPPED(a)	\
227 	((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
228 	(a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
229 	(a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
230 	(a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \
231 	(a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
232 	(a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
233 #endif
234 
235 #ifndef IN6_IS_ADDR_SITELOCAL
236 #define IN6_IS_ADDR_SITELOCAL(a)        \
237 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
238 #endif
239 
240 #ifndef IN6_IS_ADDR_LINKLOCAL
241 #define IN6_IS_ADDR_LINKLOCAL(a)        \
242 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
243 #endif
244 
245 #ifndef IN6_IS_ADDR_MULTICAST
246 #define IN6_IS_ADDR_MULTICAST(a)        ((a)->s6_addr[0] == 0xff)
247 #endif
248 
249 #ifndef __IPV6_ADDR_MC_SCOPE
250 #define __IPV6_ADDR_MC_SCOPE(a)         ((a)->s6_addr[1] & 0x0f)
251 #endif
252 
253 #ifndef __IPV6_ADDR_SCOPE_SITELOCAL
254 #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
255 #endif
256 #ifndef __IPV6_ADDR_SCOPE_ORGLOCAL
257 #define __IPV6_ADDR_SCOPE_ORGLOCAL  0x08
258 #endif
259 
260 #ifndef IN6_IS_ADDR_MC_SITELOCAL
261 #define IN6_IS_ADDR_MC_SITELOCAL(a)     \
262 	(IN6_IS_ADDR_MULTICAST(a) &&    \
263 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
264 #endif
265 
266 #ifndef IN6_IS_ADDR_MC_ORGLOCAL
267 #define IN6_IS_ADDR_MC_ORGLOCAL(a)      \
268 	(IN6_IS_ADDR_MULTICAST(a) &&    \
269 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
270 #endif
271 
272 #ifndef INADDR_NONE
273 #define INADDR_NONE 0xffffffff
274 #endif
275 
276 #ifndef MAXHOSTNAMELEN
277 #define MAXHOSTNAMELEN 256
278 #endif
279 
280 #ifndef INET6_ADDRSTRLEN
281 /* sizeof("aaaa:bbbb:cccc:dddd:eeee:ffff:123.123.123.123") */
282 #define INET6_ADDRSTRLEN 46
283 #endif
284 
285 #ifndef MIN
286 #define MIN(x,y) (((x) <= (y)) ? (x) : (y))
287 #endif
288 
289 #ifndef MAX
290 #define MAX(x,y) (((x) >= (y)) ? (x) : (y))
291 #endif
292 
293 #ifdef NEED_DAEMON
294 int daemon(int nochdir, int noclose);
295 #endif
296 
297 #ifdef NEED_STRSEP
298 char * strsep(char **stringp, const char *delim);
299 #endif
300 
301 #ifndef ALIGN
302 #define ALIGN(p) (((uintptr_t)(p) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
303 #endif
304 
305 #ifdef NEED_SETGROUPENT
306 int setgroupent(int stayopen);
307 #endif
308 
309 #ifdef NEED_GETGROUPLIST
310 int getgrouplist(GETGROUPLIST_ARGS);
311 #endif
312 
313 #ifdef POSIX_GETGRNAM_R
314 int
315 __posix_getgrnam_r(const char *, struct group *, char *, int, struct group **);
316 #endif
317 
318 #ifdef NEED_GETGRNAM_R
319 int
320 getgrnam_r(const char *,  struct group *, char *, size_t, struct group **);
321 #endif
322 
323 #ifdef POSIX_GETGRGID_R
324 int
325 __posix_getgrgid_r(gid_t, struct group *, char *, int, struct group **) ;
326 #endif
327 
328 #ifdef NEED_GETGRGID_R
329 int
330 getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
331 #endif
332 
333 #ifdef NEED_GETGRENT_R
334 GROUP_R_RETURN getgrent_r(struct group *gptr, GROUP_R_ARGS);
335 #endif
336 
337 #ifdef NEED_SETGRENT_R
338 GROUP_R_SET_RETURN setgrent_r(GROUP_R_ENT_ARGS);
339 #endif
340 
341 #ifdef NEED_ENDGRENT_R
342 GROUP_R_END_RETURN endgrent_r(GROUP_R_ENT_ARGS);
343 #endif
344 
345 #if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN)
346 NGR_R_RETURN
347 innetgr_r(const char *, const char *, const char *, const char *);
348 #endif
349 
350 #ifdef NEED_SETNETGRENT_R
351 #ifdef NGR_R_SET_ARGS
352 NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS);
353 #else
354 NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup);
355 #endif
356 #endif
357 
358 #ifdef NEED_ENDNETGRENT_R
359 #ifdef NGR_R_END_ARGS
360 NGR_R_END_RETURN endnetgrent_r(NGR_R_END_ARGS);
361 #else
362 NGR_R_END_RETURN endnetgrent_r(void);
363 #endif
364 #endif
365 
366 #ifdef POSIX_GETPWNAM_R
367 int
368 __posix_getpwnam_r(const char *login,  struct passwd *pwptr,
369 		char *buf, size_t buflen, struct passwd **result);
370 #endif
371 
372 #ifdef NEED_GETPWNAM_R
373 int
374 getpwnam_r(const char *login,  struct passwd *pwptr,
375 		char *buf, size_t buflen, struct passwd **result);
376 #endif
377 
378 #ifdef POSIX_GETPWUID_R
379 int
380 __posix_getpwuid_r(uid_t uid, struct passwd *pwptr,
381 		char *buf, int buflen, struct passwd **result);
382 #endif
383 
384 #ifdef NEED_GETPWUID_R
385 int
386 getpwuid_r(uid_t uid, struct passwd *pwptr,
387 		char *buf, size_t buflen, struct passwd **result);
388 #endif
389 
390 #ifdef NEED_SETPWENT_R
391 #ifdef PASS_R_ENT_ARGS
392 PASS_R_SET_RETURN setpwent_r(PASS_R_ENT_ARGS);
393 #else
394 PASS_R_SET_RETURN setpwent_r(void);
395 #endif
396 
397 #endif
398 
399 #ifdef NEED_SETPASSENT_R
400 #ifdef PASS_R_ENT_ARGS
401 PASS_R_SET_RETURN setpassent_r(int stayopen, PASS_R_ENT_ARGS);
402 #else
403 PASS_R_SET_RETURN setpassent_r(int stayopen);
404 #endif
405 #endif
406 
407 #ifdef NEED_GETPWENT_R
408 PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS);
409 #endif
410 
411 #ifdef NEED_ENDPWENT_R
412 void endpwent_r(void);
413 #endif
414 
415 #ifdef NEED_SETPASSENT
416 int setpassent(int stayopen);
417 #endif
418 
419 #ifndef __HAIKU__
420 #define gettimeofday isc__gettimeofday
421 #ifdef NEED_GETTIMEOFDAY
422 int isc__gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp);
423 #else
424 int isc__gettimeofday(struct timeval *tp, struct timezone *tzp);
425 #endif
426 #endif
427 
428 int getnetgrent(NGR_R_CONST char **machinep, NGR_R_CONST char **userp,
429 		NGR_R_CONST char **domainp);
430 
431 #ifdef NGR_R_ARGS
432 int getnetgrent_r(NGR_R_CONST char **machinep, NGR_R_CONST char **userp,
433 		  NGR_R_CONST char **domainp, NGR_R_ARGS);
434 #endif
435 
436 #ifdef SETNETGRENT_ARGS
437 void setnetgrent(SETNETGRENT_ARGS);
438 #else
439 void setnetgrent(const char *netgroup);
440 #endif
441 
442 void endnetgrent(void);
443 
444 #ifdef INNETGR_ARGS
445 int innetgr(INNETGR_ARGS);
446 #else
447 int innetgr(const char *netgroup, const char *machine,
448 	    const char *user, const char *domain);
449 #endif
450 
451 #ifdef NGR_R_SET_ARGS
452 NGR_R_SET_RETURN
453 setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS);
454 #else
455 NGR_R_SET_RETURN
456 setnetgrent_r(NGR_R_SET_CONST char *netgroup);
457 #endif
458 
459 #ifdef NEED_STRTOUL
460 unsigned long strtoul(const char *, char **, int);
461 #endif
462 
463 #ifdef NEED_SUN4PROTOS
464 #include <stdarg.h>
465 #ifndef __SIZE_TYPE__
466 #define __SIZE_TYPE__ int
467 #endif
468 struct sockaddr;
469 struct iovec;
470 struct timeval;
471 struct timezone;
472 int fprintf(FILE *, const char *, ...);
473 int getsockname(int, struct sockaddr *, int *);
474 int getpeername(int, struct sockaddr *, int *);
475 int socket(int, int, int);
476 int connect(int, const struct sockaddr *, int);
477 int writev(int, struct iovec *, int);
478 int readv(int, struct iovec *, int);
479 int send(int, const char *, int, int);
480 void bzero(char *, int);
481 int recvfrom(int, char *, int, int, struct sockaddr *, int *);
482 int syslog(int, const char *, ... );
483 int printf(const char *, ...);
484 __SIZE_TYPE__ fread(void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *);
485 __SIZE_TYPE__ fwrite(const void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *);
486 int fclose(FILE *);
487 int ungetc(int, FILE *);
488 int scanf(const char *, ...);
489 int sscanf(const char *, const char *, ... );
490 int tolower(int);
491 int toupper(int);
492 int strcasecmp(const char *, const char *);
493 int strncasecmp(const char *, const char *, int);
494 int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
495 #ifdef gettimeofday
496 #undef gettimeofday
497 int gettimeofday(struct timeval *, struct timezone *);
498 #define gettimeofday isc__gettimeofday
499 #else
500 int gettimeofday(struct timeval *, struct timezone *);
501 #endif
502 long strtol(const char*, char **, int);
503 int fseek(FILE *, long, int);
504 int setsockopt(int, int, int, const char *, int);
505 int bind(int, const struct sockaddr *, int);
506 void bcopy(char *, char *, int);
507 int fputc(char, FILE *);
508 int listen(int, int);
509 int accept(int, struct sockaddr *, int *);
510 int getsockopt(int, int, int, char *, int *);
511 int vfprintf(FILE *, const char *, va_list);
512 int fflush(FILE *);
513 int fgetc(FILE *);
514 int fputs(const char *, FILE *);
515 int fchown(int, int, int);
516 void setbuf(FILE *, char *);
517 int gethostname(char *, int);
518 int rename(const char *, const char *);
519 time_t time(time_t *);
520 int fscanf(FILE *, const char *, ...);
521 int sscanf(const char *, const char *, ...);
522 int ioctl(int, int, caddr_t);
523 void perror(const char *);
524 
525 #if !defined(__USE_FIXED_PROTOTYPES__) && !defined(__cplusplus) && !defined(__STRICT_ANSI__)
526 /*
527  * 'gcc -ansi' changes the prototype for vsprintf().
528  * Use this prototype when 'gcc -ansi' is not in effect.
529  */
530 char *vsprintf(char *, const char *, va_list);
531 #endif
532 #endif
533 
534 #endif
535