1 /* $NetBSD: util.h,v 1.3 2015/01/29 07:26:02 spz Exp $ */
3 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef _EVENT2_UTIL_H_
28 #define _EVENT2_UTIL_H_
30 /** @file event2/util.h
32 Common convenience functions for cross-platform portability and
33 related socket manipulations.
41 #include <event2/event-config.h>
42 #ifdef _EVENT_HAVE_SYS_TIME_H
45 #ifdef _EVENT_HAVE_STDINT_H
47 #elif defined(_EVENT_HAVE_INTTYPES_H)
50 #ifdef _EVENT_HAVE_SYS_TYPES_H
51 #include <sys/types.h>
53 #ifdef _EVENT_HAVE_STDDEF_H
60 #ifdef _EVENT_HAVE_NETDB_H
61 #if !defined(_GNU_SOURCE)
70 #include <sys/socket.h>
73 /* Some openbsd autoconf versions get the name of this macro wrong. */
74 #if defined(_EVENT_SIZEOF_VOID__) && !defined(_EVENT_SIZEOF_VOID_P)
75 #define _EVENT_SIZEOF_VOID_P _EVENT_SIZEOF_VOID__
79 * @name Standard integer types.
81 * Integer type definitions for types that are supposed to be defined in the
82 * C99-specified stdint.h. Shamefully, some platforms do not include
83 * stdint.h, so we need to replace it. (If you are on a platform like this,
84 * your C headers are now over 10 years out of date. You should bug them to
85 * do something about this.)
90 * <dt>ev_uint64_t, ev_uint32_t, ev_uint16_t, ev_uint8_t</dt>
91 * <dd>unsigned integer types of exactly 64, 32, 16, and 8 bits
93 * <dt>ev_int64_t, ev_int32_t, ev_int16_t, ev_int8_t</dt>
94 * <dd>signed integer types of exactly 64, 32, 16, and 8 bits
96 * <dt>ev_uintptr_t, ev_intptr_t</dt>
97 * <dd>unsigned/signed integers large enough
98 * to hold a pointer without loss of bits.</dd>
100 * <dd>A signed type of the same size as size_t</dd>
102 * <dd>A signed type typically used to represent offsets within a
103 * (potentially large) file</dd>
107 #ifdef _EVENT_HAVE_UINT64_T
108 #define ev_uint64_t uint64_t
109 #define ev_int64_t int64_t
111 #define ev_uint64_t unsigned __int64
112 #define ev_int64_t signed __int64
113 #elif _EVENT_SIZEOF_LONG_LONG == 8
114 #define ev_uint64_t unsigned long long
115 #define ev_int64_t long long
116 #elif _EVENT_SIZEOF_LONG == 8
117 #define ev_uint64_t unsigned long
118 #define ev_int64_t long
119 #elif defined(_EVENT_IN_DOXYGEN)
120 #define ev_uint64_t ...
121 #define ev_int64_t ...
123 #error "No way to define ev_uint64_t"
126 #ifdef _EVENT_HAVE_UINT32_T
127 #define ev_uint32_t uint32_t
128 #define ev_int32_t int32_t
130 #define ev_uint32_t unsigned int
131 #define ev_int32_t signed int
132 #elif _EVENT_SIZEOF_LONG == 4
133 #define ev_uint32_t unsigned long
134 #define ev_int32_t signed long
135 #elif _EVENT_SIZEOF_INT == 4
136 #define ev_uint32_t unsigned int
137 #define ev_int32_t signed int
138 #elif defined(_EVENT_IN_DOXYGEN)
139 #define ev_uint32_t ...
140 #define ev_int32_t ...
142 #error "No way to define ev_uint32_t"
145 #ifdef _EVENT_HAVE_UINT16_T
146 #define ev_uint16_t uint16_t
147 #define ev_int16_t int16_t
149 #define ev_uint16_t unsigned short
150 #define ev_int16_t signed short
151 #elif _EVENT_SIZEOF_INT == 2
152 #define ev_uint16_t unsigned int
153 #define ev_int16_t signed int
154 #elif _EVENT_SIZEOF_SHORT == 2
155 #define ev_uint16_t unsigned short
156 #define ev_int16_t signed short
157 #elif defined(_EVENT_IN_DOXYGEN)
158 #define ev_uint16_t ...
159 #define ev_int16_t ...
161 #error "No way to define ev_uint16_t"
164 #ifdef _EVENT_HAVE_UINT8_T
165 #define ev_uint8_t uint8_t
166 #define ev_int8_t int8_t
167 #elif defined(_EVENT_IN_DOXYGEN)
168 #define ev_uint8_t ...
169 #define ev_int8_t ...
171 #define ev_uint8_t unsigned char
172 #define ev_int8_t signed char
175 #ifdef _EVENT_HAVE_UINTPTR_T
176 #define ev_uintptr_t uintptr_t
177 #define ev_intptr_t intptr_t
178 #elif _EVENT_SIZEOF_VOID_P <= 4
179 #define ev_uintptr_t ev_uint32_t
180 #define ev_intptr_t ev_int32_t
181 #elif _EVENT_SIZEOF_VOID_P <= 8
182 #define ev_uintptr_t ev_uint64_t
183 #define ev_intptr_t ev_int64_t
184 #elif defined(_EVENT_IN_DOXYGEN)
185 #define ev_uintptr_t ...
186 #define ev_intptr_t ...
188 #error "No way to define ev_uintptr_t"
191 #ifdef _EVENT_ssize_t
192 #define ev_ssize_t _EVENT_ssize_t
194 #define ev_ssize_t ssize_t
198 #define ev_off_t ev_int64_t
200 #define ev_off_t off_t
204 /* Limits for integer types.
206 We're making two assumptions here:
207 - The compiler does constant folding properly.
208 - The platform does signed arithmetic in two's complement.
212 @name Limits for integer types
214 These macros hold the largest or smallest values possible for the
219 #define EV_UINT64_MAX ((((ev_uint64_t)0xffffffffUL) << 32) | 0xffffffffUL)
220 #define EV_INT64_MAX ((((ev_int64_t) 0x7fffffffL) << 32) | 0xffffffffL)
221 #define EV_INT64_MIN ((-EV_INT64_MAX) - 1)
222 #define EV_UINT32_MAX ((ev_uint32_t)0xffffffffUL)
223 #define EV_INT32_MAX ((ev_int32_t) 0x7fffffffL)
224 #define EV_INT32_MIN ((-EV_INT32_MAX) - 1)
225 #define EV_UINT16_MAX ((ev_uint16_t)0xffffUL)
226 #define EV_INT16_MAX ((ev_int16_t) 0x7fffL)
227 #define EV_INT16_MIN ((-EV_INT16_MAX) - 1)
228 #define EV_UINT8_MAX 255
229 #define EV_INT8_MAX 127
230 #define EV_INT8_MIN ((-EV_INT8_MAX) - 1)
234 @name Limits for SIZE_T and SSIZE_T
238 #if _EVENT_SIZEOF_SIZE_T == 8
239 #define EV_SIZE_MAX EV_UINT64_MAX
240 #define EV_SSIZE_MAX EV_INT64_MAX
241 #elif _EVENT_SIZEOF_SIZE_T == 4
242 #define EV_SIZE_MAX EV_UINT32_MAX
243 #define EV_SSIZE_MAX EV_INT32_MAX
244 #elif defined(_EVENT_IN_DOXYGEN)
245 #define EV_SIZE_MAX ...
246 #define EV_SSIZE_MAX ...
248 #error "No way to define SIZE_MAX"
251 #define EV_SSIZE_MIN ((-EV_SSIZE_MAX) - 1)
255 #define ev_socklen_t int
256 #elif defined(_EVENT_socklen_t)
257 #define ev_socklen_t _EVENT_socklen_t
259 #define ev_socklen_t socklen_t
262 #ifdef _EVENT_HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
263 #if !defined(_EVENT_HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) \
264 && !defined(ss_family)
265 #define ss_family __ss_family
270 * A type wide enough to hold the output of "socket()" or "accept()". On
271 * Windows, this is an intptr_t; elsewhere, it is an int. */
273 #define evutil_socket_t intptr_t
275 #define evutil_socket_t int
278 /** Create two new sockets that are connected to each other.
280 On Unix, this simply calls socketpair(). On Windows, it uses the
281 loopback network interface on 127.0.0.1, and only
282 AF_INET,SOCK_STREAM are supported.
284 (This may fail on some Windows hosts where firewall software has cleverly
285 decided to keep 127.0.0.1 from talking to itself.)
287 Parameters and return values are as for socketpair()
289 int evutil_socketpair(int d
, int type
, int protocol
, evutil_socket_t sv
[2]);
290 /** Do platform-specific operations as needed to make a socket nonblocking.
292 @param sock The socket to make nonblocking
293 @return 0 on success, -1 on failure
295 int evutil_make_socket_nonblocking(evutil_socket_t sock
);
297 /** Do platform-specific operations to make a listener socket reusable.
299 Specifically, we want to make sure that another program will be able
300 to bind this address right after we've closed the listener.
302 This differs from Windows's interpretation of "reusable", which
303 allows multiple listeners to bind the same address at the same time.
305 @param sock The socket to make reusable
306 @return 0 on success, -1 on failure
308 int evutil_make_listen_socket_reuseable(evutil_socket_t sock
);
310 /** Do platform-specific operations as needed to close a socket upon a
311 successful execution of one of the exec*() functions.
313 @param sock The socket to be closed
314 @return 0 on success, -1 on failure
316 int evutil_make_socket_closeonexec(evutil_socket_t sock
);
318 /** Do the platform-specific call needed to close a socket returned from
319 socket() or accept().
321 @param sock The socket to be closed
322 @return 0 on success, -1 on failure
324 int evutil_closesocket(evutil_socket_t sock
);
325 #define EVUTIL_CLOSESOCKET(s) evutil_closesocket(s)
329 /** Return the most recent socket error. Not idempotent on all platforms. */
330 #define EVUTIL_SOCKET_ERROR() WSAGetLastError()
331 /** Replace the most recent socket error with errcode */
332 #define EVUTIL_SET_SOCKET_ERROR(errcode) \
333 do { WSASetLastError(errcode); } while (0)
334 /** Return the most recent socket error to occur on sock. */
335 int evutil_socket_geterror(evutil_socket_t sock
);
336 /** Convert a socket error to a string. */
337 const char *evutil_socket_error_to_string(int errcode
);
338 #elif defined(_EVENT_IN_DOXYGEN)
340 @name Socket error functions
342 These functions are needed for making programs compatible between
343 Windows and Unix-like platforms.
345 You see, Winsock handles socket errors differently from the rest of
346 the world. Elsewhere, a socket error is like any other error and is
347 stored in errno. But winsock functions require you to retrieve the
348 error with a special function, and don't let you use strerror for
349 the error codes. And handling EWOULDBLOCK is ... different.
353 /** Return the most recent socket error. Not idempotent on all platforms. */
354 #define EVUTIL_SOCKET_ERROR() ...
355 /** Replace the most recent socket error with errcode */
356 #define EVUTIL_SET_SOCKET_ERROR(errcode) ...
357 /** Return the most recent socket error to occur on sock. */
358 #define evutil_socket_geterror(sock) ...
359 /** Convert a socket error to a string. */
360 #define evutil_socket_error_to_string(errcode) ...
363 #define EVUTIL_SOCKET_ERROR() (errno)
364 #define EVUTIL_SET_SOCKET_ERROR(errcode) \
365 do { errno = (errcode); } while (0)
366 #define evutil_socket_geterror(sock) (errno)
367 #define evutil_socket_error_to_string(errcode) (strerror(errcode))
372 * @name Manipulation macros for struct timeval.
374 * We define replacements
375 * for timeradd, timersub, timerclear, timercmp, and timerisset.
379 #ifdef _EVENT_HAVE_TIMERADD
380 #define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp))
381 #define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp))
383 #define evutil_timeradd(tvp, uvp, vvp) \
385 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
386 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
387 if ((vvp)->tv_usec >= 1000000) { \
389 (vvp)->tv_usec -= 1000000; \
392 #define evutil_timersub(tvp, uvp, vvp) \
394 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
395 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
396 if ((vvp)->tv_usec < 0) { \
398 (vvp)->tv_usec += 1000000; \
401 #endif /* !_EVENT_HAVE_HAVE_TIMERADD */
403 #ifdef _EVENT_HAVE_TIMERCLEAR
404 #define evutil_timerclear(tvp) timerclear(tvp)
406 #define evutil_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
410 /** Return true iff the tvp is related to uvp according to the relational
411 * operator cmp. Recognized values for cmp are ==, <=, <, >=, and >. */
412 #define evutil_timercmp(tvp, uvp, cmp) \
413 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
414 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
415 ((tvp)->tv_sec cmp (uvp)->tv_sec))
417 #ifdef _EVENT_HAVE_TIMERISSET
418 #define evutil_timerisset(tvp) timerisset(tvp)
420 #define evutil_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
423 /** Replacement for offsetof on platforms that don't define it. */
425 #define evutil_offsetof(type, field) offsetof(type, field)
427 #define evutil_offsetof(type, field) ((off_t)(&((type *)0)->field))
430 /* big-int related functions */
431 /** Parse a 64-bit value from a string. Arguments are as for strtol. */
432 ev_int64_t
evutil_strtoll(const char *s
, char **endptr
, int base
);
434 /** Replacement for gettimeofday on platforms that lack it. */
435 #ifdef _EVENT_HAVE_GETTIMEOFDAY
436 #define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz))
439 int evutil_gettimeofday(struct timeval
*tv
, struct timezone
*tz
);
442 /** Replacement for snprintf to get consistent behavior on platforms for
443 which the return value of snprintf does not conform to C99.
445 int evutil_snprintf(char *buf
, size_t buflen
, const char *format
, ...)
447 __attribute__((format(printf
, 3, 4)))
450 /** Replacement for vsnprintf to get consistent behavior on platforms for
451 which the return value of snprintf does not conform to C99.
453 int evutil_vsnprintf(char *buf
, size_t buflen
, const char *format
, va_list ap
)
455 __attribute__((format(printf
, 3, 0)))
459 /** Replacement for inet_ntop for platforms which lack it. */
460 const char *evutil_inet_ntop(int af
, const void *src
, char *dst
, size_t len
);
461 /** Replacement for inet_pton for platforms which lack it. */
462 int evutil_inet_pton(int af
, const char *src
, void *dst
);
465 /** Parse an IPv4 or IPv6 address, with optional port, from a string.
467 Recognized formats are:
474 If no port is specified, the port in the output is set to 0.
476 @param str The string to parse.
477 @param out A struct sockaddr to hold the result. This should probably be
478 a struct sockaddr_storage.
479 @param outlen A pointer to the number of bytes that that 'out' can safely
480 hold. Set to the number of bytes used in 'out' on success.
481 @return -1 if the address is not well-formed, if the port is out of range,
482 or if out is not large enough to hold the result. Otherwise returns
485 int evutil_parse_sockaddr_port(const char *str
, struct sockaddr
*out
, int *outlen
);
487 /** Compare two sockaddrs; return 0 if they are equal, or less than 0 if sa1
488 * preceeds sa2, or greater than 0 if sa1 follows sa2. If include_port is
489 * true, consider the port as well as the address. Only implemented for
490 * AF_INET and AF_INET6 addresses. The ordering is not guaranteed to remain
491 * the same between Libevent versions. */
492 int evutil_sockaddr_cmp(const struct sockaddr
*sa1
, const struct sockaddr
*sa2
,
495 /** As strcasecmp, but always compares the characters in locale-independent
496 ASCII. That's useful if you're handling data in ASCII-based protocols.
498 int evutil_ascii_strcasecmp(const char *str1
, const char *str2
);
499 /** As strncasecmp, but always compares the characters in locale-independent
500 ASCII. That's useful if you're handling data in ASCII-based protocols.
502 int evutil_ascii_strncasecmp(const char *str1
, const char *str2
, size_t n
);
504 /* Here we define evutil_addrinfo to the native addrinfo type, or redefine it
505 * if this system has no getaddrinfo(). */
506 #ifdef _EVENT_HAVE_STRUCT_ADDRINFO
507 #define evutil_addrinfo addrinfo
509 /** A definition of struct addrinfo for systems that lack it.
511 (This is just an alias for struct addrinfo if the system defines
514 struct evutil_addrinfo
{
515 int ai_flags
; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
516 int ai_family
; /* PF_xxx */
517 int ai_socktype
; /* SOCK_xxx */
518 int ai_protocol
; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
519 size_t ai_addrlen
; /* length of ai_addr */
520 char *ai_canonname
; /* canonical name for nodename */
521 struct sockaddr
*ai_addr
; /* binary address */
522 struct evutil_addrinfo
*ai_next
; /* next structure in linked list */
525 /** @name evutil_getaddrinfo() error codes
527 These values are possible error codes for evutil_getaddrinfo() and
532 #ifdef EAI_ADDRFAMILY
533 #define EVUTIL_EAI_ADDRFAMILY EAI_ADDRFAMILY
535 #define EVUTIL_EAI_ADDRFAMILY -901
538 #define EVUTIL_EAI_AGAIN EAI_AGAIN
540 #define EVUTIL_EAI_AGAIN -902
543 #define EVUTIL_EAI_BADFLAGS EAI_BADFLAGS
545 #define EVUTIL_EAI_BADFLAGS -903
548 #define EVUTIL_EAI_FAIL EAI_FAIL
550 #define EVUTIL_EAI_FAIL -904
553 #define EVUTIL_EAI_FAMILY EAI_FAMILY
555 #define EVUTIL_EAI_FAMILY -905
558 #define EVUTIL_EAI_MEMORY EAI_MEMORY
560 #define EVUTIL_EAI_MEMORY -906
562 /* This test is a bit complicated, since some MS SDKs decide to
563 * remove NODATA or redefine it to be the same as NONAME, in a
564 * fun interpretation of RFC 2553 and RFC 3493. */
565 #if defined(EAI_NODATA) && (!defined(EAI_NONAME) || EAI_NODATA != EAI_NONAME)
566 #define EVUTIL_EAI_NODATA EAI_NODATA
568 #define EVUTIL_EAI_NODATA -907
571 #define EVUTIL_EAI_NONAME EAI_NONAME
573 #define EVUTIL_EAI_NONAME -908
576 #define EVUTIL_EAI_SERVICE EAI_SERVICE
578 #define EVUTIL_EAI_SERVICE -909
581 #define EVUTIL_EAI_SOCKTYPE EAI_SOCKTYPE
583 #define EVUTIL_EAI_SOCKTYPE -910
586 #define EVUTIL_EAI_SYSTEM EAI_SYSTEM
588 #define EVUTIL_EAI_SYSTEM -911
591 #define EVUTIL_EAI_CANCEL -90001
594 #define EVUTIL_AI_PASSIVE AI_PASSIVE
596 #define EVUTIL_AI_PASSIVE 0x1000
599 #define EVUTIL_AI_CANONNAME AI_CANONNAME
601 #define EVUTIL_AI_CANONNAME 0x2000
603 #ifdef AI_NUMERICHOST
604 #define EVUTIL_AI_NUMERICHOST AI_NUMERICHOST
606 #define EVUTIL_AI_NUMERICHOST 0x4000
608 #ifdef AI_NUMERICSERV
609 #define EVUTIL_AI_NUMERICSERV AI_NUMERICSERV
611 #define EVUTIL_AI_NUMERICSERV 0x8000
614 #define EVUTIL_AI_V4MAPPED AI_V4MAPPED
616 #define EVUTIL_AI_V4MAPPED 0x10000
619 #define EVUTIL_AI_ALL AI_ALL
621 #define EVUTIL_AI_ALL 0x20000
624 #define EVUTIL_AI_ADDRCONFIG AI_ADDRCONFIG
626 #define EVUTIL_AI_ADDRCONFIG 0x40000
630 struct evutil_addrinfo
;
632 * This function clones getaddrinfo for systems that don't have it. For full
633 * details, see RFC 3493, section 6.1.
636 * - When the system has no getaddrinfo, we fall back to gethostbyname_r or
637 * gethostbyname, with their attendant issues.
638 * - The AI_V4MAPPED and AI_ALL flags are not currently implemented.
640 * For a nonblocking variant, see evdns_getaddrinfo.
642 int evutil_getaddrinfo(const char *nodename
, const char *servname
,
643 const struct evutil_addrinfo
*hints_in
, struct evutil_addrinfo
**res
);
645 /** Release storage allocated by evutil_getaddrinfo or evdns_getaddrinfo. */
646 void evutil_freeaddrinfo(struct evutil_addrinfo
*ai
);
648 const char *evutil_gai_strerror(int err
);
650 /** Generate n bytes of secure pseudorandom data, and store them in buf.
652 * Current versions of Libevent use an ARC4-based random number generator,
653 * seeded using the platform's entropy source (/dev/urandom on Unix-like
654 * systems; CryptGenRandom on Windows). This is not actually as secure as it
655 * should be: ARC4 is a pretty lousy cipher, and the current implementation
656 * provides only rudimentary prediction- and backtracking-resistance. Don't
657 * use this for serious cryptographic applications.
659 void evutil_secure_rng_get_bytes(void *buf
, size_t n
);
662 * Seed the secure random number generator if needed, and return 0 on
663 * success or -1 on failure.
665 * It is okay to call this function more than once; it will still return
666 * 0 if the RNG has been successfully seeded and -1 if it can't be
669 * Ordinarily you don't need to call this function from your own code;
670 * Libevent will seed the RNG itself the first time it needs good random
671 * numbers. You only need to call it if (a) you want to double-check
672 * that one of the seeding methods did succeed, or (b) you plan to drop
673 * the capability to seed (by chrooting, or dropping capabilities, or
674 * whatever), and you want to make sure that seeding happens before your
675 * program loses the ability to do it.
677 int evutil_secure_rng_init(void);
680 * Set a filename to use in place of /dev/urandom for seeding the secure
681 * PRNG. Return 0 on success, -1 on failure.
683 * Call this function BEFORE calling any other initialization or RNG
686 * (This string will _NOT_ be copied internally. Do not free it while any
687 * user of the secure RNG might be running. Don't pass anything other than a
688 * real /dev/...random device file here, or you might lose security.)
690 * This API is unstable, and might change in a future libevent version.
692 int evutil_secure_rng_set_urandom_device_file(char *fname
);
694 /** Seed the random number generator with extra random bytes.
696 You should almost never need to call this function; it should be
697 sufficient to invoke evutil_secure_rng_init(), or let Libevent take
698 care of calling evutil_secure_rng_init() on its own.
700 If you call this function as a _replacement_ for the regular
701 entropy sources, then you need to be sure that your input
702 contains a fairly large amount of strong entropy. Doing so is
703 notoriously hard: most people who try get it wrong. Watch out!
705 @param dat a buffer full of a strong source of random numbers
706 @param datlen the number of bytes to read from datlen
708 void evutil_secure_rng_add_bytes(const char *dat
, size_t datlen
);
714 #endif /* _EVUTIL_H_ */