libevent  2.2.1
Event notification library
util.h
Go to the documentation of this file.
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 EVENT2_UTIL_H_INCLUDED_
27 #define EVENT2_UTIL_H_INCLUDED_
28 
35 #include <event2/visibility.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <event2/event-config.h>
42 #ifdef EVENT__HAVE_SYS_TIME_H
43 #include <sys/time.h>
44 #endif
45 #ifdef EVENT__HAVE_STDINT_H
46 #include <stdint.h>
47 #elif defined(EVENT__HAVE_INTTYPES_H)
48 #include <inttypes.h>
49 #endif
50 #ifdef EVENT__HAVE_SYS_TYPES_H
51 #include <sys/types.h>
52 #endif
53 #ifdef EVENT__HAVE_STDDEF_H
54 #include <stddef.h>
55 #endif
56 #ifdef _MSC_VER
57 #include <BaseTsd.h>
58 #endif
59 #include <stdarg.h>
60 #ifdef EVENT__HAVE_NETDB_H
61 #include <netdb.h>
62 #endif
63 
64 #ifdef _WIN32
65 #include <winsock2.h>
66 #ifdef EVENT__HAVE_GETADDRINFO
67 /* for EAI_* definitions. */
68 #include <ws2tcpip.h>
69 #endif
70 #else
71 #ifdef EVENT__HAVE_ERRNO_H
72 #include <errno.h>
73 #endif
74 #include <sys/socket.h>
75 #endif
76 
77 #include <time.h>
78 
79 #ifdef __sun
80 #ifdef SO_FLOW_NAME
81 /* Since it's impossible to detect the Solaris 11.4 version via OS macros,
82  * so we check the presence of the socket option SO_FLOW_NAME that was first
83  * introduced to Solaris 11.4 and define a custom macro for determining 11.4.
84  *
85  * Note that this might be a false positive if the code is compiled on a system
86  * but run on another system with an older version of Solaris.
87  */
88 #define EVENT__SOLARIS_11_4 (1)
89 #else
90 #define EVENT__SOLARIS_11_4 (0)
91 #endif
92 #endif
93 
94 /* Some openbsd autoconf versions get the name of this macro wrong. */
95 #if defined(EVENT__SIZEOF_VOID__) && !defined(EVENT__SIZEOF_VOID_P)
96 #define EVENT__SIZEOF_VOID_P EVENT__SIZEOF_VOID__
97 #endif
98 
128 #ifdef EVENT__HAVE_UINT64_T
129 #define ev_uint64_t uint64_t
130 #define ev_int64_t int64_t
131 #elif defined(_WIN32)
132 #define ev_uint64_t unsigned __int64
133 #define ev_int64_t signed __int64
134 #elif EVENT__SIZEOF_LONG_LONG == 8
135 #define ev_uint64_t unsigned long long
136 #define ev_int64_t long long
137 #elif EVENT__SIZEOF_LONG == 8
138 #define ev_uint64_t unsigned long
139 #define ev_int64_t long
140 #elif defined(EVENT_IN_DOXYGEN_)
141 #define ev_uint64_t ...
142 #define ev_int64_t ...
143 #else
144 #error "No way to define ev_uint64_t"
145 #endif
146 
147 #ifdef EVENT__HAVE_UINT32_T
148 #define ev_uint32_t uint32_t
149 #define ev_int32_t int32_t
150 #elif defined(_WIN32)
151 #define ev_uint32_t unsigned int
152 #define ev_int32_t signed int
153 #elif EVENT__SIZEOF_LONG == 4
154 #define ev_uint32_t unsigned long
155 #define ev_int32_t signed long
156 #elif EVENT__SIZEOF_INT == 4
157 #define ev_uint32_t unsigned int
158 #define ev_int32_t signed int
159 #elif defined(EVENT_IN_DOXYGEN_)
160 #define ev_uint32_t ...
161 #define ev_int32_t ...
162 #else
163 #error "No way to define ev_uint32_t"
164 #endif
165 
166 #ifdef EVENT__HAVE_UINT16_T
167 #define ev_uint16_t uint16_t
168 #define ev_int16_t int16_t
169 #elif defined(_WIN32)
170 #define ev_uint16_t unsigned short
171 #define ev_int16_t signed short
172 #elif EVENT__SIZEOF_INT == 2
173 #define ev_uint16_t unsigned int
174 #define ev_int16_t signed int
175 #elif EVENT__SIZEOF_SHORT == 2
176 #define ev_uint16_t unsigned short
177 #define ev_int16_t signed short
178 #elif defined(EVENT_IN_DOXYGEN_)
179 #define ev_uint16_t ...
180 #define ev_int16_t ...
181 #else
182 #error "No way to define ev_uint16_t"
183 #endif
184 
185 #ifdef EVENT__HAVE_UINT8_T
186 #define ev_uint8_t uint8_t
187 #define ev_int8_t int8_t
188 #elif defined(EVENT_IN_DOXYGEN_)
189 #define ev_uint8_t ...
190 #define ev_int8_t ...
191 #else
192 #define ev_uint8_t unsigned char
193 #define ev_int8_t signed char
194 #endif
195 
196 #ifdef EVENT__HAVE_UINTPTR_T
197 #define ev_uintptr_t uintptr_t
198 #define ev_intptr_t intptr_t
199 #elif EVENT__SIZEOF_VOID_P <= 4
200 #define ev_uintptr_t ev_uint32_t
201 #define ev_intptr_t ev_int32_t
202 #elif EVENT__SIZEOF_VOID_P <= 8
203 #define ev_uintptr_t ev_uint64_t
204 #define ev_intptr_t ev_int64_t
205 #elif defined(EVENT_IN_DOXYGEN_)
206 #define ev_uintptr_t ...
207 #define ev_intptr_t ...
208 #else
209 #error "No way to define ev_uintptr_t"
210 #endif
211 
212 #ifdef EVENT__ssize_t
213 #define ev_ssize_t EVENT__ssize_t
214 #else
215 #define ev_ssize_t ssize_t
216 #endif
217 
218 /* Note that we define ev_off_t based on the compile-time size of off_t that
219  * we used to build Libevent, and not based on the current size of off_t.
220  * (For example, we don't define ev_off_t to off_t.). We do this because
221  * some systems let you build your software with different off_t sizes
222  * at runtime, and so putting in any dependency on off_t would risk API
223  * mismatch.
224  */
225 #ifdef _WIN32
226 #define ev_off_t ev_int64_t
227 #elif EVENT__SIZEOF_OFF_T == 8
228 #define ev_off_t ev_int64_t
229 #elif EVENT__SIZEOF_OFF_T == 4
230 #define ev_off_t ev_int32_t
231 #elif defined(EVENT_IN_DOXYGEN_)
232 #define ev_off_t ...
233 #else
234 #define ev_off_t off_t
235 #endif
236 
238 /* Limits for integer types.
239 
240  We're making two assumptions here:
241  - The compiler does constant folding properly.
242  - The platform does signed arithmetic in two's complement.
243 */
244 
253 #ifndef EVENT__HAVE_STDINT_H
254 #define EV_UINT64_MAX ((((ev_uint64_t)0xffffffffUL) << 32) | 0xffffffffUL)
255 #define EV_INT64_MAX ((((ev_int64_t) 0x7fffffffL) << 32) | 0xffffffffL)
256 #define EV_INT64_MIN ((-EV_INT64_MAX) - 1)
257 #define EV_UINT32_MAX ((ev_uint32_t)0xffffffffUL)
258 #define EV_INT32_MAX ((ev_int32_t) 0x7fffffffL)
259 #define EV_INT32_MIN ((-EV_INT32_MAX) - 1)
260 #define EV_UINT16_MAX ((ev_uint16_t)0xffffUL)
261 #define EV_INT16_MAX ((ev_int16_t) 0x7fffL)
262 #define EV_INT16_MIN ((-EV_INT16_MAX) - 1)
263 #define EV_UINT8_MAX 255
264 #define EV_INT8_MAX 127
265 #define EV_INT8_MIN ((-EV_INT8_MAX) - 1)
266 #else
267 #define EV_UINT64_MAX UINT64_MAX
268 #define EV_INT64_MAX INT64_MAX
269 #define EV_INT64_MIN INT64_MIN
270 #define EV_UINT32_MAX UINT32_MAX
271 #define EV_INT32_MAX INT32_MAX
272 #define EV_INT32_MIN INT32_MIN
273 #define EV_UINT16_MAX UINT16_MAX
274 #define EV_INT16_MIN INT16_MIN
275 #define EV_INT16_MAX INT16_MAX
276 #define EV_UINT8_MAX UINT8_MAX
277 #define EV_INT8_MAX INT8_MAX
278 #define EV_INT8_MIN INT8_MIN
279 
280 #endif
281 
282 
288 #if EVENT__SIZEOF_SIZE_T == 8
289 #define EV_SIZE_MAX EV_UINT64_MAX
290 #define EV_SSIZE_MAX EV_INT64_MAX
291 #elif EVENT__SIZEOF_SIZE_T == 4
292 #define EV_SIZE_MAX EV_UINT32_MAX
293 #define EV_SSIZE_MAX EV_INT32_MAX
294 #elif defined(EVENT_IN_DOXYGEN_)
295 #define EV_SIZE_MAX ...
296 #define EV_SSIZE_MAX ...
297 #else
298 #error "No way to define SIZE_MAX"
299 #endif
300 
301 #define EV_SSIZE_MIN ((-EV_SSIZE_MAX) - 1)
302 
304 #ifdef _WIN32
305 #define ev_socklen_t int
306 #elif defined(EVENT__socklen_t)
307 #define ev_socklen_t EVENT__socklen_t
308 #else
309 #define ev_socklen_t socklen_t
310 #endif
311 
312 #ifdef EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
313 #if !defined(EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) \
314  && !defined(ss_family)
315 #define ss_family __ss_family
316 #endif
317 #endif
318 
322 #ifdef _WIN32
323 #define evutil_socket_t intptr_t
324 #else
325 #define evutil_socket_t int
326 #endif
327 
341 #ifdef EVENT_IN_DOXYGEN_
342 {/*Empty body so that doxygen will generate documentation here.*/}
343 #endif
344 ;
345 
346 #define EV_MONOT_PRECISE 1
347 #define EV_MONOT_FALLBACK 2
348 
355 EVENT2_EXPORT_SYMBOL int
356 evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm);
357 
363 EVENT2_EXPORT_SYMBOL
365 
369 EVENT2_EXPORT_SYMBOL
371 
375 EVENT2_EXPORT_SYMBOL
377  int flags);
378 
389 EVENT2_EXPORT_SYMBOL
391  struct timeval *tp);
392 
409 EVENT2_EXPORT_SYMBOL
410 int evutil_socketpair(int domain, int type, int protocol, evutil_socket_t sv[2]);
416 EVENT2_EXPORT_SYMBOL
418 
430 EVENT2_EXPORT_SYMBOL
432 
446 EVENT2_EXPORT_SYMBOL
448 
460 EVENT2_EXPORT_SYMBOL
462 
474 EVENT2_EXPORT_SYMBOL
476 
483 EVENT2_EXPORT_SYMBOL
485 
493 EVENT2_EXPORT_SYMBOL
495 #define EVUTIL_CLOSESOCKET(s) evutil_closesocket(s)
496 
508 EVENT2_EXPORT_SYMBOL
510 
520 EVENT2_EXPORT_SYMBOL
521 int evutil_set_tcp_keepalive(evutil_socket_t sock, int on, int timeout);
522 
523 #ifdef _WIN32
524 
525 #define EVUTIL_SOCKET_ERROR() WSAGetLastError()
526 
527 #define EVUTIL_SET_SOCKET_ERROR(errcode) \
528  do { WSASetLastError(errcode); } while (0)
529 
530 EVENT2_EXPORT_SYMBOL
533 EVENT2_EXPORT_SYMBOL
534 const char *evutil_socket_error_to_string(int errcode);
535 #define EVUTIL_INVALID_SOCKET INVALID_SOCKET
536 #elif defined(EVENT_IN_DOXYGEN_)
537 
552 #define EVUTIL_SOCKET_ERROR() ...
553 
554 #define EVUTIL_SET_SOCKET_ERROR(errcode) ...
555 
556 #define evutil_socket_geterror(sock) ...
557 
558 #define evutil_socket_error_to_string(errcode) ...
559 #define EVUTIL_INVALID_SOCKET -1
560 
561 #else /* !EVENT_IN_DOXYGEN_ && !_WIN32 */
562 #define EVUTIL_SOCKET_ERROR() (errno)
563 #define EVUTIL_SET_SOCKET_ERROR(errcode) \
564  do { errno = (errcode); } while (0)
565 #define evutil_socket_geterror(sock) (errno)
566 #define evutil_socket_error_to_string(errcode) (strerror(errcode))
567 #define EVUTIL_INVALID_SOCKET -1
568 #endif /* !_WIN32 */
569 
570 
579 #ifdef EVENT__HAVE_TIMERADD
580 #define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp))
581 #define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp))
582 #else
583 #define evutil_timeradd(tvp, uvp, vvp) \
584  do { \
585  (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
586  (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
587  if ((vvp)->tv_usec >= 1000000) { \
588  (vvp)->tv_sec++; \
589  (vvp)->tv_usec -= 1000000; \
590  } \
591  } while (0)
592 #define evutil_timersub(tvp, uvp, vvp) \
593  do { \
594  (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
595  (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
596  if ((vvp)->tv_usec < 0) { \
597  (vvp)->tv_sec--; \
598  (vvp)->tv_usec += 1000000; \
599  } \
600  } while (0)
601 #endif /* !EVENT__HAVE_TIMERADD */
602 
603 #ifdef EVENT__HAVE_TIMERCLEAR
604 #define evutil_timerclear(tvp) timerclear(tvp)
605 #else
606 #define evutil_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
607 #endif
608 
612 #define evutil_timercmp(tvp, uvp, cmp) \
613  (((tvp)->tv_sec == (uvp)->tv_sec) ? \
614  ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
615  ((tvp)->tv_sec cmp (uvp)->tv_sec))
616 
617 #ifdef EVENT__HAVE_TIMERISSET
618 #define evutil_timerisset(tvp) timerisset(tvp)
619 #else
620 #define evutil_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
621 #endif
622 
624 #ifdef offsetof
625 #define evutil_offsetof(type, field) offsetof(type, field)
626 #else
627 #define evutil_offsetof(type, field) ((off_t)(&((type *)0)->field))
628 #endif
629 
630 /* big-int related functions */
632 EVENT2_EXPORT_SYMBOL
633 ev_int64_t evutil_strtoll(const char *s, char **endptr, int base);
634 
636 #ifdef EVENT__HAVE_GETTIMEOFDAY
637 #define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz))
638 #else
639 struct timezone;
640 EVENT2_EXPORT_SYMBOL
641 int evutil_gettimeofday(struct timeval *tv, struct timezone *tz);
642 #endif
643 
647 EVENT2_EXPORT_SYMBOL
648 int evutil_snprintf(char *buf, size_t buflen, const char *format, ...)
649 #ifdef __GNUC__
650  __attribute__((format(printf, 3, 4)))
651 #endif
652 ;
656 EVENT2_EXPORT_SYMBOL
657 int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
658 #ifdef __GNUC__
659  __attribute__((format(printf, 3, 0)))
660 #endif
661 ;
662 
664 EVENT2_EXPORT_SYMBOL
665 const char *evutil_inet_ntop(int af, const void *src, char *dst, size_t len);
669 EVENT2_EXPORT_SYMBOL
670 int evutil_inet_pton_scope(int af, const char *src, void *dst,
671  unsigned *indexp);
673 EVENT2_EXPORT_SYMBOL
674 int evutil_inet_pton(int af, const char *src, void *dst);
675 struct sockaddr;
676 
697 EVENT2_EXPORT_SYMBOL
698 int evutil_parse_sockaddr_port(const char *str, struct sockaddr *out, int *outlen);
699 
705 EVENT2_EXPORT_SYMBOL
706 int evutil_sockaddr_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2,
707  int include_port);
708 
713 EVENT2_EXPORT_SYMBOL
714 int evutil_ascii_strcasecmp(const char *str1, const char *str2);
718 EVENT2_EXPORT_SYMBOL
719 int evutil_ascii_strncasecmp(const char *str1, const char *str2, size_t n);
720 
721 /* Here we define evutil_addrinfo to the native addrinfo type, or redefine it
722  * if this system has no getaddrinfo(). */
723 #ifdef EVENT__HAVE_STRUCT_ADDRINFO
724 #define evutil_addrinfo addrinfo
725 #else
726 
732  int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
733  int ai_family; /* PF_xxx */
734  int ai_socktype; /* SOCK_xxx */
735  int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
736  size_t ai_addrlen; /* length of ai_addr */
737  char *ai_canonname; /* canonical name for nodename */
738  struct sockaddr *ai_addr; /* binary address */
739  struct evutil_addrinfo *ai_next; /* next structure in linked list */
740 };
741 #endif
742 
749 #if defined(EAI_ADDRFAMILY) && defined(EVENT__HAVE_GETADDRINFO)
750 #define EVUTIL_EAI_ADDRFAMILY EAI_ADDRFAMILY
751 #else
752 #define EVUTIL_EAI_ADDRFAMILY -901
753 #endif
754 #if defined(EAI_AGAIN) && defined(EVENT__HAVE_GETADDRINFO)
755 #define EVUTIL_EAI_AGAIN EAI_AGAIN
756 #else
757 #define EVUTIL_EAI_AGAIN -902
758 #endif
759 #if defined(EAI_BADFLAGS) && defined(EVENT__HAVE_GETADDRINFO)
760 #define EVUTIL_EAI_BADFLAGS EAI_BADFLAGS
761 #else
762 #define EVUTIL_EAI_BADFLAGS -903
763 #endif
764 #if defined(EAI_FAIL) && defined(EVENT__HAVE_GETADDRINFO)
765 #define EVUTIL_EAI_FAIL EAI_FAIL
766 #else
767 #define EVUTIL_EAI_FAIL -904
768 #endif
769 #if defined(EAI_FAMILY) && defined(EVENT__HAVE_GETADDRINFO)
770 #define EVUTIL_EAI_FAMILY EAI_FAMILY
771 #else
772 #define EVUTIL_EAI_FAMILY -905
773 #endif
774 #if defined(EAI_MEMORY) && defined(EVENT__HAVE_GETADDRINFO)
775 #define EVUTIL_EAI_MEMORY EAI_MEMORY
776 #else
777 #define EVUTIL_EAI_MEMORY -906
778 #endif
779 /* This test is a bit complicated, since some MS SDKs decide to
780  * remove NODATA or redefine it to be the same as NONAME, in a
781  * fun interpretation of RFC 2553 and RFC 3493. */
782 #if defined(EAI_NODATA) && defined(EVENT__HAVE_GETADDRINFO) && (!defined(EAI_NONAME) || EAI_NODATA != EAI_NONAME)
783 #define EVUTIL_EAI_NODATA EAI_NODATA
784 #else
785 #define EVUTIL_EAI_NODATA -907
786 #endif
787 #if defined(EAI_NONAME) && defined(EVENT__HAVE_GETADDRINFO)
788 #define EVUTIL_EAI_NONAME EAI_NONAME
789 #else
790 #define EVUTIL_EAI_NONAME -908
791 #endif
792 #if defined(EAI_SERVICE) && defined(EVENT__HAVE_GETADDRINFO)
793 #define EVUTIL_EAI_SERVICE EAI_SERVICE
794 #else
795 #define EVUTIL_EAI_SERVICE -909
796 #endif
797 #if defined(EAI_SOCKTYPE) && defined(EVENT__HAVE_GETADDRINFO)
798 #define EVUTIL_EAI_SOCKTYPE EAI_SOCKTYPE
799 #else
800 #define EVUTIL_EAI_SOCKTYPE -910
801 #endif
802 #if defined(EAI_SYSTEM) && defined(EVENT__HAVE_GETADDRINFO)
803 #define EVUTIL_EAI_SYSTEM EAI_SYSTEM
804 #else
805 #define EVUTIL_EAI_SYSTEM -911
806 #endif
807 
808 #define EVUTIL_EAI_CANCEL -90001
809 
810 #if defined(AI_PASSIVE) && defined(EVENT__HAVE_GETADDRINFO)
811 #define EVUTIL_AI_PASSIVE AI_PASSIVE
812 #else
813 #define EVUTIL_AI_PASSIVE 0x1000
814 #endif
815 #if defined(AI_CANONNAME) && defined(EVENT__HAVE_GETADDRINFO)
816 #define EVUTIL_AI_CANONNAME AI_CANONNAME
817 #else
818 #define EVUTIL_AI_CANONNAME 0x2000
819 #endif
820 #if defined(AI_NUMERICHOST) && defined(EVENT__HAVE_GETADDRINFO)
821 #define EVUTIL_AI_NUMERICHOST AI_NUMERICHOST
822 #else
823 #define EVUTIL_AI_NUMERICHOST 0x4000
824 #endif
825 #if defined(AI_NUMERICSERV) && defined(EVENT__HAVE_GETADDRINFO)
826 #define EVUTIL_AI_NUMERICSERV AI_NUMERICSERV
827 #else
828 #define EVUTIL_AI_NUMERICSERV 0x8000
829 #endif
830 #if defined(AI_V4MAPPED) && defined(EVENT__HAVE_GETADDRINFO)
831 #define EVUTIL_AI_V4MAPPED AI_V4MAPPED
832 #else
833 #define EVUTIL_AI_V4MAPPED 0x10000
834 #endif
835 #if defined(AI_ALL) && defined(EVENT__HAVE_GETADDRINFO)
836 #define EVUTIL_AI_ALL AI_ALL
837 #else
838 #define EVUTIL_AI_ALL 0x20000
839 #endif
840 #if defined(AI_ADDRCONFIG) && defined(EVENT__HAVE_GETADDRINFO)
841 #define EVUTIL_AI_ADDRCONFIG AI_ADDRCONFIG
842 #else
843 #define EVUTIL_AI_ADDRCONFIG 0x40000
844 #endif
845 
847 struct evutil_addrinfo;
859 EVENT2_EXPORT_SYMBOL
860 int evutil_getaddrinfo(const char *nodename, const char *servname,
861  const struct evutil_addrinfo *hints_in, struct evutil_addrinfo **res);
862 
864 EVENT2_EXPORT_SYMBOL
865 void evutil_freeaddrinfo(struct evutil_addrinfo *ai);
866 
867 EVENT2_EXPORT_SYMBOL
868 const char *evutil_gai_strerror(int err);
869 
879 EVENT2_EXPORT_SYMBOL
880 void evutil_secure_rng_get_bytes(void *buf, size_t n);
881 
898 EVENT2_EXPORT_SYMBOL
899 int evutil_secure_rng_init(void);
900 
914 EVENT2_EXPORT_SYMBOL
916 
934 EVENT2_EXPORT_SYMBOL
935 void evutil_secure_rng_add_bytes(const char *dat, size_t datlen);
936 
937 #ifdef __cplusplus
938 }
939 #endif
940 
941 #endif /* EVENT1_EVUTIL_H_INCLUDED_ */
evutil_monotonic_timer
Structure to hold information about a monotonic timer.
Definition: util.h:340
evutil_inet_pton
EVENT2_EXPORT_SYMBOL int evutil_inet_pton(int af, const char *src, void *dst)
Replacement for inet_pton for platforms which lack it.
evutil_date_rfc1123
EVENT2_EXPORT_SYMBOL int evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm)
Format a date string using RFC 1123 format (used in HTTP).
evutil_gettime_monotonic
EVENT2_EXPORT_SYMBOL int evutil_gettime_monotonic(struct evutil_monotonic_timer *timer, struct timeval *tp)
Query the current monotonic time from a struct evutil_monotonic_timer previously configured with evut...
evutil_set_tcp_keepalive
EVENT2_EXPORT_SYMBOL int evutil_set_tcp_keepalive(evutil_socket_t sock, int on, int timeout)
Do platform-specific operations to set/unset TCP keep-alive options TCP_KEEPIDLE, TCP_KEEPINTVL and T...
evutil_ascii_strcasecmp
EVENT2_EXPORT_SYMBOL int evutil_ascii_strcasecmp(const char *str1, const char *str2)
As strcasecmp, but always compares the characters in locale-independent ASCII.
evutil_make_listen_socket_ipv6only
EVENT2_EXPORT_SYMBOL int evutil_make_listen_socket_ipv6only(evutil_socket_t sock)
Set ipv6 only bind socket option to make listener work only in ipv6 sockets.
evutil_getaddrinfo
EVENT2_EXPORT_SYMBOL int evutil_getaddrinfo(const char *nodename, const char *servname, const struct evutil_addrinfo *hints_in, struct evutil_addrinfo **res)
This function clones getaddrinfo for systems that don't have it.
evutil_ascii_strncasecmp
EVENT2_EXPORT_SYMBOL int evutil_ascii_strncasecmp(const char *str1, const char *str2, size_t n)
As strncasecmp, but always compares the characters in locale-independent ASCII.
evutil_make_socket_nonblocking
EVENT2_EXPORT_SYMBOL int evutil_make_socket_nonblocking(evutil_socket_t sock)
Do platform-specific operations as needed to make a socket nonblocking.
evutil_secure_rng_init
EVENT2_EXPORT_SYMBOL int evutil_secure_rng_init(void)
Seed the secure random number generator if needed, and return 0 on success or -1 on failure.
evutil_parse_sockaddr_port
EVENT2_EXPORT_SYMBOL int evutil_parse_sockaddr_port(const char *str, struct sockaddr *out, int *outlen)
Parse an IPv4 or IPv6 address, with optional port, from a string.
evutil_secure_rng_set_urandom_device_file
EVENT2_EXPORT_SYMBOL int evutil_secure_rng_set_urandom_device_file(char *fname)
Set a filename to use in place of /dev/urandom for seeding the secure PRNG.
evutil_socket_error_to_string
#define evutil_socket_error_to_string(errcode)
Convert a socket error to a string.
Definition: util.h:558
evutil_inet_ntop
const EVENT2_EXPORT_SYMBOL char * evutil_inet_ntop(int af, const void *src, char *dst, size_t len)
Replacement for inet_ntop for platforms which lack it.
evutil_socket_geterror
#define evutil_socket_geterror(sock)
Return the most recent socket error to occur on sock.
Definition: util.h:556
evutil_snprintf
EVENT2_EXPORT_SYMBOL int evutil_snprintf(char *buf, size_t buflen, const char *format,...)
Replacement for snprintf to get consistent behavior on platforms for which the return value of snprin...
evutil_make_listen_socket_not_ipv6only
EVENT2_EXPORT_SYMBOL int evutil_make_listen_socket_not_ipv6only(evutil_socket_t sock)
Set ipv6 only bind socket option to make listener work in both ipv4 and ipv6 sockets.
evutil_make_socket_closeonexec
EVENT2_EXPORT_SYMBOL int evutil_make_socket_closeonexec(evutil_socket_t sock)
Do platform-specific operations as needed to close a socket upon a successful execution of one of the...
evutil_configure_monotonic_time
EVENT2_EXPORT_SYMBOL int evutil_configure_monotonic_time(struct evutil_monotonic_timer *timer, int flags)
Set up a struct evutil_monotonic_timer; flags can include EV_MONOT_PRECISE and EV_MONOT_FALLBACK.
evutil_socketpair
EVENT2_EXPORT_SYMBOL int evutil_socketpair(int domain, int type, int protocol, evutil_socket_t sv[2])
Create two new sockets that are connected to each other.
evutil_freeaddrinfo
EVENT2_EXPORT_SYMBOL void evutil_freeaddrinfo(struct evutil_addrinfo *ai)
Release storage allocated by evutil_getaddrinfo or evdns_getaddrinfo.
evutil_monotonic_timer_new
EVENT2_EXPORT_SYMBOL struct evutil_monotonic_timer * evutil_monotonic_timer_new(void)
Allocate a new struct evutil_monotonic_timer for use with the evutil_configure_monotonic_time() and e...
evutil_inet_pton_scope
EVENT2_EXPORT_SYMBOL int evutil_inet_pton_scope(int af, const char *src, void *dst, unsigned *indexp)
Variation of inet_pton that also parses IPv6 scopes.
evutil_strtoll
EVENT2_EXPORT_SYMBOL ev_int64_t evutil_strtoll(const char *s, char **endptr, int base)
Parse a 64-bit value from a string.
evutil_make_tcp_listen_socket_deferred
EVENT2_EXPORT_SYMBOL int evutil_make_tcp_listen_socket_deferred(evutil_socket_t sock)
Do platform-specific operations, if possible, to make a tcp listener socket defer accept()s until the...
evutil_secure_rng_add_bytes
EVENT2_EXPORT_SYMBOL void evutil_secure_rng_add_bytes(const char *dat, size_t datlen)
Seed the random number generator with extra random bytes.
evutil_sockaddr_cmp
EVENT2_EXPORT_SYMBOL int evutil_sockaddr_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2, int include_port)
Compare two sockaddrs; return 0 if they are equal, or less than 0 if sa1 preceeds sa2,...
evutil_closesocket
EVENT2_EXPORT_SYMBOL int evutil_closesocket(evutil_socket_t sock)
Do the platform-specific call needed to close a socket returned from socket() or accept().
evutil_monotonic_timer_free
EVENT2_EXPORT_SYMBOL void evutil_monotonic_timer_free(struct evutil_monotonic_timer *timer)
Free a struct evutil_monotonic_timer that was allocated using evutil_monotonic_timer_new().
evutil_addrinfo
A definition of struct addrinfo for systems that lack it.
Definition: util.h:731
evutil_make_listen_socket_reuseable_port
EVENT2_EXPORT_SYMBOL int evutil_make_listen_socket_reuseable_port(evutil_socket_t sock)
Do platform-specific operations to make a listener port reusable.
evutil_make_listen_socket_reuseable
EVENT2_EXPORT_SYMBOL int evutil_make_listen_socket_reuseable(evutil_socket_t sock)
Do platform-specific operations to make a listener socket reusable.
evutil_vsnprintf
EVENT2_EXPORT_SYMBOL int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
Replacement for vsnprintf to get consistent behavior on platforms for which the return value of snpri...
evutil_secure_rng_get_bytes
EVENT2_EXPORT_SYMBOL void evutil_secure_rng_get_bytes(void *buf, size_t n)
Generate n bytes of secure pseudorandom data, and store them in buf.
evutil_socket_t
#define evutil_socket_t
A type wide enough to hold the output of "socket()" or "accept()".
Definition: util.h:325