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