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