]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nameserv: prepare for asynchronous resolving
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 23 Apr 2014 14:04:47 +0000 (16:04 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 29 Apr 2014 10:07:38 +0000 (12:07 +0200)
Introduce a new function with callback to resolve names to IP addresses
asynchronously. For now, use a blocking wrapper around DNS_Name2IPAddress.

Makefile.in
nameserv_async.c [new file with mode: 0644]
nameserv_async.h [new file with mode: 0644]

index 010d03fc5d5c068010bbbd3b20ad2faa63aef085..5ea20fcb3daf1665f6cacc7a638611d09f5b0800 100644 (file)
@@ -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)
diff --git a/nameserv_async.c b/nameserv_async.c
new file mode 100644 (file)
index 0000000..b11da86
--- /dev/null
@@ -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);
+}
+
+/* ================================================== */
diff --git a/nameserv_async.h b/nameserv_async.h
new file mode 100644 (file)
index 0000000..5c1704e
--- /dev/null
@@ -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