1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

sd-resolv: rename to sd-resolve

Lennart pointed out that we were misspelling 'resolve'. Let's not repeat the mistakes of 'umount'
and 'resolv.conf'.
This commit is contained in:
Tom Gundersen 2014-01-14 18:18:43 +01:00
parent c2cb7cbbd5
commit 3bedba4ae1
6 changed files with 243 additions and 243 deletions

2
.gitignore vendored
View File

@ -134,7 +134,7 @@
/test-device-nodes /test-device-nodes
/test-dhcp-client /test-dhcp-client
/test-dhcp-option /test-dhcp-option
/test-resolv /test-resolve
/test-ellipsize /test-ellipsize
/test-engine /test-engine
/test-env-replace /test-env-replace

View File

@ -1982,7 +1982,7 @@ libsystemd_la_SOURCES = \
src/systemd/sd-event.h \ src/systemd/sd-event.h \
src/systemd/sd-dhcp-client.h \ src/systemd/sd-dhcp-client.h \
src/systemd/sd-rtnl.h \ src/systemd/sd-rtnl.h \
src/systemd/sd-resolv.h \ src/systemd/sd-resolve.h \
src/libsystemd/sd-bus.c \ src/libsystemd/sd-bus.c \
src/libsystemd/bus-control.c \ src/libsystemd/bus-control.c \
src/libsystemd/bus-control.h \ src/libsystemd/bus-control.h \
@ -2033,8 +2033,8 @@ libsystemd_la_SOURCES = \
src/libsystemd/rtnl-message.c \ src/libsystemd/rtnl-message.c \
src/libsystemd/rtnl-util.h \ src/libsystemd/rtnl-util.h \
src/libsystemd/rtnl-util.c \ src/libsystemd/rtnl-util.c \
src/libsystemd/sd-resolv.c \ src/libsystemd/sd-resolve.c \
src/libsystemd/resolv-util.h src/libsystemd/resolve-util.h
nodist_libsystemd_la_SOURCES = \ nodist_libsystemd_la_SOURCES = \
src/libsystemd/bus-error-mapping.c src/libsystemd/bus-error-mapping.c
@ -2112,7 +2112,7 @@ tests += \
test-dhcp-option \ test-dhcp-option \
test-dhcp-client \ test-dhcp-client \
test-rtnl \ test-rtnl \
test-resolv test-resolve
bin_PROGRAMS += \ bin_PROGRAMS += \
busctl busctl
@ -2337,15 +2337,15 @@ test_rtnl_LDADD = \
libsystemd-id128-internal.la \ libsystemd-id128-internal.la \
libsystemd-shared.la libsystemd-shared.la
test_resolv_SOURCES = \ test_resolve_SOURCES = \
src/systemd/sd-resolv.h \ src/systemd/sd-resolve.h \
src/libsystemd/test-resolv.c src/libsystemd/test-resolve.c
test_resolv_LDADD = \ test_resolve_LDADD = \
libsystemd-internal.la \ libsystemd-internal.la \
libsystemd-shared.la libsystemd-shared.la
test_resolv_CFLAGS = \ test_resolve_CFLAGS = \
$(AM_CFLAGS) \ $(AM_CFLAGS) \
-pthread -pthread

View File

@ -23,9 +23,9 @@
#include "util.h" #include "util.h"
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_resolv_t*, sd_resolv_free); DEFINE_TRIVIAL_CLEANUP_FUNC(sd_resolve_t*, sd_resolve_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(unsigned char *, sd_resolv_freeanswer); DEFINE_TRIVIAL_CLEANUP_FUNC(unsigned char *, sd_resolve_freeanswer);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct addrinfo*, sd_resolv_freeaddrinfo); DEFINE_TRIVIAL_CLEANUP_FUNC(struct addrinfo*, sd_resolve_freeaddrinfo);
#define _cleanup_resolv_free_ _cleanup_(sd_resolv_freep) #define _cleanup_resolve_free_ _cleanup_(sd_resolve_freep)
#define _cleanup_resolv_answer_free_ _cleanup_(sd_resolv_freeanswerp) #define _cleanup_resolve_answer_free_ _cleanup_(sd_resolve_freeanswerp)
#define _cleanup_resolv_addrinfo_free_ _cleanup_(sd_resolv_freeaddrinfop) #define _cleanup_resolve_addrinfo_free_ _cleanup_(sd_resolve_freeaddrinfop)

View File

