nameserv: prepare for asynchronous resolving
Introduce a new function with callback to resolve names to IP addresses asynchronously. For now, use a blocking wrapper around DNS_Name2IPAddress.
This commit is contained in:
parent
5ca8aa7840
commit
ed96b4d49d
3 changed files with 91 additions and 1 deletions
|
@ -42,7 +42,7 @@ OBJS = util.o sched.o regress.o local.o \
|
|||
sys.o main.o ntp_io.o ntp_core.o ntp_sources.o \
|
||||
sources.o sourcestats.o reference.o \
|
||||
logging.o conf.o cmdmon.o keys.o \
|
||||
nameserv.o manual.o addrfilt.o \
|
||||
nameserv.o nameserv_async.o manual.o addrfilt.o \
|
||||
cmdparse.o mkdirpp.o rtc.o pktlength.o clientlog.o \
|
||||
broadcast.o refclock.o refclock_phc.o refclock_pps.o \
|
||||
refclock_shm.o refclock_sock.o tempcomp.o $(HASH_OBJ)
|
||||
|
|
49
nameserv_async.c
Normal file
49
nameserv_async.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||
|
||||
**********************************************************************
|
||||
* Copyright (C) Miroslav Lichvar 2014
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
**********************************************************************
|
||||
|
||||
=======================================================================
|
||||
|
||||
Functions to asynchronously convert name to IP address
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "sysincl.h"
|
||||
|
||||
#include "nameserv_async.h"
|
||||
#include "logging.h"
|
||||
#include "util.h"
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
/* This is a blocking implementation used when nothing else is available */
|
||||
|
||||
void
|
||||
DNS_Name2IPAddressAsync(const char *name, DNS_NameResolveHandler handler, void *anything)
|
||||
{
|
||||
IPAddr addr;
|
||||
DNS_Status status;
|
||||
|
||||
status = DNS_Name2IPAddress(name, &addr);
|
||||
(handler)(status, &addr, anything);
|
||||
}
|
||||
|
||||
/* ================================================== */
|
41
nameserv_async.h
Normal file
41
nameserv_async.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
chronyd/chronyc - Programs for keeping computer clocks accurate.
|
||||
|
||||
**********************************************************************
|
||||
* Copyright (C) Miroslav Lichvar 2014
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of version 2 of the GNU General Public License as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
**********************************************************************
|
||||
|
||||
=======================================================================
|
||||
|
||||
Header for asynchronous nameserver functions
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GOT_NAMESERV_ASYNC_H
|
||||
#define GOT_NAMESERV_ASYNC_H
|
||||
|
||||
#include "nameserv.h"
|
||||
|
||||
/* Function type for callback to process the result */
|
||||
typedef void (*DNS_NameResolveHandler)(DNS_Status status, IPAddr *ip_addr, void *anything);
|
||||
|
||||
/* Request resolving of a name to IP address. The handler will be
|
||||
called when the result is available, but it may be also called
|
||||
directly from this function call. */
|
||||
extern void DNS_Name2IPAddressAsync(const char *name, DNS_NameResolveHandler handler, void *anything);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue