1 /* $DragonFly: src/lib/libbind/port_after.h,v 1.2 2006/09/20 21:48:39 victor Exp $ */
7 #include <sys/socket.h>
9 #if (!defined(BSD)) || (BSD < 199306)
10 #include <sys/bitypes.h>
12 #ifdef HAVE_INTTYPES_H
18 #define HAVE_MINIMUM_IFREQ 1
22 #define HAS_INET6_STRUCTS 1
23 #define HAVE_SIN6_SCOPE_ID 1
24 #undef NEED_IN6ADDR_ANY
26 #define HAVE_SOCKADDR_STORAGE 1
27 #undef NEED_GETTIMEOFDAY
29 #undef USE_FIONBIO_IOCTL
30 #undef USE_SYSERROR_LIST
32 #undef SETNETGRENT_ARGS
33 #define USE_IFNAMELINKID 1
34 #define PORT_NONBLOCK O_NONBLOCK
37 * We need to know the IPv6 address family number even on IPv4-only systems.
38 * Note that this is NOT a protocol constant, and that if the system has its
39 * own AF_INET6, different from ours below, all of BIND's libraries and
40 * executables will need to be recompiled after the system <sys/socket.h>
41 * has had this type added. The type number below is correct on most BSD-
42 * derived systems for which AF_INET6 is defined.
49 #define PF_INET6 AF_INET6
53 /* Map to pre-RFC structure. */
54 #define in6_addr in_addr6
57 #ifndef HAS_INET6_STRUCTS
58 /* Replace with structure from later rev of O/S if known. */
63 #define IN6ADDR_ANY_INIT \
64 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
65 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
67 #define IN6ADDR_LOOPBACK_INIT \
68 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
71 /* Replace with structure from later rev of O/S if known. */
74 u_int8_t sin6_len
; /* length of this struct */
75 u_int8_t sin6_family
; /* AF_INET6 */
77 u_int16_t sin6_family
; /* AF_INET6 */
79 u_int16_t sin6_port
; /* transport layer port # */
80 u_int32_t sin6_flowinfo
; /* IPv6 flow information */
81 struct in6_addr sin6_addr
; /* IPv6 address */
82 u_int32_t sin6_scope_id
; /* set of interfaces for a scope */
84 #endif /* HAS_INET6_STRUCTS */
86 #ifdef BROKEN_IN6ADDR_INIT_MACROS
87 #undef IN6ADDR_ANY_INIT
88 #undef IN6ADDR_LOOPBACK_INIT
92 #ifndef IN6ADDR_ANY_INIT
93 #define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0 }}}
95 #ifndef IN6ADDR_LOOPBACK_INIT
96 #if BYTE_ORDER == BIG_ENDIAN
97 #define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 1 }}}
99 #define IN6ADDR_LOOPBACK_INIT {{{0, 0, 0, 0x01000000}}}
104 #ifndef IN6ADDR_ANY_INIT
106 #define IN6ADDR_ANY_INIT \
107 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
110 #define IN6ADDR_ANY_INIT \
111 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
112 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
116 #ifndef IN6ADDR_LOOPBACK_INIT
118 #define IN6ADDR_LOOPBACK_INIT \
119 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
122 #define IN6ADDR_LOOPBACK_INIT \
123 {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
128 #ifndef HAVE_SOCKADDR_STORAGE
129 #define __SS_MAXSIZE 128
130 #define __SS_ALLIGSIZE (sizeof (long))
132 struct sockaddr_storage
{
134 u_int8_t ss_len
; /* address length */
135 u_int8_t ss_family
; /* address family */
136 char __ss_pad1
[__SS_ALLIGSIZE
- 2 * sizeof(u_int8_t
)];
138 char __ss_pad2
[__SS_MAXSIZE
- 2 * __SS_ALLIGSIZE
];
140 u_int16_t ss_family
; /* address family */
141 char __ss_pad1
[__SS_ALLIGSIZE
- sizeof(u_int16_t
)];
143 char __ss_pad2
[__SS_MAXSIZE
- 2 * __SS_ALLIGSIZE
];
149 #if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY)
150 #define in6addr_any isc_in6addr_any
151 extern const struct in6_addr in6addr_any
;
155 * IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_V4COMPAT and
156 * IN6_IS_ADDR_V4MAPPED are broken in glibc 2.1.
159 #if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2)
160 #undef IN6_ARE_ADDR_EQUAL
161 #undef IN6_IS_ADDR_UNSPECIFIED
162 #undef IN6_IS_ADDR_V4COMPAT
163 #undef IN6_IS_ADDR_V4MAPPED
167 #ifndef IN6_ARE_ADDR_EQUAL
168 #define IN6_ARE_ADDR_EQUAL(a,b) \
169 (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
172 #ifndef IN6_IS_ADDR_UNSPECIFIED
173 #define IN6_IS_ADDR_UNSPECIFIED(a) \
174 IN6_ARE_ADDR_EQUAL(a, &in6addr_any)
177 #ifndef IN6_IS_ADDR_LOOPBACK
178 extern const struct in6_addr isc_in6addr_loopback
;
179 #define IN6_IS_ADDR_LOOPBACK(a) \
180 IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback)
183 #ifndef IN6_IS_ADDR_V4MAPPED
184 #define IN6_IS_ADDR_V4MAPPED(a) \
185 ((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
186 (a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
187 (a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
188 (a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \
189 (a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
190 (a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
193 #ifndef IN6_IS_ADDR_SITELOCAL
194 #define IN6_IS_ADDR_SITELOCAL(a) \
195 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
198 #ifndef IN6_IS_ADDR_LINKLOCAL
199 #define IN6_IS_ADDR_LINKLOCAL(a) \
200 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
203 #ifndef IN6_IS_ADDR_MULTICAST
204 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
207 #ifndef __IPV6_ADDR_MC_SCOPE
208 #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
211 #ifndef __IPV6_ADDR_SCOPE_SITELOCAL
212 #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
214 #ifndef __IPV6_ADDR_SCOPE_ORGLOCAL
215 #define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08
218 #ifndef IN6_IS_ADDR_MC_SITELOCAL
219 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
220 (IN6_IS_ADDR_MULTICAST(a) && \
221 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
224 #ifndef IN6_IS_ADDR_MC_ORGLOCAL
225 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
226 (IN6_IS_ADDR_MULTICAST(a) && \
227 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
231 #define INADDR_NONE 0xffffffff
234 #ifndef MAXHOSTNAMELEN
235 #define MAXHOSTNAMELEN 256
238 #ifndef INET6_ADDRSTRLEN
239 /* sizeof("aaaa:bbbb:cccc:dddd:eeee:ffff:123.123.123.123") */
240 #define INET6_ADDRSTRLEN 46
244 #define MIN(x,y) (((x) <= (y)) ? (x) : (y))
248 #define MAX(x,y) (((x) >= (y)) ? (x) : (y))
252 int daemon(int nochdir
, int noclose
);
256 char * strsep(char **stringp
, const char *delim
);
260 #define ALIGN(p) (((uintptr_t)(p) + (sizeof(long) - 1)) & ~(sizeof(long) - 1))
263 #ifdef NEED_SETGROUPENT
264 int setgroupent(int stayopen
);
267 #ifdef NEED_GETGROUPLIST
268 int getgrouplist(GETGROUPLIST_ARGS
);
271 #ifdef POSIX_GETGRNAM_R
273 __posix_getgrnam_r(const char *, struct group
*, char *, int, struct group
**);
276 #ifdef NEED_GETGRNAM_R
278 getgrnam_r(const char *, struct group
*, char *, size_t, struct group
**);
281 #ifdef POSIX_GETGRGID_R
283 __posix_getgrgid_r(gid_t
, struct group
*, char *, int, struct group
**) ;
286 #ifdef NEED_GETGRGID_R
288 getgrgid_r(gid_t
, struct group
*, char *, size_t, struct group
**);
291 #ifdef NEED_GETGRENT_R
292 GROUP_R_RETURN
getgrent_r(struct group
*gptr
, GROUP_R_ARGS
);
295 #ifdef NEED_SETGRENT_R
296 GROUP_R_SET_RETURN
setgrent_r(GROUP_R_ENT_ARGS
);
299 #ifdef NEED_ENDGRENT_R
300 GROUP_R_END_RETURN
endgrent_r(GROUP_R_ENT_ARGS
);
303 #if defined(NEED_INNETGR_R) && defined(NGR_R_RETURN)
305 innetgr_r(const char *, const char *, const char *, const char *);
308 #ifdef NEED_SETNETGRENT_R
309 #ifdef NGR_R_ENT_ARGS
310 NGR_R_SET_RETURN
setnetgrent_r(const char *netgroup
, NGR_R_ENT_ARGS
);
312 NGR_R_SET_RETURN
setnetgrent_r(const char *netgroup
);
316 #ifdef NEED_ENDNETGRENT_R
317 #ifdef NGR_R_ENT_ARGS
318 NGR_R_END_RETURN
endnetgrent_r(NGR_R_ENT_ARGS
);
320 NGR_R_END_RETURN
endnetgrent_r(void);
324 #ifdef POSIX_GETPWNAM_R
326 __posix_getpwnam_r(const char *login
, struct passwd
*pwptr
,
327 char *buf
, size_t buflen
, struct passwd
**result
);
330 #ifdef NEED_GETPWNAM_R
332 getpwnam_r(const char *login
, struct passwd
*pwptr
,
333 char *buf
, size_t buflen
, struct passwd
**result
);
336 #ifdef POSIX_GETPWUID_R
338 __posix_getpwuid_r(uid_t uid
, struct passwd
*pwptr
,
339 char *buf
, int buflen
, struct passwd
**result
);
342 #ifdef NEED_GETPWUID_R
344 getpwuid_r(uid_t uid
, struct passwd
*pwptr
,
345 char *buf
, size_t buflen
, struct passwd
**result
);
348 #ifdef NEED_SETPWENT_R
349 #ifdef PASS_R_ENT_ARGS
350 PASS_R_SET_RETURN
setpwent_r(PASS_R_ENT_ARGS
);
352 PASS_R_SET_RETURN
setpwent_r(void);
357 #ifdef NEED_SETPASSENT_R
358 #ifdef PASS_R_ENT_ARGS
359 PASS_R_SET_RETURN
setpassent_r(int stayopen
, PASS_R_ENT_ARGS
);
361 PASS_R_SET_RETURN
setpassent_r(int stayopen
);
365 #ifdef NEED_GETPWENT_R
366 PASS_R_RETURN
getpwent_r(struct passwd
*pwptr
, PASS_R_ARGS
);
369 #ifdef NEED_ENDPWENT_R
370 void endpwent_r(void);
373 #ifdef NEED_SETPASSENT
374 int setpassent(int stayopen
);
377 #define gettimeofday isc__gettimeofday
378 #ifdef NEED_GETTIMEOFDAY
379 int isc__gettimeofday(struct timeval
*tvp
, struct _TIMEZONE
*tzp
);
381 int isc__gettimeofday(struct timeval
*tp
, struct timezone
*tzp
);
384 int getnetgrent(char **machinep
, char **userp
, char **domainp
);
387 int getnetgrent_r(char **machinep
, char **userp
, char **domainp
, NGR_R_ARGS
);
390 #ifdef SETNETGRENT_ARGS
391 void setnetgrent(SETNETGRENT_ARGS
);
393 void setnetgrent(const char *netgroup
);
396 void endnetgrent(void);
399 int innetgr(INNETGR_ARGS
);
401 int innetgr(const char *netgroup
, const char *machine
,
402 const char *user
, const char *domain
);
405 #ifdef NGR_R_ENT_ARGS
407 setnetgrent_r(const char *netgroup
, NGR_R_ENT_ARGS
);
410 setnetgrent_r(const char *netgroup
);