util-internal.h 17 KB

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