1 /*
2  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 #ifndef UTIL_INTERNAL_H_INCLUDED_
27 #define UTIL_INTERNAL_H_INCLUDED_
28 
29 #include "event2/event-config.h"
30 #include "evconfig-private.h"
31 
32 #include <errno.h>
33 
34 /* For EVUTIL_ASSERT */
35 #include "log-internal.h"
36 #include <stdio.h>
37 #include <stdlib.h>
38 #ifdef EVENT__HAVE_SYS_SOCKET_H
39 #include <sys/socket.h>
40 #endif
41 #ifdef EVENT__HAVE_SYS_EVENTFD_H
42 #include <sys/eventfd.h>
43 #endif
44 #include "event2/util.h"
45 
46 #include "time-internal.h"
47 #include "ipv6-internal.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /* __has_attribute() wrapper */
54 #ifdef __has_attribute
55 # define EVUTIL_HAS_ATTRIBUTE __has_attribute
56 #endif
57 /** clang 3 __has_attribute misbehaves in some versions */
58 #if defined(__clang__) && __clang__ == 1
59 # if defined(__apple_build_version__)
60 #  if __clang_major__ <= 6
61 #   undef EVUTIL_HAS_ATTRIBUTE
62 #  endif
63 # else /* !__apple_build_version__ */
64 #  if __clang_major__ == 3 && __clang_minor__ >= 2 && __clang_minor__ <= 5
65 #   undef EVUTIL_HAS_ATTRIBUTE
66 #  endif
67 # endif /* __apple_build_version__ */
68 #endif /*\ defined(__clang__) && __clang__ == 1 */
69 #ifndef EVUTIL_HAS_ATTRIBUTE
70 # define EVUTIL_HAS_ATTRIBUTE(x) 0
71 #endif
72 
73 #if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
74 # undef EVUTIL_HAS_ATTRIBUTE
75 # define EVUTIL_HAS_ATTRIBUTE(x) 0
76 #endif
77 
78 /* If we need magic to say "inline", get it for free internally. */
79 #ifdef EVENT__inline
80 #define inline EVENT__inline
81 #endif
82 
83 /* Define to appropriate substitute if compiler doesnt have __func__ */
84 #if defined(EVENT__HAVE___func__)
85 # ifndef __func__
86 #  define __func__ __func__
87 # endif
88 #elif defined(EVENT__HAVE___FUNCTION__)
89 # define __func__ __FUNCTION__
90 #else
91 # define __func__ __FILE__
92 #endif
93 
94 /* A good no-op to use in macro definitions. */
95 #define EVUTIL_NIL_STMT_ ((void)0)
96 /* A no-op that tricks the compiler into thinking a condition is used while
97  * definitely not making any code for it.  Used to compile out asserts while
98  * avoiding "unused variable" warnings.  The "!" forces the compiler to
99  * do the sizeof() on an int, in case "condition" is a bitfield value.
100  */
101 #define EVUTIL_NIL_CONDITION_(condition) do { \
102 	(void)sizeof(!(condition));  \
103 } while(0)
104 
105 /* Internal use only: macros to match patterns of error codes in a
106    cross-platform way.  We need these macros because of two historical
107    reasons: first, nonblocking IO functions are generally written to give an
108    error on the "blocked now, try later" case, so sometimes an error from a
109    read, write, connect, or accept means "no error; just wait for more
110    data," and we need to look at the error code.  Second, Windows defines
111    a different set of error codes for sockets. */
112 
113 #ifndef _WIN32
114 
115 #if EAGAIN == EWOULDBLOCK
116 #define EVUTIL_ERR_IS_EAGAIN(e) \
117 	((e) == EAGAIN)
118 #else
119 #define EVUTIL_ERR_IS_EAGAIN(e) \
120 	((e) == EAGAIN || (e) == EWOULDBLOCK)
121 #endif
122 
123 /* True iff e is an error that means a read/write operation can be retried. */
124 #define EVUTIL_ERR_RW_RETRIABLE(e)				\
125 	((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e))
126 /* True iff e is an error that means an connect can be retried. */
127 #define EVUTIL_ERR_CONNECT_RETRIABLE(e)			\
128 	((e) == EINTR || (e) == EINPROGRESS)
129 /* True iff e is an error that means a accept can be retried. */
130 #define EVUTIL_ERR_ACCEPT_RETRIABLE(e)			\
131 	((e) == EINTR || EVUTIL_ERR_IS_EAGAIN(e) || (e) == ECONNABORTED)
132 
133 /* True iff e is an error that means the connection was refused */
134 #define EVUTIL_ERR_CONNECT_REFUSED(e)					\
135 	((e) == ECONNREFUSED)
136 
137 #else
138 /* Win32 */
139 
140 #define EVUTIL_ERR_IS_EAGAIN(e) \
141 	((e) == WSAEWOULDBLOCK || (e) == EAGAIN)
142 
143 #define EVUTIL_ERR_RW_RETRIABLE(e)					\
144 	((e) == WSAEWOULDBLOCK ||					\
145 	    (e) == WSAEINTR)
146 
147 #define EVUTIL_ERR_CONNECT_RETRIABLE(e)					\
148 	((e) == WSAEWOULDBLOCK ||					\
149 	    (e) == WSAEINTR ||						\
150 	    (e) == WSAEINPROGRESS ||					\
151 	    (e) == WSAEINVAL)
152 
153 #define EVUTIL_ERR_ACCEPT_RETRIABLE(e)			\
154 	EVUTIL_ERR_RW_RETRIABLE(e)
155 
156 #define EVUTIL_ERR_CONNECT_REFUSED(e)					\
157 	((e) == WSAECONNREFUSED)
158 
159 #endif
160 
161 /* Arguments for shutdown() */
162 #ifdef SHUT_RD
163 #define EVUTIL_SHUT_RD SHUT_RD
164 #else
165 #define EVUTIL_SHUT_RD 0
166 #endif
167 #ifdef SHUT_WR
168 #define EVUTIL_SHUT_WR SHUT_WR
169 #else
170 #define EVUTIL_SHUT_WR 1 /* SD_SEND */
171 #endif
172 #ifdef SHUT_BOTH
173 #define EVUTIL_SHUT_BOTH SHUT_BOTH
174 #else
175 #define EVUTIL_SHUT_BOTH 2
176 #endif
177 
178 /* Helper: Verify that all the elements in 'dlist' are internally consistent.
179  * Checks for circular lists and bad prev/next pointers.
180  *
181  * Example usage:
182  *    EVUTIL_ASSERT_LIST_OK(eventlist, event, ev_next);
183  */
184 #define EVUTIL_ASSERT_LIST_OK(dlist, type, field) do {			\
185 		struct type *elm1, *elm2, **nextp;			\
186 		if (LIST_EMPTY((dlist)))				\
187 			break;						\
188 									\
189 		/* Check list for circularity using Floyd's */		\
190 		/* 'Tortoise and Hare' algorithm */			\
191 		elm1 = LIST_FIRST((dlist));				\
192 		elm2 = LIST_NEXT(elm1, field);				\
193 		while (elm1 && elm2) {					\
194 			EVUTIL_ASSERT(elm1 != elm2);			\
195 			elm1 = LIST_NEXT(elm1, field);			\
196 			elm2 = LIST_NEXT(elm2, field);			\
197 			if (!elm2)					\
198 				break;					\
199 			EVUTIL_ASSERT(elm1 != elm2);			\
200 			elm2 = LIST_NEXT(elm2, field);			\
201 		}							\
202 									\
203 		/* Now check next and prev pointers for consistency. */ \
204 		nextp = &LIST_FIRST((dlist));				\
205 		elm1 = LIST_FIRST((dlist));				\
206 		while (elm1) {						\
207 			EVUTIL_ASSERT(*nextp == elm1);			\
208 			EVUTIL_ASSERT(nextp == elm1->field.le_prev);	\
209 			nextp = &LIST_NEXT(elm1, field);		\
210 			elm1 = *nextp;					\
211 		}							\
212 	} while (0)
213 
214 /* Helper: Verify that all the elements in a TAILQ are internally consistent.
215  * Checks for circular lists and bad prev/next pointers.
216  *
217  * Example usage:
218  *    EVUTIL_ASSERT_TAILQ_OK(activelist, event, ev_active_next);
219  */
220 #define EVUTIL_ASSERT_TAILQ_OK(tailq, type, field) do {			\
221 		struct type *elm1, *elm2, **nextp;			\
222 		if (TAILQ_EMPTY((tailq)))				\
223 			break;						\
224 									\
225 		/* Check list for circularity using Floyd's */		\
226 		/* 'Tortoise and Hare' algorithm */			\
227 		elm1 = TAILQ_FIRST((tailq));				\
228 		elm2 = TAILQ_NEXT(elm1, field);				\
229 		while (elm1 && elm2) {					\
230 			EVUTIL_ASSERT(elm1 != elm2);			\
231 			elm1 = TAILQ_NEXT(elm1, field);			\
232 			elm2 = TAILQ_NEXT(elm2, field);			\
233 			if (!elm2)					\
234 				break;					\
235 			EVUTIL_ASSERT(elm1 != elm2);			\
236 			elm2 = TAILQ_NEXT(elm2, field);			\
237 		}							\
238 									\
239 		/* Now check next and prev pointers for consistency. */ \
240 		nextp = &TAILQ_FIRST((tailq));				\
241 		elm1 = TAILQ_FIRST((tailq));				\
242 		while (elm1) {						\
243 			EVUTIL_ASSERT(*nextp == elm1);			\
244 			EVUTIL_ASSERT(nextp == elm1->field.tqe_prev);	\
245 			nextp = &TAILQ_NEXT(elm1, field);		\
246 			elm1 = *nextp;					\
247 		}							\
248 		EVUTIL_ASSERT(nextp == (tailq)->tqh_last);		\
249 	} while (0)
250 
251 /* Locale-independent replacements for some ctypes functions.  Use these
252  * when you care about ASCII's notion of character types, because you are about
253  * to send those types onto the wire.
254  */
255 EVENT2_EXPORT_SYMBOL
256 int EVUTIL_ISALPHA_(char c);
257 EVENT2_EXPORT_SYMBOL
258 int EVUTIL_ISALNUM_(char c);
259 int EVUTIL_ISSPACE_(char c);
260 EVENT2_EXPORT_SYMBOL
261 int EVUTIL_ISDIGIT_(char c);
262 EVENT2_EXPORT_SYMBOL
263 int EVUTIL_ISXDIGIT_(char c);
264 int EVUTIL_ISPRINT_(char c);
265 int EVUTIL_ISLOWER_(char c);
266 int EVUTIL_ISUPPER_(char c);
267 EVENT2_EXPORT_SYMBOL
268 char EVUTIL_TOUPPER_(char c);
269 EVENT2_EXPORT_SYMBOL
270 char EVUTIL_TOLOWER_(char c);
271 
272 /** Remove all trailing horizontal whitespace (space or tab) from the end of a
273  * string */
274 EVENT2_EXPORT_SYMBOL
275 void evutil_rtrim_lws_(char *);
276 
277 
278 /** Helper macro.  If we know that a given pointer points to a field in a
279     structure, return a pointer to the structure itself.  Used to implement
280     our half-baked C OO.  Example:
281 
282     struct subtype {
283 	int x;
284 	struct supertype common;
285 	int y;
286     };
287     ...
288     void fn(struct supertype *super) {
289 	struct subtype *sub = EVUTIL_UPCAST(super, struct subtype, common);
290 	...
291     }
292  */
293 #define EVUTIL_UPCAST(ptr, type, field)				\
294 	((type *)(((char*)(ptr)) - evutil_offsetof(type, field)))
295 
296 /* As open(pathname, flags, mode), except that the file is always opened with
297  * the close-on-exec flag set. (And the mode argument is mandatory.)
298  */
299 int evutil_open_closeonexec_(const char *pathname, int flags, unsigned mode);
300 
301 EVENT2_EXPORT_SYMBOL
302 int evutil_read_file_(const char *filename, char **content_out, size_t *len_out,
303     int is_binary);
304 
305 EVENT2_EXPORT_SYMBOL
306 int evutil_socket_connect_(evutil_socket_t *fd_ptr, const struct sockaddr *sa, int socklen);
307 
308 int evutil_socket_finished_connecting_(evutil_socket_t fd);
309 
310 EVENT2_EXPORT_SYMBOL
311 int evutil_ersatz_socketpair_(int, int , int, evutil_socket_t[]);
312 
313 int evutil_resolve_(int family, const char *hostname, struct sockaddr *sa,
314     ev_socklen_t *socklen, int port);
315 
316 const char *evutil_getenv_(const char *name);
317 
318 /* Structure to hold the state of our weak random number generator.
319  */
320 struct evutil_weakrand_state {
321 	ev_uint32_t seed;
322 };
323 
324 #define EVUTIL_WEAKRAND_MAX EV_INT32_MAX
325 
326 /* Initialize the state of a week random number generator based on 'seed'.  If
327  * the seed is 0, construct a new seed based on not-very-strong platform
328  * entropy, like the PID and the time of day.
329  *
330  * This function, and the other evutil_weakrand* functions, are meant for
331  * speed, not security or statistical strength.  If you need a RNG which an
332  * attacker can't predict, or which passes strong statistical tests, use the
333  * evutil_secure_rng* functions instead.
334  */
335 EVENT2_EXPORT_SYMBOL
336 ev_uint32_t evutil_weakrand_seed_(struct evutil_weakrand_state *state, ev_uint32_t seed);
337 /* Return a pseudorandom value between 0 and EVUTIL_WEAKRAND_MAX inclusive.
338  * Updates the state in 'seed' as needed -- this value must be protected by a
339  * lock.
340  */
341 EVENT2_EXPORT_SYMBOL
342 ev_int32_t evutil_weakrand_(struct evutil_weakrand_state *seed);
343 /* Return a pseudorandom value x such that 0 <= x < top. top must be no more
344  * than EVUTIL_WEAKRAND_MAX. Updates the state in 'seed' as needed -- this
345  * value must be proteced by a lock */
346 EVENT2_EXPORT_SYMBOL
347 ev_int32_t evutil_weakrand_range_(struct evutil_weakrand_state *seed, ev_int32_t top);
348 
349 /* Evaluates to the same boolean value as 'p', and hints to the compiler that
350  * we expect this value to be false. */
351 #if defined(__GNUC__) && __GNUC__ >= 3         /* gcc 3.0 or later */
352 #define EVUTIL_UNLIKELY(p) __builtin_expect(!!(p),0)
353 #else
354 #define EVUTIL_UNLIKELY(p) (p)
355 #endif
356 
357 #if EVUTIL_HAS_ATTRIBUTE(fallthrough)
358 #define EVUTIL_FALLTHROUGH __attribute__((fallthrough))
359 #else
360 #define EVUTIL_FALLTHROUGH /* fallthrough */
361 #endif
362 
363 /* Replacement for assert() that calls event_errx on failure. */
364 #ifdef NDEBUG
365 #define EVUTIL_ASSERT(cond) EVUTIL_NIL_CONDITION_(cond)
366 #define EVUTIL_FAILURE_CHECK(cond) 0
367 #else
368 #define EVUTIL_ASSERT(cond)						\
369 	do {								\
370 		if (EVUTIL_UNLIKELY(!(cond))) {				\
371 			event_errx(EVENT_ERR_ABORT_,			\
372 			    "%s:%d: Assertion %s failed in %s",		\
373 			    __FILE__,__LINE__,#cond,__func__);		\
374 			/* In case a user-supplied handler tries to */	\
375 			/* return control to us, log and abort here. */	\
376 			(void)fprintf(stderr,				\
377 			    "%s:%d: Assertion %s failed in %s",		\
378 			    __FILE__,__LINE__,#cond,__func__);		\
379 			abort();					\
380 		}							\
381 	} while (0)
382 #define EVUTIL_FAILURE_CHECK(cond) EVUTIL_UNLIKELY(cond)
383 #endif
384 
385 #ifndef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE
386 /* Replacement for sockaddr storage that we can use internally on platforms
387  * that lack it.  It is not space-efficient, but neither is sockaddr_storage.
388  */
389 struct sockaddr_storage {
390 	union {
391 		struct sockaddr ss_sa;
392 		struct sockaddr_in ss_sin;
393 		struct sockaddr_in6 ss_sin6;
394 		char ss_padding[128];
395 	} ss_union;
396 };
397 #define ss_family ss_union.ss_sa.sa_family
398 #endif
399 
400 /* Internal addrinfo error code.  This one is returned from only from
401  * evutil_getaddrinfo_common_, when we are sure that we'll have to hit a DNS
402  * server. */
403 #define EVUTIL_EAI_NEED_RESOLVE      -90002
404 
405 struct evdns_base;
406 struct evdns_getaddrinfo_request;
407 typedef struct evdns_getaddrinfo_request* (*evdns_getaddrinfo_fn)(
408     struct evdns_base *base,
409     const char *nodename, const char *servname,
410     const struct evutil_addrinfo *hints_in,
411     void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
412 EVENT2_EXPORT_SYMBOL
413 void evutil_set_evdns_getaddrinfo_fn_(evdns_getaddrinfo_fn fn);
414 typedef void (*evdns_getaddrinfo_cancel_fn)(
415     struct evdns_getaddrinfo_request *req);
416 EVENT2_EXPORT_SYMBOL
417 void evutil_set_evdns_getaddrinfo_cancel_fn_(evdns_getaddrinfo_cancel_fn fn);
418 
419 EVENT2_EXPORT_SYMBOL
420 struct evutil_addrinfo *evutil_new_addrinfo_(struct sockaddr *sa,
421     ev_socklen_t socklen, const struct evutil_addrinfo *hints);
422 EVENT2_EXPORT_SYMBOL
423 struct evutil_addrinfo *evutil_addrinfo_append_(struct evutil_addrinfo *first,
424     struct evutil_addrinfo *append);
425 EVENT2_EXPORT_SYMBOL
426 void evutil_adjust_hints_for_addrconfig_(struct evutil_addrinfo *hints);
427 EVENT2_EXPORT_SYMBOL
428 int evutil_getaddrinfo_common_(const char *nodename, const char *servname,
429     struct evutil_addrinfo *hints, struct evutil_addrinfo **res, int *portnum);
430 
431 struct evdns_getaddrinfo_request *evutil_getaddrinfo_async_(
432     struct evdns_base *dns_base,
433     const char *nodename, const char *servname,
434     const struct evutil_addrinfo *hints_in,
435     void (*cb)(int, struct evutil_addrinfo *, void *), void *arg);
436 void evutil_getaddrinfo_cancel_async_(struct evdns_getaddrinfo_request *data);
437 
438 /** Return true iff sa is a looback address. (That is, it is 127.0.0.1/8, or
439  * ::1). */
440 EVENT2_EXPORT_SYMBOL
441 int evutil_sockaddr_is_loopback_(const struct sockaddr *sa);
442 
443 
444 /**
445     Formats a sockaddr sa into a string buffer of size outlen stored in out.
446     Returns a pointer to out.  Always writes something into out, so it's safe
447     to use the output of this function without checking it for NULL.
448  */
449 EVENT2_EXPORT_SYMBOL
450 const char *evutil_format_sockaddr_port_(const struct sockaddr *sa, char *out, size_t outlen);
451 
452 int evutil_hex_char_to_int_(char c);
453 
454 
455 void evutil_free_secure_rng_globals_(void);
456 void evutil_free_globals_(void);
457 
458 #ifdef _WIN32
459 EVENT2_EXPORT_SYMBOL
460 HMODULE evutil_load_windows_system_library_(const TCHAR *library_name);
461 #endif
462 
463 #ifndef EV_SIZE_FMT
464 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
465 #define EV_U64_FMT "%I64u"
466 #define EV_I64_FMT "%I64d"
467 #define EV_I64_ARG(x) ((__int64)(x))
468 #define EV_U64_ARG(x) ((unsigned __int64)(x))
469 #else
470 #define EV_U64_FMT "%llu"
471 #define EV_I64_FMT "%lld"
472 #define EV_I64_ARG(x) ((long long)(x))
473 #define EV_U64_ARG(x) ((unsigned long long)(x))
474 #endif
475 #endif
476 
477 #ifdef _WIN32
478 #define EV_SOCK_FMT EV_I64_FMT
479 #define EV_SOCK_ARG(x) EV_I64_ARG((x))
480 #else
481 #define EV_SOCK_FMT "%d"
482 #define EV_SOCK_ARG(x) (x)
483 #endif
484 
485 #if defined(__STDC__) && defined(__STDC_VERSION__) && !defined(__MINGW64_VERSION_MAJOR)
486 #if (__STDC_VERSION__ >= 199901L)
487 #define EV_SIZE_FMT "%zu"
488 #define EV_SSIZE_FMT "%zd"
489 #define EV_SIZE_ARG(x) (x)
490 #define EV_SSIZE_ARG(x) (x)
491 #endif
492 #endif
493 
494 #ifndef EV_SIZE_FMT
495 #if (EVENT__SIZEOF_SIZE_T <= EVENT__SIZEOF_LONG)
496 #define EV_SIZE_FMT "%lu"
497 #define EV_SSIZE_FMT "%ld"
498 #define EV_SIZE_ARG(x) ((unsigned long)(x))
499 #define EV_SSIZE_ARG(x) ((long)(x))
500 #else
501 #define EV_SIZE_FMT EV_U64_FMT
502 #define EV_SSIZE_FMT EV_I64_FMT
503 #define EV_SIZE_ARG(x) EV_U64_ARG(x)
504 #define EV_SSIZE_ARG(x) EV_I64_ARG(x)
505 #endif
506 #endif
507 
508 EVENT2_EXPORT_SYMBOL
509 evutil_socket_t evutil_socket_(int domain, int type, int protocol);
510 evutil_socket_t evutil_accept4_(evutil_socket_t sockfd, struct sockaddr *addr,
511     ev_socklen_t *addrlen, int flags);
512 
513     /* used by one of the test programs.. */
514 EVENT2_EXPORT_SYMBOL
515 int evutil_make_internal_pipe_(evutil_socket_t fd[2]);
516 evutil_socket_t evutil_eventfd_(unsigned initval, int flags);
517 
518 #ifdef SOCK_NONBLOCK
519 #define EVUTIL_SOCK_NONBLOCK SOCK_NONBLOCK
520 #else
521 #define EVUTIL_SOCK_NONBLOCK 0x4000000
522 #endif
523 #ifdef SOCK_CLOEXEC
524 #define EVUTIL_SOCK_CLOEXEC SOCK_CLOEXEC
525 #else
526 #define EVUTIL_SOCK_CLOEXEC 0x80000000
527 #endif
528 #ifdef EFD_NONBLOCK
529 #define EVUTIL_EFD_NONBLOCK EFD_NONBLOCK
530 #else
531 #define EVUTIL_EFD_NONBLOCK 0x4000
532 #endif
533 #ifdef EFD_CLOEXEC
534 #define EVUTIL_EFD_CLOEXEC EFD_CLOEXEC
535 #else
536 #define EVUTIL_EFD_CLOEXEC 0x8000
537 #endif
538 
539 void evutil_memclear_(void *mem, size_t len);
540 
541 struct in_addr;
542 struct in6_addr;
543 
544 /* This is a any, loopback, link-local, multicast */
545 EVENT2_EXPORT_SYMBOL
546 int evutil_v4addr_is_local_(const struct in_addr *in);
547 /* This is a reserved, ipv4compat, ipv4map, loopback,
548  * link-local, multicast, or unspecified address. */
549 EVENT2_EXPORT_SYMBOL
550 int evutil_v6addr_is_local_(const struct in6_addr *in);
551 
552 #ifdef __cplusplus
553 }
554 #endif
555 
556 #endif
557