@ -41,7 +41,7 @@
#include <pthread.h> #include <pthread.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include "sd-resolv.h" #include "sd-resolve.h"
#include "util.h" #include "util.h"
#define MAX_WORKERS 16 #define MAX_WORKERS 16
@ -68,27 +68,27 @@ enum {
MESSAGE_FD_MAX = 4 MESSAGE_FD_MAX = 4
}; };
struct sd_resolv { struct sd_resolve {
int fds[MESSAGE_FD_MAX]; int fds[MESSAGE_FD_MAX];
pthread_t workers[MAX_WORKERS]; pthread_t workers[MAX_WORKERS];
unsigned valid_workers; unsigned valid_workers;
unsigned current_id, current_index; unsigned current_id, current_index;
sd_resolv_query_t* queries[MAX_QUERIES]; sd_resolve_query_t* queries[MAX_QUERIES];
sd_resolv_query_t *done_head, *done_tail; sd_resolve_query_t *done_head, *done_tail;
int n_queries; int n_queries;
int dead; int dead;
}; };
struct sd_resolv_query { struct sd_resolve_query {
sd_resolv_t *resolv; sd_resolve_t *resolve;
int done; int done;
unsigned id; unsigned id;
query_type_t type; query_type_t type;
sd_resolv_query_t *done_next, *done_prev; sd_resolve_query_t *done_next, *done_prev;
int ret; int ret;
int _errno; int _errno;
int _h_errno; int _h_errno;
@ -383,18 +383,18 @@ static int handle_request(int out_fd, const packet_t *packet, size_t length) {
} }
static void* thread_worker(void *p) { static void* thread_worker(void *p) {
sd_resolv_t *resolv = p; sd_resolve_t *resolve = p;
sigset_t fullset; sigset_t fullset;
/* No signals in this thread please */ /* No signals in this thread please */
sigfillset(&fullset); sigfillset(&fullset);
pthread_sigmask(SIG_BLOCK, &fullset, NULL); pthread_sigmask(SIG_BLOCK, &fullset, NULL);
while (!resolv->dead) { while (!resolve->dead) {
packet_t buf[BUFSIZE/sizeof(packet_t) + 1]; packet_t buf[BUFSIZE/sizeof(packet_t) + 1];
ssize_t length; ssize_t length;
length = recv(resolv->fds[REQUEST_RECV_FD], buf, sizeof(buf), 0); length = recv(resolve->fds[REQUEST_RECV_FD], buf, sizeof(buf), 0);
if (length <= 0) { if (length <= 0) {
if (length < 0 && (errno == EAGAIN || errno == EINTR)) if (length < 0 && (errno == EAGAIN || errno == EINTR))
@ -402,20 +402,20 @@ static void* thread_worker(void *p) {
break; break;
} }
if (resolv->dead) if (resolve->dead)
break; break;
if (handle_request(resolv->fds[RESPONSE_SEND_FD], buf, (size_t) length) < 0) if (handle_request(resolve->fds[RESPONSE_SEND_FD], buf, (size_t) length) < 0)
break; break;
} }
send_died(resolv->fds[RESPONSE_SEND_FD]); send_died(resolve->fds[RESPONSE_SEND_FD]);
return NULL; return NULL;
} }
sd_resolv_t* sd_resolv_new(unsigned n_proc) { sd_resolve_t* sd_resolve_new(unsigned n_proc) {
sd_resolv_t *resolv = NULL; sd_resolve_t *resolve = NULL;
int i, r; int i, r;
assert(n_proc >= 1); assert(n_proc >= 1);
@ -423,61 +423,61 @@ sd_resolv_t* sd_resolv_new(unsigned n_proc) {
if (n_proc > MAX_WORKERS) if (n_proc > MAX_WORKERS)
n_proc = MAX_WORKERS; n_proc = MAX_WORKERS;
resolv = malloc(sizeof(sd_resolv_t)); resolve = malloc(sizeof(sd_resolve_t));
if (!resolv) { if (!resolve) {
errno = ENOMEM; errno = ENOMEM;
goto fail; goto fail;
} }
resolv->dead = 0; resolve->dead = 0;
resolv->valid_workers = 0; resolve->valid_workers = 0;
for (i = 0; i < MESSAGE_FD_MAX; i++) for (i = 0; i < MESSAGE_FD_MAX; i++)
resolv->fds[i] = -1; resolve->fds[i] = -1;
memset(resolv->queries, 0, sizeof(resolv->queries)); memset(resolve->queries, 0, sizeof(resolve->queries));
r = socketpair(PF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, resolv->fds); r = socketpair(PF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, resolve->fds);
if (r < 0) if (r < 0)
goto fail; goto fail;
r = socketpair(PF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, resolv->fds+2); r = socketpair(PF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, resolve->fds+2);
if (r < 0) if (r < 0)
goto fail; goto fail;
for (resolv->valid_workers = 0; resolv->valid_workers < n_proc; resolv->valid_workers++) { for (resolve->valid_workers = 0; resolve->valid_workers < n_proc; resolve->valid_workers++) {
r = pthread_create(&resolv->workers[resolv->valid_workers], NULL, thread_worker, resolv); r = pthread_create(&resolve->workers[resolve->valid_workers], NULL, thread_worker, resolve);
if (r) { if (r) {
errno = r; errno = r;
goto fail; goto fail;
} }
} }
resolv->current_index = resolv->current_id = 0; resolve->current_index = resolve->current_id = 0;
resolv->done_head = resolv->done_tail = NULL; resolve->done_head = resolve->done_tail = NULL;
resolv->n_queries = 0; resolve->n_queries = 0;
fd_nonblock(resolv->fds[RESPONSE_RECV_FD], true); fd_nonblock(resolve->fds[RESPONSE_RECV_FD], true);
return resolv; return resolve;
fail: fail:
if (resolv) if (resolve)
sd_resolv_free(resolv); sd_resolve_free(resolve);
return NULL; return NULL;
} }
void sd_resolv_free(sd_resolv_t *resolv) { void sd_resolve_free(sd_resolve_t *resolve) {
int i; int i;
int saved_errno = errno; int saved_errno = errno;
unsigned p; unsigned p;
assert(resolv); assert(resolve);
resolv->dead = 1; resolve->dead = 1;
if (resolv->fds[REQUEST_SEND_FD] >= 0) { if (resolve->fds[REQUEST_SEND_FD] >= 0) {
rheader_t req = {}; rheader_t req = {};
req.type = REQUEST_TERMINATE; req.type = REQUEST_TERMINATE;
@ -485,43 +485,43 @@ void sd_resolv_free(sd_resolv_t *resolv) {
req.id = 0; req.id = 0;
/* Send one termination packet for each worker */ /* Send one termination packet for each worker */
for (p = 0; p < resolv->valid_workers; p++) for (p = 0; p < resolve->valid_workers; p++)
send(resolv->fds[REQUEST_SEND_FD], &req, req.length, MSG_NOSIGNAL); send(resolve->fds[REQUEST_SEND_FD], &req, req.length, MSG_NOSIGNAL);
} }
/* Now terminate them and wait until they are gone. */ /* Now terminate them and wait until they are gone. */
for (p = 0; p < resolv->valid_workers; p++) { for (p = 0; p < resolve->valid_workers; p++) {
for (;;) { for (;;) {
if (pthread_join(resolv->workers[p], NULL) != EINTR) if (pthread_join(resolve->workers[p], NULL) != EINTR)
break; break;
} }
} }
/* Close all communication channels */ /* Close all communication channels */
for (i = 0; i < MESSAGE_FD_MAX; i++) for (i = 0; i < MESSAGE_FD_MAX; i++)
if (resolv->fds[i] >= 0) if (resolve->fds[i] >= 0)
close(resolv->fds[i]); close(resolve->fds[i]);
for (p = 0; p < MAX_QUERIES; p++) for (p = 0; p < MAX_QUERIES; p++)
if (resolv->queries[p]) if (resolve->queries[p])
sd_resolv_cancel(resolv, resolv->queries[p]); sd_resolve_cancel(resolve, resolve->queries[p]);
free(resolv); free(resolve);
errno = saved_errno; errno = saved_errno;
} }
int sd_resolv_fd(sd_resolv_t *resolv) { int sd_resolve_fd(sd_resolve_t *resolve) {
assert(resolv); assert(resolve);
return resolv->fds[RESPONSE_RECV_FD]; return resolve->fds[RESPONSE_RECV_FD];
} }
static sd_resolv_query_t *lookup_query(sd_resolv_t *resolv, unsigned id) { static sd_resolve_query_t *lookup_query(sd_resolve_t *resolve, unsigned id) {
sd_resolv_query_t *q; sd_resolve_query_t *q;
assert(resolv); assert(resolve);
q = resolv->queries[id % MAX_QUERIES]; q = resolve->queries[id % MAX_QUERIES];
if (q) if (q)
if (q->id == id) if (q->id == id)
return q; return q;
@ -529,19 +529,19 @@ static sd_resolv_query_t *lookup_query(sd_resolv_t *resolv, unsigned id) {
return NULL; return NULL;
} }
static void complete_query(sd_resolv_t *resolv, sd_resolv_query_t *q) { static void complete_query(sd_resolve_t *resolve, sd_resolve_query_t *q) {
assert(resolv); assert(resolve);
assert(q); assert(q);
assert(!q->done); assert(!q->done);
q->done = 1; q->done = 1;
if ((q->done_prev = resolv->done_tail)) if ((q->done_prev = resolve->done_tail))
resolv->done_tail->done_next = q; resolve->done_tail->done_next = q;
else else
resolv->done_head = q; resolve->done_head = q;
resolv->done_tail = q; resolve->done_tail = q;
q->done_next = NULL; q->done_next = NULL;
} }
@ -596,16 +596,16 @@ static const void *unserialize_addrinfo(const void *p, struct addrinfo **ret_ai,
fail: fail:
if (ai) if (ai)
sd_resolv_freeaddrinfo(ai); sd_resolve_freeaddrinfo(ai);
return NULL; return NULL;
} }
static int handle_response(sd_resolv_t *resolv, const packet_t *packet, size_t length) { static int handle_response(sd_resolve_t *resolve, const packet_t *packet, size_t length) {
const rheader_t *resp; const rheader_t *resp;
sd_resolv_query_t *q; sd_resolve_query_t *q;
assert(resolv); assert(resolve);
resp = &packet->rheader; resp = &packet->rheader;
assert(resp); assert(resp);
@ -613,11 +613,11 @@ static int handle_response(sd_resolv_t *resolv, const packet_t *packet, size_t l
assert(length == resp->length); assert(length == resp->length);
if (resp->type == RESPONSE_DIED) { if (resp->type == RESPONSE_DIED) {
resolv->dead = 1; resolve->dead = 1;
return 0; return 0;
} }
q = lookup_query(resolv, resp->id); q = lookup_query(resolve, resp->id);
if (!q) if (!q)
return 0; return 0;
@ -654,7 +654,7 @@ static int handle_response(sd_resolv_t *resolv, const packet_t *packet, size_t l
prev = ai; prev = ai;
} }
complete_query(resolv, q); complete_query(resolve, q);
break; break;
} }
@ -676,7 +676,7 @@ static int handle_response(sd_resolv_t *resolv, const packet_t *packet, size_t l
if (!(q->serv = strndup((const char*) ni_resp + sizeof(nameinfo_response_t) + ni_resp->hostlen, ni_resp->servlen-1))) if (!(q->serv = strndup((const char*) ni_resp + sizeof(nameinfo_response_t) + ni_resp->hostlen, ni_resp->servlen-1)))
q->ret = EAI_MEMORY; q->ret = EAI_MEMORY;
complete_query(resolv, q); complete_query(resolve, q);
break; break;
} }
@ -698,7 +698,7 @@ static int handle_response(sd_resolv_t *resolv, const packet_t *packet, size_t l
memcpy(q->serv, (const char *)resp + sizeof(res_response_t), res_resp->ret); memcpy(q->serv, (const char *)resp + sizeof(res_response_t), res_resp->ret);
} }
complete_query(resolv, q); complete_query(resolve, q);
break; break;
} }
@ -709,20 +709,20 @@ static int handle_response(sd_resolv_t *resolv, const packet_t *packet, size_t l
return 0; return 0;
} }
int sd_resolv_wait(sd_resolv_t *resolv, int block) { int sd_resolve_wait(sd_resolve_t *resolve, int block) {
int handled = 0; int handled = 0;
assert(resolv); assert(resolve);
for (;;) { for (;;) {
packet_t buf[BUFSIZE/sizeof(packet_t) + 1]; packet_t buf[BUFSIZE/sizeof(packet_t) + 1];
ssize_t l; ssize_t l;
if (resolv->dead) { if (resolve->dead) {
errno = ECHILD; errno = ECHILD;
return -1; return -1;
} }
l = recv(resolv->fds[RESPONSE_RECV_FD], buf, sizeof(buf), 0); l = recv(resolve->fds[RESPONSE_RECV_FD], buf, sizeof(buf), 0);
if (l < 0) { if (l < 0) {
fd_set fds; fd_set fds;
@ -733,49 +733,49 @@ int sd_resolv_wait(sd_resolv_t *resolv, int block) {
return 0; return 0;
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(resolv->fds[RESPONSE_RECV_FD], &fds); FD_SET(resolve->fds[RESPONSE_RECV_FD], &fds);
if (select(resolv->fds[RESPONSE_RECV_FD]+1, &fds, NULL, NULL, NULL) < 0) if (select(resolve->fds[RESPONSE_RECV_FD]+1, &fds, NULL, NULL, NULL) < 0)
return -1; return -1;
continue; continue;
} }
if (handle_response(resolv, buf, (size_t) l) < 0) if (handle_response(resolve, buf, (size_t) l) < 0)
return -1; return -1;
handled = 1; handled = 1;
} }
} }
static sd_resolv_query_t *alloc_query(sd_resolv_t *resolv) { static sd_resolve_query_t *alloc_query(sd_resolve_t *resolve) {
sd_resolv_query_t *q; sd_resolve_query_t *q;
assert(resolv); assert(resolve);
if (resolv->n_queries >= MAX_QUERIES) { if (resolve->n_queries >= MAX_QUERIES) {
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
} }
while (resolv->queries[resolv->current_index]) { while (resolve->queries[resolve->current_index]) {
resolv->current_index++; resolve->current_index++;
resolv->current_id++; resolve->current_id++;
while (resolv->current_index >= MAX_QUERIES) while (resolve->current_index >= MAX_QUERIES)
resolv->current_index -= MAX_QUERIES; resolve->current_index -= MAX_QUERIES;
} }
q = resolv->queries[resolv->current_index] = malloc(sizeof(sd_resolv_query_t)); q = resolve->queries[resolve->current_index] = malloc(sizeof(sd_resolve_query_t));
if (!q) { if (!q) {
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
} }
resolv->n_queries++; resolve->n_queries++;
q->resolv = resolv; q->resolve = resolve;
q->done = 0; q->done = 0;
q->id = resolv->current_id; q->id = resolve->current_id;
q->done_next = q->done_prev = NULL; q->done_next = q->done_prev = NULL;
q->ret = 0; q->ret = 0;
q->_errno = 0; q->_errno = 0;
@ -787,19 +787,19 @@ static sd_resolv_query_t *alloc_query(sd_resolv_t *resolv) {
return q; return q;
} }
sd_resolv_query_t* sd_resolv_getaddrinfo(sd_resolv_t *resolv, const char *node, const char *service, const struct addrinfo *hints) { sd_resolve_query_t* sd_resolve_getaddrinfo(sd_resolve_t *resolve, const char *node, const char *service, const struct addrinfo *hints) {
addrinfo_request_t data[BUFSIZE/sizeof(addrinfo_request_t) + 1] = {}; addrinfo_request_t data[BUFSIZE/sizeof(addrinfo_request_t) + 1] = {};
addrinfo_request_t *req = data; addrinfo_request_t *req = data;
sd_resolv_query_t *q; sd_resolve_query_t *q;
assert(resolv); assert(resolve);
assert(node || service); assert(node || service);
if (resolv->dead) { if (resolve->dead) {
errno = ECHILD; errno = ECHILD;
return NULL; return NULL;
} }
q = alloc_query(resolv); q = alloc_query(resolve);
if (!q) if (!q)
return NULL; return NULL;
@ -828,26 +828,26 @@ sd_resolv_query_t* sd_resolv_getaddrinfo(sd_resolv_t *resolv, const char *node,
if (service) if (service)
strcpy((char*) req + sizeof(addrinfo_request_t) + req->node_len, service); strcpy((char*) req + sizeof(addrinfo_request_t) + req->node_len, service);
if (send(resolv->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0) if (send(resolve->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0)
goto fail; goto fail;
return q; return q;
fail: fail:
if (q) if (q)
sd_resolv_cancel(resolv, q); sd_resolve_cancel(resolve, q);
return NULL; return NULL;
} }
int sd_resolv_getaddrinfo_done(sd_resolv_t *resolv, sd_resolv_query_t* q, struct addrinfo **ret_res) { int sd_resolve_getaddrinfo_done(sd_resolve_t *resolve, sd_resolve_query_t* q, struct addrinfo **ret_res) {
int ret; int ret;
assert(resolv); assert(resolve);
assert(q); assert(q);
assert(q->resolv == resolv); assert(q->resolve == resolve);
assert(q->type == REQUEST_ADDRINFO); assert(q->type == REQUEST_ADDRINFO);
if (resolv->dead) { if (resolve->dead) {
errno = ECHILD; errno = ECHILD;
return EAI_SYSTEM; return EAI_SYSTEM;
} }
@ -866,26 +866,26 @@ int sd_resolv_getaddrinfo_done(sd_resolv_t *resolv, sd_resolv_query_t* q, struct
if (ret != 0) if (ret != 0)
h_errno = q->_h_errno; h_errno = q->_h_errno;
sd_resolv_cancel(resolv, q); sd_resolve_cancel(resolve, q);
return ret; return ret;
} }
sd_resolv_query_t* sd_resolv_getnameinfo(sd_resolv_t *resolv, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv) { sd_resolve_query_t* sd_resolve_getnameinfo(sd_resolve_t *resolve, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv) {
nameinfo_request_t data[BUFSIZE/sizeof(nameinfo_request_t) + 1] = {}; nameinfo_request_t data[BUFSIZE/sizeof(nameinfo_request_t) + 1] = {};
nameinfo_request_t *req = data; nameinfo_request_t *req = data;
sd_resolv_query_t *q; sd_resolve_query_t *q;
assert(resolv); assert(resolve);
assert(sa); assert(sa);
assert(salen > 0); assert(salen > 0);
if (resolv->dead) { if (resolve->dead) {
errno = ECHILD; errno = ECHILD;
return NULL; return NULL;
} }
q = alloc_query(resolv); q = alloc_query(resolve);
if (!q) if (!q)
return NULL; return NULL;
@ -905,28 +905,28 @@ sd_resolv_query_t* sd_resolv_getnameinfo(sd_resolv_t *resolv, const struct socka
memcpy((uint8_t*) req + sizeof(nameinfo_request_t), sa, salen); memcpy((uint8_t*) req + sizeof(nameinfo_request_t), sa, salen);
if (send(resolv->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0) if (send(resolve->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0)
goto fail; goto fail;
return q; return q;
fail: fail:
if (q) if (q)
sd_resolv_cancel(resolv, q); sd_resolve_cancel(resolve, q);
return NULL; return NULL;
} }
int sd_resolv_getnameinfo_done(sd_resolv_t *resolv, sd_resolv_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen) { int sd_resolve_getnameinfo_done(sd_resolve_t *resolve, sd_resolve_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen) {
int ret; int ret;
assert(resolv); assert(resolve);
assert(q); assert(q);
assert(q->resolv == resolv); assert(q->resolve == resolve);
assert(q->type == REQUEST_NAMEINFO); assert(q->type == REQUEST_NAMEINFO);
assert(!ret_host || hostlen); assert(!ret_host || hostlen);
assert(!ret_serv || servlen); assert(!ret_serv || servlen);
if (resolv->dead) { if (resolve->dead) {
errno = ECHILD; errno = ECHILD;
return EAI_SYSTEM; return EAI_SYSTEM;
} }
@ -952,25 +952,25 @@ int sd_resolv_getnameinfo_done(sd_resolv_t *resolv, sd_resolv_query_t* q, char *
if (ret != 0) if (ret != 0)
h_errno = q->_h_errno; h_errno = q->_h_errno;
sd_resolv_cancel(resolv, q); sd_resolve_cancel(resolve, q);
return ret; return ret;
} }
static sd_resolv_query_t * resolv_res(sd_resolv_t *resolv, query_type_t qtype, const char *dname, int class, int type) { static sd_resolve_query_t * resolve_res(sd_resolve_t *resolve, query_type_t qtype, const char *dname, int class, int type) {
res_request_t data[BUFSIZE/sizeof(res_request_t) + 1]; res_request_t data[BUFSIZE/sizeof(res_request_t) + 1];
res_request_t *req = data; res_request_t *req = data;
sd_resolv_query_t *q; sd_resolve_query_t *q;
assert(resolv); assert(resolve);
assert(dname); assert(dname);
if (resolv->dead) { if (resolve->dead) {
errno = ECHILD; errno = ECHILD;
return NULL; return NULL;
} }
q = alloc_query(resolv); q = alloc_query(resolve);
if (!q) if (!q)
return NULL; return NULL;
@ -990,35 +990,35 @@ static sd_resolv_query_t * resolv_res(sd_resolv_t *resolv, query_type_t qtype, c
strcpy((char*) req + sizeof(res_request_t), dname); strcpy((char*) req + sizeof(res_request_t), dname);
if (send(resolv->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0) if (send(resolve->fds[REQUEST_SEND_FD], req, req->header.length, MSG_NOSIGNAL) < 0)
goto fail; goto fail;
return q; return q;
fail: fail:
if (q) if (q)
sd_resolv_cancel(resolv, q); sd_resolve_cancel(resolve, q);
return NULL; return NULL;
} }
sd_resolv_query_t* sd_resolv_res_query(sd_resolv_t *resolv, const char *dname, int class, int type) { sd_resolve_query_t* sd_resolve_res_query(sd_resolve_t *resolve, const char *dname, int class, int type) {
return resolv_res(resolv, REQUEST_RES_QUERY, dname, class, type); return resolve_res(resolve, REQUEST_RES_QUERY, dname, class, type);
} }
sd_resolv_query_t* sd_resolv_res_search(sd_resolv_t *resolv, const char *dname, int class, int type) { sd_resolve_query_t* sd_resolve_res_search(sd_resolve_t *resolve, const char *dname, int class, int type) {
return resolv_res(resolv, REQUEST_RES_SEARCH, dname, class, type); return resolve_res(resolve, REQUEST_RES_SEARCH, dname, class, type);
} }
int sd_resolv_res_done(sd_resolv_t *resolv, sd_resolv_query_t* q, unsigned char **answer) { int sd_resolve_res_done(sd_resolve_t *resolve, sd_resolve_query_t* q, unsigned char **answer) {
int ret; int ret;
assert(resolv); assert(resolve);
assert(q); assert(q);
assert(q->resolv == resolv); assert(q->resolve == resolve);
assert(q->type == REQUEST_RES_QUERY || q->type == REQUEST_RES_SEARCH); assert(q->type == REQUEST_RES_QUERY || q->type == REQUEST_RES_SEARCH);
assert(answer); assert(answer);
if (resolv->dead) { if (resolve->dead) {
errno = ECHILD; errno = ECHILD;
return -ECHILD; return -ECHILD;
} }
@ -1038,58 +1038,58 @@ int sd_resolv_res_done(sd_resolv_t *resolv, sd_resolv_query_t* q, unsigned char
h_errno = q->_h_errno; h_errno = q->_h_errno;
} }
sd_resolv_cancel(resolv, q); sd_resolve_cancel(resolve, q);
return ret < 0 ? -errno : ret; return ret < 0 ? -errno : ret;
} }
sd_resolv_query_t* sd_resolv_getnext(sd_resolv_t *resolv) { sd_resolve_query_t* sd_resolve_getnext(sd_resolve_t *resolve) {
assert(resolv); assert(resolve);
return resolv->done_head; return resolve->done_head;
} }
int sd_resolv_getnqueries(sd_resolv_t *resolv) { int sd_resolve_getnqueries(sd_resolve_t *resolve) {
assert(resolv); assert(resolve);
return resolv->n_queries; return resolve->n_queries;
} }
void sd_resolv_cancel(sd_resolv_t *resolv, sd_resolv_query_t* q) { void sd_resolve_cancel(sd_resolve_t *resolve, sd_resolve_query_t* q) {
int i; int i;
int saved_errno = errno; int saved_errno = errno;
assert(resolv); assert(resolve);
assert(q); assert(q);
assert(q->resolv == resolv); assert(q->resolve == resolve);
assert(resolv->n_queries > 0); assert(resolve->n_queries > 0);
if (q->done) { if (q->done) {
if (q->done_prev) if (q->done_prev)
q->done_prev->done_next = q->done_next; q->done_prev->done_next = q->done_next;
else else
resolv->done_head = q->done_next; resolve->done_head = q->done_next;
if (q->done_next) if (q->done_next)
q->done_next->done_prev = q->done_prev; q->done_next->done_prev = q->done_prev;
else else
resolv->done_tail = q->done_prev; resolve->done_tail = q->done_prev;
} }
i = q->id % MAX_QUERIES; i = q->id % MAX_QUERIES;
assert(resolv->queries[i] == q); assert(resolve->queries[i] == q);
resolv->queries[i] = NULL; resolve->queries[i] = NULL;
sd_resolv_freeaddrinfo(q->addrinfo); sd_resolve_freeaddrinfo(q->addrinfo);
free(q->host); free(q->host);
free(q->serv); free(q->serv);
resolv->n_queries--; resolve->n_queries--;
free(q); free(q);
errno = saved_errno; errno = saved_errno;
} }
void sd_resolv_freeaddrinfo(struct addrinfo *ai) { void sd_resolve_freeaddrinfo(struct addrinfo *ai) {
int saved_errno = errno; int saved_errno = errno;
while (ai) { while (ai) {
@ -1105,7 +1105,7 @@ void sd_resolv_freeaddrinfo(struct addrinfo *ai) {
errno = saved_errno; errno = saved_errno;
} }
void sd_resolv_freeanswer(unsigned char *answer) { void sd_resolve_freeanswer(unsigned char *answer) {
int saved_errno = errno; int saved_errno = errno;
if (!answer) if (!answer)
@ -1116,26 +1116,26 @@ void sd_resolv_freeanswer(unsigned char *answer) {
errno = saved_errno; errno = saved_errno;
} }
int sd_resolv_isdone(sd_resolv_t *resolv, sd_resolv_query_t*q) { int sd_resolve_isdone(sd_resolve_t *resolve, sd_resolve_query_t*q) {
assert(resolv); assert(resolve);
assert(q); assert(q);
assert(q->resolv == resolv); assert(q->resolve == resolve);
return q->done; return q->done;
} }
void sd_resolv_setuserdata(sd_resolv_t *resolv, sd_resolv_query_t *q, void *userdata) { void sd_resolve_setuserdata(sd_resolve_t *resolve, sd_resolve_query_t *q, void *userdata) {
assert(q); assert(q);
assert(resolv); assert(resolve);
assert(q->resolv = resolv); assert(q->resolve = resolve);
q->userdata = userdata; q->userdata = userdata;
} }
void* sd_resolv_getuserdata(sd_resolv_t *resolv, sd_resolv_query_t *q) { void* sd_resolve_getuserdata(sd_resolve_t *resolve, sd_resolve_query_t *q) {
assert(q); assert(q);
assert(resolv); assert(resolve);
assert(q->resolv = resolv); assert(q->resolve = resolve);
return q->userdata; return q->userdata;
} }

View File

@ -31,58 +31,58 @@
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include "sd-resolv.h" #include "sd-resolve.h"
#include "resolv-util.h" #include "resolve-util.h"
#include "macro.h" #include "macro.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int r = 1, ret; int r = 1, ret;
_cleanup_resolv_free_ sd_resolv_t *resolv = NULL; _cleanup_resolve_free_ sd_resolve_t *resolve = NULL;
_cleanup_resolv_addrinfo_free_ struct addrinfo *ai = NULL; _cleanup_resolve_addrinfo_free_ struct addrinfo *ai = NULL;
_cleanup_resolv_answer_free_ unsigned char *srv = NULL; _cleanup_resolve_answer_free_ unsigned char *srv = NULL;
sd_resolv_query_t *q1, *q2, *q3; sd_resolve_query_t *q1, *q2, *q3;
struct addrinfo hints = {}; struct addrinfo hints = {};
struct sockaddr_in sa = {}; struct sockaddr_in sa = {};
char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = ""; char host[NI_MAXHOST] = "", serv[NI_MAXSERV] = "";
signal(SIGCHLD, SIG_IGN); signal(SIGCHLD, SIG_IGN);
resolv = sd_resolv_new(2); resolve = sd_resolve_new(2);
if (!resolv) if (!resolve)
log_oom(); log_oom();
/* Make a name -> address query */ /* Make a name -> address query */
hints.ai_family = PF_UNSPEC; hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
q1 = sd_resolv_getaddrinfo(resolv, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints); q1 = sd_resolve_getaddrinfo(resolve, argc >= 2 ? argv[1] : "www.heise.de", NULL, &hints);
if (!q1) if (!q1)
fprintf(stderr, "sd_resolv_getaddrinfo(): %s\n", strerror(errno)); fprintf(stderr, "sd_resolve_getaddrinfo(): %s\n", strerror(errno));
/* Make an address -> name query */ /* Make an address -> name query */
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr(argc >= 3 ? argv[2] : "193.99.144.71"); sa.sin_addr.s_addr = inet_addr(argc >= 3 ? argv[2] : "193.99.144.71");
sa.sin_port = htons(80); sa.sin_port = htons(80);
q2 = sd_resolv_getnameinfo(resolv, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1); q2 = sd_resolve_getnameinfo(resolve, (struct sockaddr*) &sa, sizeof(sa), 0, 1, 1);
if (!q2) if (!q2)
fprintf(stderr, "sd_resolv_getnameinfo(): %s\n", strerror(errno)); fprintf(stderr, "sd_resolve_getnameinfo(): %s\n", strerror(errno));
/* Make a res_query() call */ /* Make a res_query() call */
q3 = sd_resolv_res_query(resolv, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV); q3 = sd_resolve_res_query(resolve, "_xmpp-client._tcp.gmail.com", C_IN, T_SRV);
if (!q3) if (!q3)
fprintf(stderr, "sd_resolv_res_query(): %s\n", strerror(errno)); fprintf(stderr, "sd_resolve_res_query(): %s\n", strerror(errno));
/* Wait until the three queries are completed */ /* Wait until the three queries are completed */
while (!sd_resolv_isdone(resolv, q1) || while (!sd_resolve_isdone(resolve, q1) ||
!sd_resolv_isdone(resolv, q2) || !sd_resolve_isdone(resolve, q2) ||
!sd_resolv_isdone(resolv, q3)) { !sd_resolve_isdone(resolve, q3)) {
if (sd_resolv_wait(resolv, 1) < 0) if (sd_resolve_wait(resolve, 1) < 0)
fprintf(stderr, "sd_resolv_wait(): %s\n", strerror(errno)); fprintf(stderr, "sd_resolve_wait(): %s\n", strerror(errno));
} }
/* Interpret the result of the name -> addr query */ /* Interpret the result of the name -> addr query */
ret = sd_resolv_getaddrinfo_done(resolv, q1, &ai); ret = sd_resolve_getaddrinfo_done(resolve, q1, &ai);
if (ret) if (ret)
fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret); fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
else { else {
@ -102,14 +102,14 @@ int main(int argc, char *argv[]) {
} }
/* Interpret the result of the addr -> name query */ /* Interpret the result of the addr -> name query */
ret = sd_resolv_getnameinfo_done(resolv, q2, host, sizeof(host), serv, sizeof(serv)); ret = sd_resolve_getnameinfo_done(resolve, q2, host, sizeof(host), serv, sizeof(serv));
if (ret) if (ret)
fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret); fprintf(stderr, "error: %s %i\n", gai_strerror(ret), ret);
else else
printf("%s -- %s\n", host, serv); printf("%s -- %s\n", host, serv);
/* Interpret the result of the SRV lookup */ /* Interpret the result of the SRV lookup */
ret = sd_resolv_res_done(resolv, q3, &srv); ret = sd_resolve_res_done(resolve, q3, &srv);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "error: %s %i\n", strerror(errno), ret); fprintf(stderr, "error: %s %i\n", strerror(errno), ret);
} else if (ret == 0) { } else if (ret == 0) {

View File

@ -1,7 +1,7 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
#ifndef foosdresolvhfoo #ifndef foosdresolvehfoo
#define foosdresolvhfoo #define foosdresolvehfoo
/*** /***
This file is part of systemd. This file is part of systemd.
@ -33,125 +33,125 @@ _SD_BEGIN_DECLARATIONS;
* *
* \section moo Method of operation * \section moo Method of operation
* *
* To use libresolv allocate an sd_resolv_t object with * To use sd-resolve allocate an sd_resolve_t object with
* sd_resolv_new(). This will spawn a number of worker threads (or processes, depending on what is available) which * sd_resolve_new(). This will spawn a number of worker threads (or processes, depending on what is available) which
* are subsequently used to process the queries the controlling * are subsequently used to process the queries the controlling
* program issues via sd_resolv_getaddrinfo() and * program issues via sd_resolve_getaddrinfo() and
* sd_resolv_getnameinfo(). Use sd_resolv_free() to shut down the worker * sd_resolve_getnameinfo(). Use sd_resolve_free() to shut down the worker
* threads/processes. * threads/processes.
* *
* Since libresolv may fork off new processes you have to make sure that * Since sd-resolve may fork off new processes you have to make sure that
* your program is not irritated by spurious SIGCHLD signals. * your program is not irritated by spurious SIGCHLD signals.
*/ */
/** An opaque libresolv session structure */ /** An opaque sd-resolve session structure */
typedef struct sd_resolv sd_resolv_t; typedef struct sd_resolve sd_resolve_t;
/** An opaque libresolv query structure */ /** An opaque sd-resolve query structure */
typedef struct sd_resolv_query sd_resolv_query_t; typedef struct sd_resolve_query sd_resolve_query_t;
/** Allocate a new libresolv session with n_proc worker processes/threads */ /** Allocate a new sd-resolve session with n_proc worker processes/threads */
sd_resolv_t* sd_resolv_new(unsigned n_proc); sd_resolve_t* sd_resolve_new(unsigned n_proc);
/** Free a libresolv session. This destroys all attached /** Free a sd-resolve session. This destroys all attached
* sd_resolv_query_t objects automatically */ * sd_resolve_query_t objects automatically */
void sd_resolv_free(sd_resolv_t *resolv); void sd_resolve_free(sd_resolve_t *resolve);
/** Return the UNIX file descriptor to select() for readability /** Return the UNIX file descriptor to select() for readability
* on. Use this function to integrate libresolv with your custom main * on. Use this function to integrate sd-resolve with your custom main
* loop. */ * loop. */
int sd_resolv_fd(sd_resolv_t *resolv); int sd_resolve_fd(sd_resolve_t *resolve);
/** Process pending responses. After this function is called you can /** Process pending responses. After this function is called you can
* get the next completed query object(s) using sd_resolv_getnext(). If * get the next completed query object(s) using sd_resolve_getnext(). If
* block is non-zero wait until at least one response has been * block is non-zero wait until at least one response has been
* processed. If block is zero, process all pending responses and * processed. If block is zero, process all pending responses and
* return. */ * return. */
int sd_resolv_wait(sd_resolv_t *resolv, int block); int sd_resolve_wait(sd_resolve_t *resolve, int block);
/** Issue a name to address query on the specified session. The /** Issue a name to address query on the specified session. The
* arguments are compatible with the ones of libc's * arguments are compatible with the ones of libc's
* getaddrinfo(3). The function returns a new query object. When the * getaddrinfo(3). The function returns a new query object. When the
* query is completed you may retrieve the results using * query is completed you may retrieve the results using
* sd_resolv_getaddrinfo_done().*/ * sd_resolve_getaddrinfo_done().*/
sd_resolv_query_t* sd_resolv_getaddrinfo(sd_resolv_t *resolv, const char *node, const char *service, const struct addrinfo *hints); sd_resolve_query_t* sd_resolve_getaddrinfo(sd_resolve_t *resolve, const char *node, const char *service, const struct addrinfo *hints);
/** Retrieve the results of a preceding sd_resolv_getaddrinfo() /** Retrieve the results of a preceding sd_resolve_getaddrinfo()
* call. Returns a addrinfo structure and a return value compatible * call. Returns a addrinfo structure and a return value compatible
* with libc's getaddrinfo(3). The query object q is destroyed by this * with libc's getaddrinfo(3). The query object q is destroyed by this
* call and may not be used any further. Make sure to free the * call and may not be used any further. Make sure to free the
* returned addrinfo structure with sd_resolv_freeaddrinfo() and not * returned addrinfo structure with sd_resolve_freeaddrinfo() and not
* libc's freeaddrinfo(3)! If the query is not completed yet EAI_AGAIN * libc's freeaddrinfo(3)! If the query is not completed yet EAI_AGAIN
* is returned.*/ * is returned.*/
int sd_resolv_getaddrinfo_done(sd_resolv_t *resolv, sd_resolv_query_t* q, struct addrinfo **ret_res); int sd_resolve_getaddrinfo_done(sd_resolve_t *resolve, sd_resolve_query_t* q, struct addrinfo **ret_res);
/** Issue an address to name query on the specified session. The /** Issue an address to name query on the specified session. The
* arguments are compatible with the ones of libc's * arguments are compatible with the ones of libc's
* getnameinfo(3). The function returns a new query object. When the * getnameinfo(3). The function returns a new query object. When the
* query is completed you may retrieve the results using * query is completed you may retrieve the results using
* sd_resolv_getnameinfo_done(). Set gethost (resp. getserv) to non-zero * sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
* if you want to query the hostname (resp. the service name). */ * if you want to query the hostname (resp. the service name). */
sd_resolv_query_t* sd_resolv_getnameinfo(sd_resolv_t *resolv, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv); sd_resolve_query_t* sd_resolve_getnameinfo(sd_resolve_t *resolve, const struct sockaddr *sa, socklen_t salen, int flags, int gethost, int getserv);
/** Retrieve the results of a preceding sd_resolv_getnameinfo() /** Retrieve the results of a preceding sd_resolve_getnameinfo()
* call. Returns the hostname and the service name in ret_host and * call. Returns the hostname and the service name in ret_host and
* ret_serv. The query object q is destroyed by this call and may not * ret_serv. The query object q is destroyed by this call and may not
* be used any further. If the query is not completed yet EAI_AGAIN is * be used any further. If the query is not completed yet EAI_AGAIN is
* returned. */ * returned. */
int sd_resolv_getnameinfo_done(sd_resolv_t *resolv, sd_resolv_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen); int sd_resolve_getnameinfo_done(sd_resolve_t *resolve, sd_resolve_query_t* q, char *ret_host, size_t hostlen, char *ret_serv, size_t servlen);
/** Issue a resolver query on the specified session. The arguments are /** Issue a resolveer query on the specified session. The arguments are
* compatible with the ones of libc's res_query(3). The function returns a new * compatible with the ones of libc's res_query(3). The function returns a new
* query object. When the query is completed you may retrieve the results using * query object. When the query is completed you may retrieve the results using
* sd_resolv_res_done(). */ * sd_resolve_res_done(). */
sd_resolv_query_t* sd_resolv_res_query(sd_resolv_t *resolv, const char *dname, int class, int type); sd_resolve_query_t* sd_resolve_res_query(sd_resolve_t *resolve, const char *dname, int class, int type);
/** Issue an resolver query on the specified session. The arguments are /** Issue an resolveer query on the specified session. The arguments are
* compatible with the ones of libc's res_search(3). The function returns a new * compatible with the ones of libc's res_search(3). The function returns a new
* query object. When the query is completed you may retrieve the results using * query object. When the query is completed you may retrieve the results using
* sd_resolv_res_done(). */ * sd_resolve_res_done(). */
sd_resolv_query_t* sd_resolv_res_search(sd_resolv_t *resolv, const char *dname, int class, int type); sd_resolve_query_t* sd_resolve_res_search(sd_resolve_t *resolve, const char *dname, int class, int type);
/** Retrieve the results of a preceding sd_resolv_res_query() or /** Retrieve the results of a preceding sd_resolve_res_query() or
* resolv_res_search call. The query object q is destroyed by this * resolve_res_search call. The query object q is destroyed by this
* call and may not be used any further. Returns a pointer to the * call and may not be used any further. Returns a pointer to the
* answer of the res_query call. If the query is not completed yet * answer of the res_query call. If the query is not completed yet
* -EAGAIN is returned, on failure -errno is returned, otherwise the * -EAGAIN is returned, on failure -errno is returned, otherwise the
* length of answer is returned. Make sure to free the answer is a * length of answer is returned. Make sure to free the answer is a
* call to sd_resolv_freeanswer(). */ * call to sd_resolve_freeanswer(). */
int sd_resolv_res_done(sd_resolv_t *resolv, sd_resolv_query_t* q, unsigned char **answer); int sd_resolve_res_done(sd_resolve_t *resolve, sd_resolve_query_t* q, unsigned char **answer);
/** Return the next completed query object. If no query has been /** Return the next completed query object. If no query has been
* completed yet, return NULL. Please note that you need to run * completed yet, return NULL. Please note that you need to run
* sd_resolv_wait() before this function will return sensible data. */ * sd_resolve_wait() before this function will return sensible data. */
sd_resolv_query_t* sd_resolv_getnext(sd_resolv_t *resolv); sd_resolve_query_t* sd_resolve_getnext(sd_resolve_t *resolve);
/** Return the number of query objects (completed or not) attached to /** Return the number of query objects (completed or not) attached to
* this session */ * this session */
int sd_resolv_getnqueries(sd_resolv_t *resolv); int sd_resolve_getnqueries(sd_resolve_t *resolve);
/** Cancel a currently running query. q is is destroyed by this call /** Cancel a currently running query. q is is destroyed by this call
* and may not be used any futher. */ * and may not be used any futher. */
void sd_resolv_cancel(sd_resolv_t *resolv, sd_resolv_query_t* q); void sd_resolve_cancel(sd_resolve_t *resolve, sd_resolve_query_t* q);
/** Free the addrinfo structure as returned by /** Free the addrinfo structure as returned by
* sd_resolv_getaddrinfo_done(). Make sure to use this functions instead * sd_resolve_getaddrinfo_done(). Make sure to use this functions instead
* of the libc's freeaddrinfo()! */ * of the libc's freeaddrinfo()! */
void sd_resolv_freeaddrinfo(struct addrinfo *ai); void sd_resolve_freeaddrinfo(struct addrinfo *ai);
/** Free the answer data as returned by sd_resolv_res_done().*/ /** Free the answer data as returned by sd_resolve_res_done().*/
void sd_resolv_freeanswer(unsigned char *answer); void sd_resolve_freeanswer(unsigned char *answer);
/** Returns non-zero when the query operation specified by q has been completed */ /** Returns non-zero when the query operation specified by q has been completed */
int sd_resolv_isdone(sd_resolv_t *resolv, sd_resolv_query_t*q); int sd_resolve_isdone(sd_resolve_t *resolve, sd_resolve_query_t*q);
/** Assign some opaque userdata with a query object */ /** Assign some opaque userdata with a query object */
void sd_resolv_setuserdata(sd_resolv_t *resolv, sd_resolv_query_t *q, void *userdata); void sd_resolve_setuserdata(sd_resolve_t *resolve, sd_resolve_query_t *q, void *userdata);
/** Return userdata assigned to a query object. Use /** Return userdata assigned to a query object. Use
* sd_resolv_setuserdata() to set this data. If no data has been set * sd_resolve_setuserdata() to set this data. If no data has been set
* prior to this call it returns NULL. */ * prior to this call it returns NULL. */
void* sd_resolv_getuserdata(sd_resolv_t *resolv, sd_resolv_query_t *q); void* sd_resolve_getuserdata(sd_resolve_t *resolve, sd_resolve_query_t *q);
_SD_END_DECLARATIONS; _SD_END_DECLARATIONS;