12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include <config.h>
- #include <dlfcn.h>
- #include <assert.h>
- #include <errno.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <unistd.h>
- #include <libhostile/initialize.h>
- __thread bool is_in_getaddrinfo= 0;
- static int not_until= 500;
- static struct function_st __function;
- static pthread_once_t function_lookup_once = PTHREAD_ONCE_INIT;
- static void set_local(void)
- {
- __function= set_function("getaddrinfo", "HOSTILE_GETADDRINFO");
- }
- bool is_getaddrinfo(void)
- {
- return is_in_getaddrinfo;
- }
- int getaddrinfo(const char *node, const char *service,
- const struct addrinfo *hints,
- struct addrinfo **res)
- {
- hostile_initialize();
- (void) pthread_once(&function_lookup_once, set_local);
- if (__function.frequency)
- {
- if (--not_until < 0 && random() % __function.frequency)
- {
- #if 0
- perror("HOSTILE CLOSE() of socket during getaddrinfo()");
- #endif
- return EAI_FAIL;
- }
- }
- is_in_getaddrinfo= true;
- int ret= __function.function.getaddrinfo(node, service, hints, res);
- is_in_getaddrinfo= false;
- return ret;
- }
|