18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
19 |
# include <config.h> |
# include <config.h> |
20 |
#endif |
#endif |
|
#include <pthread.h> |
|
21 |
#include <netdb.h> |
#include <netdb.h> |
22 |
#include <string.h> |
#include <string.h> |
23 |
|
|
24 |
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
LOCK_DECLARE(lock) |
25 |
|
|
26 |
static int |
static int |
27 |
store_hostent(h_in, h_out, buf, buflen, h_errnop) |
store_hostent(h_in, h_out, buf, buflen, h_errnop) |
104 |
{ |
{ |
105 |
struct hostent *host; |
struct hostent *host; |
106 |
|
|
107 |
pthread_cleanup_push((void (*)(void*))pthread_mutex_unlock, &mutex); |
LOCK_SET(lock) |
|
pthread_mutex_lock(&mutex); |
|
108 |
host = gethostbyname(name); |
host = gethostbyname(name); |
109 |
if (!host || store_hostent(host, result, buffer, buflen, h_errnop)) |
if (!host || store_hostent(host, result, buffer, buflen, h_errnop)) |
110 |
result = NULL; |
result = NULL; |
111 |
pthread_cleanup_pop(1); |
LOCK_RELEASE(lock) |
112 |
return result; |
return result; |
113 |
} |
} |
114 |
|
|
124 |
{ |
{ |
125 |
struct hostent *host; |
struct hostent *host; |
126 |
|
|
127 |
pthread_cleanup_push((void (*)(void*))pthread_mutex_unlock, &mutex); |
LOCK_SET(lock); |
|
pthread_mutex_lock (&mutex); |
|
128 |
host = gethostbyaddr (addr, length, type); |
host = gethostbyaddr (addr, length, type); |
129 |
if (!host || store_hostent(host, result, buffer, buflen, h_errnop)) |
if (!host || store_hostent(host, result, buffer, buflen, h_errnop)) |
130 |
result = NULL; |
result = NULL; |
131 |
pthread_cleanup_pop(1); |
LOCK_RELEASE(lock); |
132 |
return result; |
return result; |
133 |
} |
} |
134 |
|
|