mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:35:06 -05:00
nameserv: add support for returning multiple addresses
This commit is contained in:
@@ -37,12 +37,14 @@
|
||||
#ifdef USE_PTHREAD_ASYNCDNS
|
||||
#include <pthread.h>
|
||||
|
||||
#define MAX_ADDRESSES 16
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
struct DNS_Async_Instance {
|
||||
const char *name;
|
||||
DNS_Status status;
|
||||
IPAddr addr;
|
||||
IPAddr addresses[MAX_ADDRESSES];
|
||||
DNS_NameResolveHandler handler;
|
||||
void *arg;
|
||||
|
||||
@@ -59,7 +61,7 @@ start_resolving(void *anything)
|
||||
{
|
||||
struct DNS_Async_Instance *inst = (struct DNS_Async_Instance *)anything;
|
||||
|
||||
inst->status = DNS_Name2IPAddress(inst->name, &inst->addr);
|
||||
inst->status = DNS_Name2IPAddress(inst->name, inst->addresses, MAX_ADDRESSES);
|
||||
|
||||
/* Notify the main thread that the result is ready */
|
||||
if (write(inst->pipe[1], "", 1) < 0)
|
||||
@@ -74,6 +76,7 @@ static void
|
||||
end_resolving(void *anything)
|
||||
{
|
||||
struct DNS_Async_Instance *inst = (struct DNS_Async_Instance *)anything;
|
||||
int i;
|
||||
|
||||
if (pthread_join(inst->thread, NULL)) {
|
||||
LOG_FATAL(LOGF_Nameserv, "pthread_join() failed");
|
||||
@@ -85,7 +88,11 @@ end_resolving(void *anything)
|
||||
close(inst->pipe[0]);
|
||||
close(inst->pipe[1]);
|
||||
|
||||
(inst->handler)(inst->status, &inst->addr, inst->arg);
|
||||
for (i = 0; inst->status == DNS_Success && i < MAX_ADDRESSES &&
|
||||
inst->addresses[i].family != IPADDR_UNSPEC; i++)
|
||||
;
|
||||
|
||||
(inst->handler)(inst->status, i, inst->addresses, inst->arg);
|
||||
|
||||
Free(inst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user