root/opal/mca/event/libevent2022/libevent/include/event2/util.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   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_
  27 #define _EVENT2_UTIL_H_
  28 
  29 /** @file event2/util.h
  30 
  31   Common convenience functions for cross-platform portability and
  32   related socket manipulations.
  33 
  34  */
  35 
  36 #ifdef __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 /****    OMPI CHANGE    ****/
  41 #include "opal_rename.h"
  42 /****  END OMPI CHANGE  ****/
  43 
  44 #include <event2/event-config.h>
  45 #ifdef _EVENT_HAVE_SYS_TIME_H
  46 #include <sys/time.h>
  47 #endif
  48 #ifdef _EVENT_HAVE_STDINT_H
  49 #include <stdint.h>
  50 #elif defined(_EVENT_HAVE_INTTYPES_H)
  51 #include <inttypes.h>
  52 #endif
  53 #ifdef _EVENT_HAVE_SYS_TYPES_H
  54 #include <sys/types.h>
  55 #endif
  56 #ifdef _EVENT_HAVE_STDDEF_H
  57 #include <stddef.h>
  58 #endif
  59 #ifdef _MSC_VER
  60 #include <BaseTsd.h>
  61 #endif
  62 #include <stdarg.h>
  63 #ifdef _EVENT_HAVE_NETDB_H
  64 #if !defined(_GNU_SOURCE)
  65 #define _GNU_SOURCE
  66 #endif
  67 #include <netdb.h>
  68 #endif
  69 
  70 #if defined(WIN32) && !defined(__CYGWIN__)
  71 #include <winsock2.h>
  72 #else
  73 #include <sys/socket.h>
  74 #endif
  75 
  76 /* Some openbsd autoconf versions get the name of this macro wrong. */
  77 #if defined(_EVENT_SIZEOF_VOID__) && !defined(_EVENT_SIZEOF_VOID_P)
  78 #define _EVENT_SIZEOF_VOID_P _EVENT_SIZEOF_VOID__
  79 #endif
  80 
  81 /**
  82  * @name Standard integer types.
  83  *
  84  * Integer type definitions for types that are supposed to be defined in the
  85  * C99-specified stdint.h.  Shamefully, some platforms do not include
  86  * stdint.h, so we need to replace it.  (If you are on a platform like this,
  87  * your C headers are now over 10 years out of date.  You should bug them to
  88  * do something about this.)
  89  *
  90  * We define:
  91  *
  92  * <dl>
  93  *   <dt>ev_uint64_t, ev_uint32_t, ev_uint16_t, ev_uint8_t</dt>
  94  *      <dd>unsigned integer types of exactly 64, 32, 16, and 8 bits
  95  *          respectively.</dd>
  96  *    <dt>ev_int64_t, ev_int32_t, ev_int16_t, ev_int8_t</dt>
  97  *      <dd>signed integer types of exactly 64, 32, 16, and 8 bits
  98  *          respectively.</dd>
  99  *    <dt>ev_uintptr_t, ev_intptr_t</dt>
 100  *      <dd>unsigned/signed integers large enough
 101  *      to hold a pointer without loss of bits.</dd>
 102  *    <dt>ev_ssize_t</dt>
 103  *      <dd>A signed type of the same size as size_t</dd>
 104  *    <dt>ev_off_t</dt>
 105  *      <dd>A signed type typically used to represent offsets within a
 106  *      (potentially large) file</dd>
 107  *
 108  * @{
 109  */
 110 #ifdef _EVENT_HAVE_UINT64_T
 111 #define ev_uint64_t uint64_t
 112 #define ev_int64_t int64_t
 113 #elif defined(WIN32)
 114 #define ev_uint64_t unsigned __int64
 115 #define ev_int64_t signed __int64
 116 #elif _EVENT_SIZEOF_LONG_LONG == 8
 117 #define ev_uint64_t unsigned long long
 118 #define ev_int64_t long long
 119 #elif _EVENT_SIZEOF_LONG == 8
 120 #define ev_uint64_t unsigned long
 121 #define ev_int64_t long
 122 #elif defined(_EVENT_IN_DOXYGEN)
 123 #define ev_uint64_t ...
 124 #define ev_int64_t ...
 125 #else
 126 #error "No way to define ev_uint64_t"
 127 #endif
 128 
 129 #ifdef _EVENT_HAVE_UINT32_T
 130 #define ev_uint32_t uint32_t
 131 #define ev_int32_t int32_t
 132 #elif defined(WIN32)
 133 #define ev_uint32_t unsigned int
 134 #define ev_int32_t signed int
 135 #elif _EVENT_SIZEOF_LONG == 4
 136 #define ev_uint32_t unsigned long
 137 #define ev_int32_t signed long
 138 #elif _EVENT_SIZEOF_INT == 4
 139 #define ev_uint32_t unsigned int
 140 #define ev_int32_t signed int
 141 #elif defined(_EVENT_IN_DOXYGEN)
 142 #define ev_uint32_t ...
 143 #define ev_int32_t ...
 144 #else
 145 #error "No way to define ev_uint32_t"
 146 #endif
 147 
 148 #ifdef _EVENT_HAVE_UINT16_T
 149 #define ev_uint16_t uint16_t
 150 #define ev_int16_t  int16_t
 151 #elif defined(WIN32)
 152 #define ev_uint16_t unsigned short
 153 #define ev_int16_t  signed short
 154 #elif _EVENT_SIZEOF_INT == 2
 155 #define ev_uint16_t unsigned int
 156 #define ev_int16_t  signed int
 157 #elif _EVENT_SIZEOF_SHORT == 2
 158 #define ev_uint16_t unsigned short
 159 #define ev_int16_t  signed short
 160 #elif defined(_EVENT_IN_DOXYGEN)
 161 #define ev_uint16_t ...
 162 #define ev_int16_t ...
 163 #else
 164 #error "No way to define ev_uint16_t"
 165 #endif
 166 
 167 #ifdef _EVENT_HAVE_UINT8_T
 168 #define ev_uint8_t uint8_t
 169 #define ev_int8_t int8_t
 170 #elif defined(_EVENT_IN_DOXYGEN)
 171 #define ev_uint8_t ...
 172 #define ev_int8_t ...
 173 #else
 174 #define ev_uint8_t unsigned char
 175 #define ev_int8_t signed char
 176 #endif
 177 
 178 #ifdef _EVENT_HAVE_UINTPTR_T
 179 #define ev_uintptr_t uintptr_t
 180 #define ev_intptr_t intptr_t
 181 #elif _EVENT_SIZEOF_VOID_P <= 4
 182 #define ev_uintptr_t ev_uint32_t
 183 #define ev_intptr_t ev_int32_t
 184 #elif _EVENT_SIZEOF_VOID_P <= 8
 185 #define ev_uintptr_t ev_uint64_t
 186 #define ev_intptr_t ev_int64_t
 187 #elif defined(_EVENT_IN_DOXYGEN)
 188 #define ev_uintptr_t ...
 189 #define ev_intptr_t ...
 190 #else
 191 #error "No way to define ev_uintptr_t"
 192 #endif
 193 
 194 #ifdef _EVENT_ssize_t
 195 #define ev_ssize_t _EVENT_ssize_t
 196 #else
 197 #define ev_ssize_t ssize_t
 198 #endif
 199 
 200 #ifdef WIN32
 201 #define ev_off_t ev_int64_t
 202 #else
 203 #define ev_off_t off_t
 204 #endif
 205 /**@}*/
 206 
 207 /* Limits for integer types.
 208 
 209    We're making two assumptions here:
 210      - The compiler does constant folding properly.
 211      - The platform does signed arithmetic in two's complement.
 212 */
 213 
 214 /**
 215    @name Limits for integer types
 216 
 217    These macros hold the largest or smallest values possible for the
 218    ev_[u]int*_t types.
 219 
 220    @{
 221 */
 222 #define EV_UINT64_MAX ((((ev_uint64_t)0xffffffffUL) << 32) | 0xffffffffUL)
 223 #define EV_INT64_MAX  ((((ev_int64_t) 0x7fffffffL) << 32) | 0xffffffffL)
 224 #define EV_INT64_MIN  ((-EV_INT64_MAX) - 1)
 225 #define EV_UINT32_MAX ((ev_uint32_t)0xffffffffUL)
 226 #define EV_INT32_MAX  ((ev_int32_t) 0x7fffffffL)
 227 #define EV_INT32_MIN  ((-EV_INT32_MAX) - 1)
 228 #define EV_UINT16_MAX ((ev_uint16_t)0xffffUL)
 229 #define EV_INT16_MAX  ((ev_int16_t) 0x7fffL)
 230 #define EV_INT16_MIN  ((-EV_INT16_MAX) - 1)
 231 #define EV_UINT8_MAX  255
 232 #define EV_INT8_MAX   127
 233 #define EV_INT8_MIN   ((-EV_INT8_MAX) - 1)
 234 /** @} */
 235 
 236 /**
 237    @name Limits for SIZE_T and SSIZE_T
 238 
 239    @{
 240 */
 241 #if _EVENT_SIZEOF_SIZE_T == 8
 242 #define EV_SIZE_MAX EV_UINT64_MAX
 243 #define EV_SSIZE_MAX EV_INT64_MAX
 244 #elif _EVENT_SIZEOF_SIZE_T == 4
 245 #define EV_SIZE_MAX EV_UINT32_MAX
 246 #define EV_SSIZE_MAX EV_INT32_MAX
 247 #elif defined(_EVENT_IN_DOXYGEN)
 248 #define EV_SIZE_MAX ...
 249 #define EV_SSIZE_MAX ...
 250 #else
 251 #error "No way to define SIZE_MAX"
 252 #endif
 253 
 254 #define EV_SSIZE_MIN ((-EV_SSIZE_MAX) - 1)
 255 /**@}*/
 256 
 257 #ifdef WIN32
 258 #define ev_socklen_t int
 259 #elif defined(_EVENT_socklen_t)
 260 #define ev_socklen_t _EVENT_socklen_t
 261 #else
 262 #define ev_socklen_t socklen_t
 263 #endif
 264 
 265 #ifdef _EVENT_HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
 266 #if !defined(_EVENT_HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) \
 267  && !defined(ss_family)
 268 #define ss_family __ss_family
 269 #endif
 270 #endif
 271 
 272 /**
 273  * A type wide enough to hold the output of "socket()" or "accept()".  On
 274  * Windows, this is an intptr_t; elsewhere, it is an int. */
 275 #ifdef WIN32
 276 #define evutil_socket_t intptr_t
 277 #else
 278 #define evutil_socket_t int
 279 #endif
 280 
 281 /** Create two new sockets that are connected to each other.
 282 
 283     On Unix, this simply calls socketpair().  On Windows, it uses the
 284     loopback network interface on 127.0.0.1, and only
 285     AF_INET,SOCK_STREAM are supported.
 286 
 287     (This may fail on some Windows hosts where firewall software has cleverly
 288     decided to keep 127.0.0.1 from talking to itself.)
 289 
 290     Parameters and return values are as for socketpair()
 291 */
 292 int evutil_socketpair(int d, int type, int protocol, evutil_socket_t sv[2]);
 293 /** Do platform-specific operations as needed to make a socket nonblocking.
 294 
 295     @param sock The socket to make nonblocking
 296     @return 0 on success, -1 on failure
 297  */
 298 int evutil_make_socket_nonblocking(evutil_socket_t sock);
 299 
 300 /** Do platform-specific operations to make a listener socket reusable.
 301 
 302     Specifically, we want to make sure that another program will be able
 303     to bind this address right after we've closed the listener.
 304 
 305     This differs from Windows's interpretation of "reusable", which
 306     allows multiple listeners to bind the same address at the same time.
 307 
 308     @param sock The socket to make reusable
 309     @return 0 on success, -1 on failure
 310  */
 311 int evutil_make_listen_socket_reuseable(evutil_socket_t sock);
 312 
 313 /** Do platform-specific operations as needed to close a socket upon a
 314     successful execution of one of the exec*() functions.
 315 
 316     @param sock The socket to be closed
 317     @return 0 on success, -1 on failure
 318  */
 319 int evutil_make_socket_closeonexec(evutil_socket_t sock);
 320 
 321 /** Do the platform-specific call needed to close a socket returned from
 322     socket() or accept().
 323 
 324     @param sock The socket to be closed
 325     @return 0 on success, -1 on failure
 326  */
 327 int evutil_closesocket(evutil_socket_t sock);
 328 #define EVUTIL_CLOSESOCKET(s) evutil_closesocket(s)
 329 
 330 
 331 #ifdef WIN32
 332 /** Return the most recent socket error.  Not idempotent on all platforms. */
 333 #define EVUTIL_SOCKET_ERROR() WSAGetLastError()
 334 /** Replace the most recent socket error with errcode */
 335 #define EVUTIL_SET_SOCKET_ERROR(errcode)                \
 336         do { WSASetLastError(errcode); } while (0)
 337 /** Return the most recent socket error to occur on sock. */
 338 int evutil_socket_geterror(evutil_socket_t sock);
 339 /** Convert a socket error to a string. */
 340 const char *evutil_socket_error_to_string(int errcode);
 341 #elif defined(_EVENT_IN_DOXYGEN)
 342 /**
 343    @name Socket error functions
 344 
 345    These functions are needed for making programs compatible between
 346    Windows and Unix-like platforms.
 347 
 348    You see, Winsock handles socket errors differently from the rest of
 349    the world.  Elsewhere, a socket error is like any other error and is
 350    stored in errno.  But winsock functions require you to retrieve the
 351    error with a special function, and don't let you use strerror for
 352    the error codes.  And handling EWOULDBLOCK is ... different.
 353 
 354    @{
 355 */
 356 /** Return the most recent socket error.  Not idempotent on all platforms. */
 357 #define EVUTIL_SOCKET_ERROR() ...
 358 /** Replace the most recent socket error with errcode */
 359 #define EVUTIL_SET_SOCKET_ERROR(errcode) ...
 360 /** Return the most recent socket error to occur on sock. */
 361 #define evutil_socket_geterror(sock) ...
 362 /** Convert a socket error to a string. */
 363 #define evutil_socket_error_to_string(errcode) ...
 364 /**@}*/
 365 #else
 366 #define EVUTIL_SOCKET_ERROR() (errno)
 367 #define EVUTIL_SET_SOCKET_ERROR(errcode)                \
 368                 do { errno = (errcode); } while (0)
 369 #define evutil_socket_geterror(sock) (errno)
 370 #define evutil_socket_error_to_string(errcode) (strerror(errcode))
 371 #endif
 372 
 373 
 374 /**
 375  * @name Manipulation macros for struct timeval.
 376  *
 377  * We define replacements
 378  * for timeradd, timersub, timerclear, timercmp, and timerisset.
 379  *
 380  * @{
 381  */
 382 #ifdef _EVENT_HAVE_TIMERADD
 383 #define evutil_timeradd(tvp, uvp, vvp) timeradd((tvp), (uvp), (vvp))
 384 #define evutil_timersub(tvp, uvp, vvp) timersub((tvp), (uvp), (vvp))
 385 #else
 386 #define evutil_timeradd(tvp, uvp, vvp)                                  \
 387         do {                                                            \
 388                 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;          \
 389                 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;       \
 390                 if ((vvp)->tv_usec >= 1000000) {                        \
 391                         (vvp)->tv_sec++;                                \
 392                         (vvp)->tv_usec -= 1000000;                      \
 393                 }                                                       \
 394         } while (0)
 395 #define evutil_timersub(tvp, uvp, vvp)                                  \
 396         do {                                                            \
 397                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
 398                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
 399                 if ((vvp)->tv_usec < 0) {                               \
 400                         (vvp)->tv_sec--;                                \
 401                         (vvp)->tv_usec += 1000000;                      \
 402                 }                                                       \
 403         } while (0)
 404 #endif /* !_EVENT_HAVE_HAVE_TIMERADD */
 405 
 406 #ifdef _EVENT_HAVE_TIMERCLEAR
 407 #define evutil_timerclear(tvp) timerclear(tvp)
 408 #else
 409 #define evutil_timerclear(tvp)  (tvp)->tv_sec = (tvp)->tv_usec = 0
 410 #endif
 411 /**@}*/
 412 
 413 /** Return true iff the tvp is related to uvp according to the relational
 414  * operator cmp.  Recognized values for cmp are ==, <=, <, >=, and >. */
 415 #define evutil_timercmp(tvp, uvp, cmp)                                  \
 416         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
 417          ((tvp)->tv_usec cmp (uvp)->tv_usec) :                          \
 418          ((tvp)->tv_sec cmp (uvp)->tv_sec))
 419 
 420 #ifdef _EVENT_HAVE_TIMERISSET
 421 #define evutil_timerisset(tvp) timerisset(tvp)
 422 #else
 423 #define evutil_timerisset(tvp)  ((tvp)->tv_sec || (tvp)->tv_usec)
 424 #endif
 425 
 426 /** Replacement for offsetof on platforms that don't define it. */
 427 #ifdef offsetof
 428 #define evutil_offsetof(type, field) offsetof(type, field)
 429 #else
 430 #define evutil_offsetof(type, field) ((off_t)(&((type *)0)->field))
 431 #endif
 432 
 433 /* big-int related functions */
 434 /** Parse a 64-bit value from a string.  Arguments are as for strtol. */
 435 ev_int64_t evutil_strtoll(const char *s, char **endptr, int base);
 436 
 437 /** Replacement for gettimeofday on platforms that lack it. */
 438 #ifdef _EVENT_HAVE_GETTIMEOFDAY
 439 #define evutil_gettimeofday(tv, tz) gettimeofday((tv), (tz))
 440 #else
 441 struct timezone;
 442 int evutil_gettimeofday(struct timeval *tv, struct timezone *tz);
 443 #endif
 444 
 445 /** Replacement for snprintf to get consistent behavior on platforms for
 446     which the return value of snprintf does not conform to C99.
 447  */
 448 int evutil_snprintf(char *buf, size_t buflen, const char *format, ...)
 449 #ifdef __GNUC__
 450         __attribute__((format(printf, 3, 4)))
 451 #endif
 452 ;
 453 /** Replacement for vsnprintf to get consistent behavior on platforms for
 454     which the return value of snprintf does not conform to C99.
 455  */
 456 int evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
 457 #ifdef __GNUC__
 458         __attribute__((format(printf, 3, 0)))
 459 #endif
 460 ;
 461 
 462 /** Replacement for inet_ntop for platforms which lack it. */
 463 const char *evutil_inet_ntop(int af, const void *src, char *dst, size_t len);
 464 /** Replacement for inet_pton for platforms which lack it. */
 465 int evutil_inet_pton(int af, const char *src, void *dst);
 466 struct sockaddr;
 467 
 468 /** Parse an IPv4 or IPv6 address, with optional port, from a string.
 469 
 470     Recognized formats are:
 471     - [IPv6Address]:port
 472     - [IPv6Address]
 473     - IPv6Address
 474     - IPv4Address:port
 475     - IPv4Address
 476 
 477     If no port is specified, the port in the output is set to 0.
 478 
 479     @param str The string to parse.
 480     @param out A struct sockaddr to hold the result.  This should probably be
 481        a struct sockaddr_storage.
 482     @param outlen A pointer to the number of bytes that that 'out' can safely
 483        hold.  Set to the number of bytes used in 'out' on success.
 484     @return -1 if the address is not well-formed, if the port is out of range,
 485        or if out is not large enough to hold the result.  Otherwise returns
 486        0 on success.
 487 */
 488 int evutil_parse_sockaddr_port(const char *str, struct sockaddr *out, int *outlen);
 489 
 490 /** Compare two sockaddrs; return 0 if they are equal, or less than 0 if sa1
 491  * preceeds sa2, or greater than 0 if sa1 follows sa2.  If include_port is
 492  * true, consider the port as well as the address.  Only implemented for
 493  * AF_INET and AF_INET6 addresses. The ordering is not guaranteed to remain
 494  * the same between Libevent versions. */
 495 int evutil_sockaddr_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2,
 496     int include_port);
 497 
 498 /** As strcasecmp, but always compares the characters in locale-independent
 499     ASCII.  That's useful if you're handling data in ASCII-based protocols.
 500  */
 501 int evutil_ascii_strcasecmp(const char *str1, const char *str2);
 502 /** As strncasecmp, but always compares the characters in locale-independent
 503     ASCII.  That's useful if you're handling data in ASCII-based protocols.
 504  */
 505 int evutil_ascii_strncasecmp(const char *str1, const char *str2, size_t n);
 506 
 507 /* Here we define evutil_addrinfo to the native addrinfo type, or redefine it
 508  * if this system has no getaddrinfo(). */
 509 #ifdef _EVENT_HAVE_STRUCT_ADDRINFO
 510 #define evutil_addrinfo addrinfo
 511 #else
 512 /** A definition of struct addrinfo for systems that lack it.
 513 
 514     (This is just an alias for struct addrinfo if the system defines
 515     struct addrinfo.)
 516 */
 517 struct evutil_addrinfo {
 518         int     ai_flags;     /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
 519         int     ai_family;    /* PF_xxx */
 520         int     ai_socktype;  /* SOCK_xxx */
 521         int     ai_protocol;  /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
 522         size_t  ai_addrlen;   /* length of ai_addr */
 523         char   *ai_canonname; /* canonical name for nodename */
 524         struct sockaddr  *ai_addr; /* binary address */
 525         struct evutil_addrinfo  *ai_next; /* next structure in linked list */
 526 };
 527 #endif
 528 /** @name evutil_getaddrinfo() error codes
 529 
 530     These values are possible error codes for evutil_getaddrinfo() and
 531     related functions.
 532 
 533     @{
 534 */
 535 #ifdef EAI_ADDRFAMILY
 536 #define EVUTIL_EAI_ADDRFAMILY EAI_ADDRFAMILY
 537 #else
 538 #define EVUTIL_EAI_ADDRFAMILY -901
 539 #endif
 540 #ifdef EAI_AGAIN
 541 #define EVUTIL_EAI_AGAIN EAI_AGAIN
 542 #else
 543 #define EVUTIL_EAI_AGAIN -902
 544 #endif
 545 #ifdef EAI_BADFLAGS
 546 #define EVUTIL_EAI_BADFLAGS EAI_BADFLAGS
 547 #else
 548 #define EVUTIL_EAI_BADFLAGS -903
 549 #endif
 550 #ifdef EAI_FAIL
 551 #define EVUTIL_EAI_FAIL EAI_FAIL
 552 #else
 553 #define EVUTIL_EAI_FAIL -904
 554 #endif
 555 #ifdef EAI_FAMILY
 556 #define EVUTIL_EAI_FAMILY EAI_FAMILY
 557 #else
 558 #define EVUTIL_EAI_FAMILY -905
 559 #endif
 560 #ifdef EAI_MEMORY
 561 #define EVUTIL_EAI_MEMORY EAI_MEMORY
 562 #else
 563 #define EVUTIL_EAI_MEMORY -906
 564 #endif
 565 /* This test is a bit complicated, since some MS SDKs decide to
 566  * remove NODATA or redefine it to be the same as NONAME, in a
 567  * fun interpretation of RFC 2553 and RFC 3493. */
 568 #if defined(EAI_NODATA) && (!defined(EAI_NONAME) || EAI_NODATA != EAI_NONAME)
 569 #define EVUTIL_EAI_NODATA EAI_NODATA
 570 #else
 571 #define EVUTIL_EAI_NODATA -907
 572 #endif
 573 #ifdef EAI_NONAME
 574 #define EVUTIL_EAI_NONAME EAI_NONAME
 575 #else
 576 #define EVUTIL_EAI_NONAME -908
 577 #endif
 578 #ifdef EAI_SERVICE
 579 #define EVUTIL_EAI_SERVICE EAI_SERVICE
 580 #else
 581 #define EVUTIL_EAI_SERVICE -909
 582 #endif
 583 #ifdef EAI_SOCKTYPE
 584 #define EVUTIL_EAI_SOCKTYPE EAI_SOCKTYPE
 585 #else
 586 #define EVUTIL_EAI_SOCKTYPE -910
 587 #endif
 588 #ifdef EAI_SYSTEM
 589 #define EVUTIL_EAI_SYSTEM EAI_SYSTEM
 590 #else
 591 #define EVUTIL_EAI_SYSTEM -911
 592 #endif
 593 
 594 #define EVUTIL_EAI_CANCEL -90001
 595 
 596 #ifdef AI_PASSIVE
 597 #define EVUTIL_AI_PASSIVE AI_PASSIVE
 598 #else
 599 #define EVUTIL_AI_PASSIVE 0x1000
 600 #endif
 601 #ifdef AI_CANONNAME
 602 #define EVUTIL_AI_CANONNAME AI_CANONNAME
 603 #else
 604 #define EVUTIL_AI_CANONNAME 0x2000
 605 #endif
 606 #ifdef AI_NUMERICHOST
 607 #define EVUTIL_AI_NUMERICHOST AI_NUMERICHOST
 608 #else
 609 #define EVUTIL_AI_NUMERICHOST 0x4000
 610 #endif
 611 #ifdef AI_NUMERICSERV
 612 #define EVUTIL_AI_NUMERICSERV AI_NUMERICSERV
 613 #else
 614 #define EVUTIL_AI_NUMERICSERV 0x8000
 615 #endif
 616 #ifdef AI_V4MAPPED
 617 #define EVUTIL_AI_V4MAPPED AI_V4MAPPED
 618 #else
 619 #define EVUTIL_AI_V4MAPPED 0x10000
 620 #endif
 621 #ifdef AI_ALL
 622 #define EVUTIL_AI_ALL AI_ALL
 623 #else
 624 #define EVUTIL_AI_ALL 0x20000
 625 #endif
 626 #ifdef AI_ADDRCONFIG
 627 #define EVUTIL_AI_ADDRCONFIG AI_ADDRCONFIG
 628 #else
 629 #define EVUTIL_AI_ADDRCONFIG 0x40000
 630 #endif
 631 /**@}*/
 632 
 633 struct evutil_addrinfo;
 634 /**
 635  * This function clones getaddrinfo for systems that don't have it.  For full
 636  * details, see RFC 3493, section 6.1.
 637  *
 638  * Limitations:
 639  * - When the system has no getaddrinfo, we fall back to gethostbyname_r or
 640  *   gethostbyname, with their attendant issues.
 641  * - The AI_V4MAPPED and AI_ALL flags are not currently implemented.
 642  *
 643  * For a nonblocking variant, see evdns_getaddrinfo.
 644  */
 645 int evutil_getaddrinfo(const char *nodename, const char *servname,
 646     const struct evutil_addrinfo *hints_in, struct evutil_addrinfo **res);
 647 
 648 /** Release storage allocated by evutil_getaddrinfo or evdns_getaddrinfo. */
 649 void evutil_freeaddrinfo(struct evutil_addrinfo *ai);
 650 
 651 const char *evutil_gai_strerror(int err);
 652 
 653 /** Generate n bytes of secure pseudorandom data, and store them in buf.
 654  *
 655  * By default, Libevent uses an ARC4-based random number generator, seeded
 656  * using the platform's entropy source (/dev/urandom on Unix-like systems;
 657  * CryptGenRandom on Windows).
 658  */
 659 void evutil_secure_rng_get_bytes(void *buf, size_t n);
 660 
 661 /**
 662  * Seed the secure random number generator if needed, and return 0 on
 663  * success or -1 on failure.
 664  *
 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
 667  * seeded.
 668  *
 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.
 676  */
 677 int evutil_secure_rng_init(void);
 678 
 679 /****     OMPI CHANGE     *****/
 680 /* Unused by OPAL and cannot support on OpenBSD.
 681  * See https://svn.open-mpi.org/trac/ompi/ticket/4829
 682  */
 683 #if 0
 684 /** Seed the random number generator with extra random bytes.
 685 
 686     You should almost never need to call this function; it should be
 687     sufficient to invoke evutil_secure_rng_init(), or let Libevent take
 688     care of calling evutil_secure_rng_init() on its own.
 689 
 690     If you call this function as a _replacement_ for the regular
 691     entropy sources, then you need to be sure that your input
 692     contains a fairly large amount of strong entropy.  Doing so is
 693     notoriously hard: most people who try get it wrong.  Watch out!
 694 
 695     @param dat a buffer full of a strong source of random numbers
 696     @param datlen the number of bytes to read from datlen
 697  */
 698 void evutil_secure_rng_add_bytes(const char *dat, size_t datlen);
 699 #endif
 700 
 701 #ifdef __cplusplus
 702 }
 703 #endif
 704 
 705 #endif /* _EVUTIL_H_ */

/* [<][>][^][v][top][bottom][index][help] */