summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2006-11-28 01:54:16 +0000
committerStef Walter <stef@memberwebs.com>2006-11-28 01:54:16 +0000
commit87521fc8eff52fc4bc3bbb5a0ac80d81634bc1e0 (patch)
treefd82bb8bf0df95120247d2858ff53ffb05e21215
parentfafb8142821a34311f55971674630b674b063495 (diff)
Fixed asynchronous resolving on FreeBSD
-rw-r--r--common/async-resolver.c8
-rw-r--r--common/async-resolver.h2
-rw-r--r--daemon/snmp-engine.c7
3 files changed, 13 insertions, 4 deletions
diff --git a/common/async-resolver.c b/common/async-resolver.c
index cf92c86..284a486 100644
--- a/common/async-resolver.c
+++ b/common/async-resolver.c
@@ -109,6 +109,7 @@ typedef struct _resolve_request
{
char hostname[256];
char servname[256];
+ struct addrinfo hints;
async_resolve_callback cb;
void *arg;
@@ -164,7 +165,7 @@ resolver_thread(void* arg)
/* The actual resolve */
req->gaierr = getaddrinfo(req->hostname, req->servname[0] ? req->servname : NULL,
- NULL, &req->ai);
+ &req->hints, &req->ai);
req->errn = errno;
/* A timeout */
@@ -255,7 +256,7 @@ async_resolver_init()
void
async_resolver_queue(const char* hostname, const char* servname,
- async_resolve_callback cb, void* arg)
+ struct addrinfo* hints, async_resolve_callback cb, void* arg)
{
resolve_request* req;
resolve_request* r;
@@ -287,6 +288,9 @@ async_resolver_queue(const char* hostname, const char* servname,
strncpy(req->servname, servname, sizeof(req->servname));
req->servname[sizeof(req->servname) - 1] = 0;
+ if(hints)
+ memcpy(&(req->hints), hints, sizeof(req->hints));
+
/* Append the result to requests */
pthread_mutex_lock(&res_mutex);
diff --git a/common/async-resolver.h b/common/async-resolver.h
index bc17735..a3be364 100644
--- a/common/async-resolver.h
+++ b/common/async-resolver.h
@@ -42,7 +42,7 @@ int async_resolver_init();
void async_resolver_uninit();
void async_resolver_queue(const char* hostname, const char* servname,
- async_resolve_callback cb, void* arg);
+ struct addrinfo* hints, async_resolve_callback cb, void* arg);
#endif /* __ASYNC_RESOLVER_H__ */
diff --git a/daemon/snmp-engine.c b/daemon/snmp-engine.c
index 1d1b64a..65bc1de 100644
--- a/daemon/snmp-engine.c
+++ b/daemon/snmp-engine.c
@@ -637,6 +637,7 @@ static int
resolve_timer(mstime when, void* arg)
{
rb_host* host;
+ struct addrinfo hints;
/* Go through hosts and see which ones need resolving */
for(host = g_state.hosts; host; host = host->next)
@@ -647,9 +648,13 @@ resolve_timer(mstime when, void* arg)
if(when - host->resolve_interval > host->last_resolve_try)
{
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+
/* Automatically strips port number */
rb_messagex(LOG_DEBUG, "resolving host: %s", host->hostname);
- async_resolver_queue(host->hostname, "161", resolve_cb, host);
+ async_resolver_queue(host->hostname, "161", &hints, resolve_cb, host);
host->last_resolve_try = when;
}