2 * Copyright (C) 2004-2008 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2001-2003 Internet Software Consortium.
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.
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.
18 /* Id: port_after.h.in,v 1.60 2008/02/28 05:34:17 marka Exp */
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <sys/param.h>
28 #if (!defined(BSD)) || (BSD < 199306)
29 #include <sys/bitypes.h>
31 #ifdef HAVE_INTTYPES_H
34 #ifdef HAVE_SYS_SELECT_H
35 #include <sys/select.h>
36 #endif /* HAVE_SYS_SELECT_H */
49 const char *isc_strerror(int);
50 #define strerror isc_strerror
56 @HAVE_SOCKADDR_STORAGE@
65 #ifndef _POSIX_PATH_MAX
66 #define _POSIX_PATH_MAX 255
69 #define PATH_MAX _POSIX_PATH_MAX
73 * We need to know the IPv6 address family number even on IPv4-only systems.
74 * Note that this is NOT a protocol constant, and that if the system has its
75 * own AF_INET6, different from ours below, all of BIND's libraries and
76 * executables will need to be recompiled after the system <sys/socket.h>
77 * has had this type added. The type number below is correct on most BSD-
78 * derived systems for which AF_INET6 is defined.
85 #define PF_INET6 AF_INET6
89 /* Map to pre-RFC structure. */
90 #define in6_addr in_addr6
93 #ifndef HAS_INET6_STRUCTS
94 /* Replace with structure from later rev of O/S if known. */
99 #define IN6ADDR_ANY_INIT \
100 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
103 #define IN6ADDR_LOOPBACK_INIT \
104 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
105 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
107 /* Replace with structure from later rev of O/S if known. */
108 struct sockaddr_in6
{
110 u_int8_t sin6_len
; /* length of this struct */
111 u_int8_t sin6_family
; /* AF_INET6 */
113 u_int16_t sin6_family
; /* AF_INET6 */
115 u_int16_t sin6_port
; /* transport layer port # */
116 u_int32_t sin6_flowinfo
; /* IPv6 flow information */
117 struct in6_addr sin6_addr
; /* IPv6 address */
118 u_int32_t sin6_scope_id
; /* set of interfaces for a scope */
120 #endif /* HAS_INET6_STRUCTS */
122 #ifdef BROKEN_IN6ADDR_INIT_MACROS
123 #undef IN6ADDR_ANY_INIT
124 #undef IN6ADDR_LOOPBACK_INIT
128 #ifndef IN6ADDR_ANY_INIT
129 #define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0 }}}
131 #ifndef IN6ADDR_LOOPBACK_INIT
132 #if BYTE_ORDER == BIG_ENDIAN
133 #define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 1 }}}
135 #define IN6ADDR_LOOPBACK_INIT {{{0, 0, 0, 0x01000000}}}
140 #ifndef IN6ADDR_ANY_INIT
142 #define IN6ADDR_ANY_INIT \
143 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
146 #define IN6ADDR_ANY_INIT \
147 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
152 #ifndef IN6ADDR_LOOPBACK_INIT
154 #define IN6ADDR_LOOPBACK_INIT \
155 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
158 #define IN6ADDR_LOOPBACK_INIT \
159 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
164 #ifndef HAVE_SOCKADDR_STORAGE
165 #define __SS_MAXSIZE 128
166 #define __SS_ALLIGSIZE (sizeof (long))
168 struct sockaddr_storage
{
170 u_int8_t ss_len
; /* address length */
171 u_int8_t ss_family
; /* address family */
172 char __ss_pad1
[__SS_ALLIGSIZE
- 2 * sizeof(u_int8_t
)];
174 char __ss_pad2
[__SS_MAXSIZE
- 2 * __SS_ALLIGSIZE
];
176 u_int16_t ss_family
; /* address family */
177 char __ss_pad1
[__SS_ALLIGSIZE
- sizeof(u_int16_t
)];
179 char __ss_pad2
[__SS_MAXSIZE
- 2 * __SS_ALLIGSIZE
];
185 #if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY)
186 #define in6addr_any isc_in6addr_any
187 extern const struct in6_addr in6addr_any
;
191 * IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_V4COMPAT and
192 * IN6_IS_ADDR_V4MAPPED are broken in glibc 2.1.
195 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2)
196 #undef IN6_ARE_ADDR_EQUAL
197 #undef IN6_IS_ADDR_UNSPECIFIED
198 #undef IN6_IS_ADDR_V4COMPAT
199 #undef IN6_IS_ADDR_V4MAPPED
203 #ifndef IN6_ARE_ADDR_EQUAL
204 #define IN6_ARE_ADDR_EQUAL(a,b) \
205 (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
208 #ifndef IN6_IS_ADDR_UNSPECIFIED
209 #define IN6_IS_ADDR_UNSPECIFIED(a) \
210 IN6_ARE_ADDR_EQUAL(a, &in6addr_any)
213 #ifndef IN6_IS_ADDR_LOOPBACK
214 extern const struct in6_addr isc_in6addr_loopback
;
215 #define IN6_IS_ADDR_LOOPBACK(a) \
216 IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback)
219 #ifndef IN6_IS_ADDR_V4MAPPED
220 #define IN6_IS_ADDR_V4MAPPED(a) \
221 ((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
222 (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
223 (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
224 (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \
225 (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
226 (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
229 #ifndef IN6_IS_ADDR_SITELOCAL
230 #define IN6_IS_ADDR_SITELOCAL(a) \
231 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
234 #ifndef IN6_IS_ADDR_LINKLOCAL
235 #define IN6_IS_ADDR_LINKLOCAL(a) \
236 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
239 #ifndef IN6_IS_ADDR_MULTICAST
240 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
243 #ifndef __IPV6_ADDR_MC_SCOPE
244 #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
247 #ifndef __IPV6_ADDR_SCOPE_SITELOCAL
248 #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
250 #ifndef __IPV6_ADDR_SCOPE_ORGLOCAL
251 #define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08
254 #ifndef IN6_IS_ADDR_MC_SITELOCAL
255 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
256 (IN6_IS_ADDR_MULTICAST(a) && \
257 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
260 #ifndef IN6_IS_ADDR_MC_ORGLOCAL
261 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
262 (IN6_IS_ADDR_MULTICAST(a) && \
263 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
267 #define INADDR_NONE 0xffffffff
270 #ifndef MAXHOSTNAMELEN
271 #define MAXHOSTNAMELEN 256
274 #ifndef INET6_ADDRSTRLEN
275 /* sizeof("aaaa:bbbb:cccc:dddd:eeee:ffff:123.123.123.123") */
276 #define INET6_ADDRSTRLEN 46
280 #define MIN(x,y) (((x) <= (y)) ? (x) : (y))
284 #define MAX(x,y) (((x) >= (y)) ? (x) : (y))
288 int daemon(int nochdir
, int noclose
);
292 char * strsep(char **stringp
, const char *delim
);
296 #define ALIGN(p) (((uintptr_t)(p) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
299 #ifdef NEED_SETGROUPENT
300 int setgroupent(int stayopen
);
303 #ifdef NEED_GETGROUPLIST
304 int getgrouplist(GETGROUPLIST_ARGS
);
307 #ifdef POSIX_GETGRNAM_R
309 __posix_getgrnam_r(const char *, struct group
*, char *, int, struct group
**);
312 #ifdef NEED_GETGRNAM_R
314 getgrnam_r(const char *, struct group
*, char *, size_t, struct group
**);
317 #ifdef POSIX_GETGRGID_R
319 __posix_getgrgid_r(gid_t
, struct group
*, char *, int, struct group
**) ;
322 #ifdef NEED_GETGRGID_R
324 getgrgid_r(gid_t
, struct group
*, char *, size_t, struct group
**);
327 #ifdef NEED_GETGRENT_R
328 GROUP_R_RETURN
getgrent_r(struct group
*gptr
, GROUP_R_ARGS
);
331 #ifdef NEED_SETGRENT_R
332 GROUP_R_SET_RETURN
setgrent_r(GROUP_R_ENT_ARGS
);
335 #ifdef NEED_ENDGRENT_R
336 GROUP_R_END_RETURN
endgrent_r(GROUP_R_ENT_ARGS
);
339 #if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN)
341 innetgr_r(const char *, const char *, const char *, const char *);
344 #ifdef NEED_SETNETGRENT_R
345 #ifdef NGR_R_SET_ARGS
346 NGR_R_SET_RETURN
setnetgrent_r(NGR_R_SET_CONST
char *netgroup
, NGR_R_SET_ARGS
);
348 NGR_R_SET_RETURN
setnetgrent_r(NGR_R_SET_CONST
char *netgroup
);
352 #ifdef NEED_ENDNETGRENT_R
353 #ifdef NGR_R_END_ARGS
354 NGR_R_END_RETURN
endnetgrent_r(NGR_R_END_ARGS
);
356 NGR_R_END_RETURN
endnetgrent_r(void);
360 #ifdef POSIX_GETPWNAM_R
362 __posix_getpwnam_r(const char *login
, struct passwd
*pwptr
,
363 char *buf
, size_t buflen
, struct passwd
**result
);
366 #ifdef NEED_GETPWNAM_R
368 getpwnam_r(const char *login
, struct passwd
*pwptr
,
369 char *buf
, size_t buflen
, struct passwd
**result
);
372 #ifdef POSIX_GETPWUID_R
374 __posix_getpwuid_r(uid_t uid
, struct passwd
*pwptr
,
375 char *buf
, int buflen
, struct passwd
**result
);
378 #ifdef NEED_GETPWUID_R
380 getpwuid_r(uid_t uid
, struct passwd
*pwptr
,
381 char *buf
, size_t buflen
, struct passwd
**result
);
384 #ifdef NEED_SETPWENT_R
385 #ifdef PASS_R_ENT_ARGS
386 PASS_R_SET_RETURN
setpwent_r(PASS_R_ENT_ARGS
);
388 PASS_R_SET_RETURN
setpwent_r(void);
393 #ifdef NEED_SETPASSENT_R
394 #ifdef PASS_R_ENT_ARGS
395 PASS_R_SET_RETURN
setpassent_r(int stayopen
, PASS_R_ENT_ARGS
);
397 PASS_R_SET_RETURN
setpassent_r(int stayopen
);
401 #ifdef NEED_GETPWENT_R
402 PASS_R_RETURN
getpwent_r(struct passwd
*pwptr
, PASS_R_ARGS
);
405 #ifdef NEED_ENDPWENT_R
406 void endpwent_r(void);
409 #ifdef NEED_SETPASSENT
410 int setpassent(int stayopen
);
413 #define gettimeofday isc__gettimeofday
414 #ifdef NEED_GETTIMEOFDAY
415 int isc__gettimeofday(struct timeval
*tvp
, struct _TIMEZONE
*tzp
);
417 int isc__gettimeofday(struct timeval
*tp
, struct timezone
*tzp
);
420 int getnetgrent(NGR_R_CONST
char **machinep
, NGR_R_CONST
char **userp
,
421 NGR_R_CONST
char **domainp
);
424 int getnetgrent_r(NGR_R_CONST
char **machinep
, NGR_R_CONST
char **userp
,
425 NGR_R_CONST
char **domainp
, NGR_R_ARGS
);
428 #ifdef SETNETGRENT_ARGS
429 void setnetgrent(SETNETGRENT_ARGS
);
431 void setnetgrent(const char *netgroup
);
434 void endnetgrent(void);
437 int innetgr(INNETGR_ARGS
);
439 int innetgr(const char *netgroup
, const char *machine
,
440 const char *user
, const char *domain
);
443 #ifdef NGR_R_SET_ARGS
445 setnetgrent_r(NGR_R_SET_CONST
char *netgroup
, NGR_R_SET_ARGS
);
448 setnetgrent_r(NGR_R_SET_CONST
char *netgroup
);
452 unsigned long strtoul(const char *, char **, int);
455 #ifdef NEED_SUN4PROTOS
457 #ifndef __SIZE_TYPE__
458 #define __SIZE_TYPE__ int
464 int fprintf(FILE *, const char *, ...);
465 int getsockname(int, struct sockaddr
*, int *);
466 int getpeername(int, struct sockaddr
*, int *);
467 int socket(int, int, int);
468 int connect(int, const struct sockaddr
*, int);
469 int writev(int, struct iovec
*, int);
470 int readv(int, struct iovec
*, int);
471 int send(int, const char *, int, int);
472 void bzero(char *, int);
473 int recvfrom(int, char *, int, int, struct sockaddr
*, int *);
474 int syslog(int, const char *, ... );
475 int printf(const char *, ...);
476 __SIZE_TYPE__
fread(void *, __SIZE_TYPE__
, __SIZE_TYPE__
, FILE *);
477 __SIZE_TYPE__
fwrite(const void *, __SIZE_TYPE__
, __SIZE_TYPE__
, FILE *);
479 int ungetc(int, FILE *);
480 int scanf(const char *, ...);
481 int sscanf(const char *, const char *, ... );
484 int strcasecmp(const char *, const char *);
485 int strncasecmp(const char *, const char *, int);
486 int select(int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*);
489 int gettimeofday(struct timeval
*, struct timezone
*);
490 #define gettimeofday isc__gettimeofday
492 int gettimeofday(struct timeval
*, struct timezone
*);
494 long strtol(const char*, char **, int);
495 int fseek(FILE *, long, int);
496 int setsockopt(int, int, int, const char *, int);
497 int bind(int, const struct sockaddr
*, int);
498 void bcopy(char *, char *, int);
499 int fputc(char, FILE *);
500 int listen(int, int);
501 int accept(int, struct sockaddr
*, int *);
502 int getsockopt(int, int, int, char *, int *);
503 int vfprintf(FILE *, const char *, va_list);
506 int fputs(const char *, FILE *);
507 int fchown(int, int, int);
508 void setbuf(FILE *, char *);
509 int gethostname(char *, int);
510 int rename(const char *, const char *);
511 time_t time(time_t *);
512 int fscanf(FILE *, const char *, ...);
513 int sscanf(const char *, const char *, ...);
514 int ioctl(int, int, caddr_t
);
515 void perror(const char *);
517 #if !defined(__USE_FIXED_PROTOTYPES__) && !defined(__cplusplus) && !defined(__STRICT_ANSI__)
519 * 'gcc -ansi' changes the prototype for vsprintf().
520 * Use this prototype when 'gcc -ansi' is not in effect.
522 char *vsprintf(char *, const char *, va_list);