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
52const 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. */
102struct 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. */
115struct 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
175struct 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
194extern 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
221extern 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
295char * 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
303int setgroupent(int stayopen);
304#endif
305
306#ifdef NEED_GETGROUPLIST
307int getgrouplist(GETGROUPLIST_ARGS);
308#endif
309
310#ifdef POSIX_GETGRNAM_R
311int
312__posix_getgrnam_r(const char *, struct group *, char *, int, struct group **);
313#endif
314
315#ifdef NEED_GETGRNAM_R
316int
317getgrnam_r(const char *,  struct group *, char *, size_t, struct group **);
318#endif
319
320#ifdef POSIX_GETGRGID_R
321int
322__posix_getgrgid_r(gid_t, struct group *, char *, int, struct group **) ;
323#endif
324
325#ifdef NEED_GETGRGID_R
326int
327getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
328#endif
329
330#ifdef NEED_GETGRENT_R
331GROUP_R_RETURN getgrent_r(struct group *gptr, GROUP_R_ARGS);
332#endif
333
334#ifdef NEED_SETGRENT_R
335GROUP_R_SET_RETURN setgrent_r(GROUP_R_ENT_ARGS);
336#endif
337
338#ifdef NEED_ENDGRENT_R
339GROUP_R_END_RETURN endgrent_r(GROUP_R_ENT_ARGS);
340#endif
341
342#if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN)
343NGR_R_RETURN
344innetgr_r(const char *, const char *, const char *, const char *);
345#endif
346
347#ifdef NEED_SETNETGRENT_R
348#ifdef NGR_R_SET_ARGS
349NGR_R_SET_RETURN setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS);
350#else
351NGR_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
357NGR_R_END_RETURN endnetgrent_r(NGR_R_END_ARGS);
358#else
359NGR_R_END_RETURN endnetgrent_r(void);
360#endif
361#endif
362
363#ifdef POSIX_GETPWNAM_R
364int
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
370int
371getpwnam_r(const char *login,  struct passwd *pwptr,
372		char *buf, size_t buflen, struct passwd **result);
373#endif
374
375#ifdef POSIX_GETPWUID_R
376int
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
382int
383getpwuid_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
389PASS_R_SET_RETURN setpwent_r(PASS_R_ENT_ARGS);
390#else
391PASS_R_SET_RETURN setpwent_r(void);
392#endif
393
394#endif
395
396#ifdef NEED_SETPASSENT_R
397#ifdef PASS_R_ENT_ARGS
398PASS_R_SET_RETURN setpassent_r(int stayopen, PASS_R_ENT_ARGS);
399#else
400PASS_R_SET_RETURN setpassent_r(int stayopen);
401#endif
402#endif
403
404#ifdef NEED_GETPWENT_R
405PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS);
406#endif
407
408#ifdef NEED_ENDPWENT_R
409void endpwent_r(void);
410#endif
411
412#ifdef NEED_SETPASSENT
413int setpassent(int stayopen);
414#endif
415
416#define gettimeofday isc__gettimeofday
417#ifdef NEED_GETTIMEOFDAY
418int isc__gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp);
419#else
420int isc__gettimeofday(struct timeval *tp, struct timezone *tzp);
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/* setnetgrent and endnetgrent are defined in sunw_port_after.h
432#ifdef SETNETGRENT_ARGS
433void setnetgrent(SETNETGRENT_ARGS);
434#else
435void setnetgrent(const char *netgroup);
436#endif
437
438void endnetgrent(void);
439*/
440
441#ifdef INNETGR_ARGS
442int innetgr(INNETGR_ARGS);
443#else
444int innetgr(const char *netgroup, const char *machine,
445	    const char *user, const char *domain);
446#endif
447
448#ifdef NGR_R_SET_ARGS
449NGR_R_SET_RETURN
450setnetgrent_r(NGR_R_SET_CONST char *netgroup, NGR_R_SET_ARGS);
451#else
452NGR_R_SET_RETURN
453setnetgrent_r(NGR_R_SET_CONST char *netgroup);
454#endif
455
456#ifdef NEED_STRTOUL
457unsigned 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
465struct sockaddr;
466struct iovec;
467struct timeval;
468struct timezone;
469int fprintf(FILE *, const char *, ...);
470int getsockname(int, struct sockaddr *, int *);
471int getpeername(int, struct sockaddr *, int *);
472int socket(int, int, int);
473int connect(int, const struct sockaddr *, int);
474int writev(int, struct iovec *, int);
475int readv(int, struct iovec *, int);
476int send(int, const char *, int, int);
477void bzero(char *, int);
478int recvfrom(int, char *, int, int, struct sockaddr *, int *);
479int syslog(int, const char *, ... );
480int printf(const char *, ...);
481__SIZE_TYPE__ fread(void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *);
482__SIZE_TYPE__ fwrite(const void *, __SIZE_TYPE__, __SIZE_TYPE__, FILE *);
483int fclose(FILE *);
484int ungetc(int, FILE *);
485int scanf(const char *, ...);
486int sscanf(const char *, const char *, ... );
487int tolower(int);
488int toupper(int);
489int strcasecmp(const char *, const char *);
490int strncasecmp(const char *, const char *, int);
491int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
492#ifdef gettimeofday
493#undef gettimeofday
494int gettimeofday(struct timeval *, struct timezone *);
495#define gettimeofday isc__gettimeofday
496#else
497int gettimeofday(struct timeval *, struct timezone *);
498#endif
499long strtol(const char*, char **, int);
500int fseek(FILE *, long, int);
501int setsockopt(int, int, int, const char *, int);
502int bind(int, const struct sockaddr *, int);
503void bcopy(char *, char *, int);
504int fputc(char, FILE *);
505int listen(int, int);
506int accept(int, struct sockaddr *, int *);
507int getsockopt(int, int, int, char *, int *);
508int vfprintf(FILE *, const char *, va_list);
509int fflush(FILE *);
510int fgetc(FILE *);
511int fputs(const char *, FILE *);
512int fchown(int, int, int);
513void setbuf(FILE *, char *);
514int gethostname(char *, int);
515int rename(const char *, const char *);
516time_t time(time_t *);
517int fscanf(FILE *, const char *, ...);
518int sscanf(const char *, const char *, ...);
519int ioctl(int, int, caddr_t);
520void 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 */
527char *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 */
535