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