summaryrefslogtreecommitdiff
path: root/zwgc
diff options
context:
space:
mode:
authorGravatar Greg Hudson <ghudson@mit.edu>1998-09-02 21:45:09 +0000
committerGravatar Greg Hudson <ghudson@mit.edu>1998-09-02 21:45:09 +0000
commitbaee3bd5f3b357e10fb27f6ae4021dbcb68fff40 (patch)
tree76df97c871109a9f4b9bdc2da39c81a0fd8acdc6 /zwgc
parenta37c099d4b2633186993127d647ad2285af62fa9 (diff)
Use libares for reverse resolution if HAVE_ARES is defined.
Diffstat (limited to 'zwgc')
-rw-r--r--zwgc/main.c75
-rw-r--r--zwgc/main.h6
-rw-r--r--zwgc/mux.c31
-rw-r--r--zwgc/notice.c16
-rw-r--r--zwgc/zephyr.c11
5 files changed, 111 insertions, 28 deletions
diff --git a/zwgc/main.c b/zwgc/main.c
index 0cc5145..e79c1b0 100644
--- a/zwgc/main.c
+++ b/zwgc/main.c
@@ -13,11 +13,16 @@
*/
#include <sysdep.h>
+#ifdef HAVE_ARES
+#include <ares.h>
+#endif
#if (!defined(lint) && !defined(SABER))
static const char rcsid_main_c[] = "$Id$";
#endif
+#include <netdb.h>
+#include <sys/socket.h>
#include <sys/resource.h>
#include <zephyr/mit-copyright.h>
#include <zephyr/zephyr.h>
@@ -37,7 +42,10 @@ static const char rcsid_main_c[] = "$Id$";
#include "main.h"
extern void notice_handler();
-static void setup_signals(), detach(), signal_exit();
+static void process_notice(), setup_signals(), detach(), signal_exit();
+#ifdef HAVE_ARES
+static void notice_callback();
+#endif
/*
* Global zwgc-wide variables:
@@ -73,6 +81,14 @@ char *subscriptions_filename_override = NULL;
char *location_override = NULL;
+#ifdef HAVE_ARES
+/*
+ * achannel - <<<>>> export!
+ */
+
+ares_channel achannel;
+#endif
+
/****************************************************************************/
/* */
/* Code to deal with reading in the description file: */
@@ -116,7 +132,7 @@ static void fake_startup_packet()
notice.z_message = msgbuf;
notice.z_message_len = strlen(notice.z_message)+1;
- notice_handler(&notice);
+ process_notice(&notice, NULL);
}
static void read_in_description_file()
@@ -206,6 +222,10 @@ int main(argc, argv)
char **new;
register char **current;
int dofork = 1;
+#ifdef HAVE_ARES
+ char *errmem;
+ int status;
+#endif
progname = argv[0];
@@ -245,6 +265,19 @@ int main(argc, argv)
}
*new = *current;
+#ifdef HAVE_ARES
+ /*
+ * Initialize resolver library
+ */
+ status = ares_init(&achannel);
+ if (status != ARES_SUCCESS) {
+ fprintf(stderr, "Couldn't initialize resolver: %s\n",
+ ares_strerror(status, &errmem));
+ ares_free_errmem(errmem);
+ return(1);
+ }
+#endif
+
/*
* Initialize various subsystems in proper order:
*/
@@ -292,11 +325,47 @@ int main(argc, argv)
void notice_handler(notice)
ZNotice_t *notice;
{
+ struct hostent *fromhost = NULL;
+
+ if (notice->z_sender_addr.s_addr) {
+#ifdef HAVE_ARES
+ ares_gethostbyaddr(achannel, &(notice->z_sender_addr),
+ sizeof(notice->z_sender_addr), AF_INET,
+ notice_callback, notice);
+ return;
+#else
+ fromhost = gethostbyaddr((char *) &(notice->z_sender_addr),
+ sizeof(struct in_addr), AF_INET);
+#endif
+ }
+ process_notice(notice, fromhost ? fromhost->h_name : NULL);
+ ZFreeNotice(notice);
+ free(notice);
+}
+
+#ifdef HAVE_ARES
+static void notice_callback(arg, status, fromhost)
+ void *arg;
+ int status;
+ struct hostent *fromhost;
+{
+ ZNotice_t *notice = (ZNotice_t *) arg;
+
+ process_notice(notice, fromhost ? fromhost->h_name : NULL);
+ ZFreeNotice(notice);
+ free(notice);
+}
+#endif
+
+static void process_notice(notice, hostname)
+ ZNotice_t *notice;
+ char *hostname;
+{
char *control_opcode;
dprintf("Got a message\n");
- if (control_opcode = decode_notice(notice)) {
+ if (control_opcode = decode_notice(notice, hostname)) {
#ifdef DEBUG
printf("got control opcode <%s>.\n", control_opcode);
#endif
diff --git a/zwgc/main.h b/zwgc/main.h
index ef9146e..38ed1bd 100644
--- a/zwgc/main.h
+++ b/zwgc/main.h
@@ -19,6 +19,12 @@
#ifndef main_MODULE
#define main_MODULE
+#ifdef HAVE_ARES
+#include <ares.h>
+
+extern ares_channel achannel;
+#endif
+
extern char *progname;
extern char *subscriptions_filename_override;
extern char *location_override;
diff --git a/zwgc/mux.c b/zwgc/mux.c
index 221ae8b..a18d15b 100644
--- a/zwgc/mux.c
+++ b/zwgc/mux.c
@@ -25,6 +25,7 @@ static const char rcsid_mux_c[] = "$Id$";
/****************************************************************************/
#include <zephyr/zephyr.h>
+#include "main.h"
#include "mux.h"
#include "error.h"
#include "zwgc.h"
@@ -130,9 +131,9 @@ void mux_add_input_source(descriptor, handler, arg)
void mux_loop()
{
- int i;
- fd_set input_sources_copy;
- struct timeval tv;
+ int i, nfds;
+ fd_set inputs, outputs;
+ struct timeval tv, *tvp;
mux_end_loop_p = 0;
@@ -146,18 +147,28 @@ void mux_loop()
if (have_tty) {
tv.tv_sec = 10;
tv.tv_usec = 0;
+ tvp = &tv;
} else {
- tv.tv_sec = tv.tv_usec = 0;
+ tvp = NULL;
}
/*
* Do a select on all the file descriptors we care about to
* wait until at least one of them has input available:
*/
- input_sources_copy = input_sources;
+ inputs = input_sources;
+ FD_ZERO(&outputs);
+
+#ifdef HAVE_ARES
+ nfds = ares_fds(achannel, &inputs, &outputs);
+ if (nfds < max_source + 1)
+ nfds = max_source + 1;
+ tvp = ares_timeout(achannel, tvp, &tv);
+#else
+ nfds = max_source + 1;
+#endif
- i = select(max_source+1, &input_sources_copy, (fd_set *)0,
- (fd_set *)NULL, have_tty ? &tv : (struct timeval *)0);
+ i = select(nfds, &inputs, &outputs, NULL, tvp);
if (i == -1) {
if (errno == EINTR)
@@ -172,12 +183,16 @@ void mux_loop()
}
}
+#ifdef HAVE_ARES
+ ares_process(achannel, &inputs, &outputs);
+#endif
+
/*
* Call all input handlers whose corresponding file descriptors have
* input:
*/
for(i=0; i<=max_source; i++)
- if (FD_ISSET(i, &input_sources_copy) && input_handler[i]) {
+ if (FD_ISSET(i, &inputs) && input_handler[i]) {
#ifdef DEBUG
if (zwgc_debug)
fprintf(stderr,
diff --git a/zwgc/notice.c b/zwgc/notice.c
index 4e14946..60aec5c 100644
--- a/zwgc/notice.c
+++ b/zwgc/notice.c
@@ -27,8 +27,6 @@ static const char rcsid_notice_c[] = "$Id$";
/****************************************************************************/
#include <zephyr/zephyr.h>
-#include <netdb.h>
-#include <sys/socket.h>
#include <arpa/inet.h>
#include "new_memory.h"
#include "error.h"
@@ -252,12 +250,12 @@ static string z_auth_to_ascii(z_auth)
* Effects:
*/
-char *decode_notice(notice)
+char *decode_notice(notice, hostname)
ZNotice_t *notice;
+ char *hostname;
{
char *temp;
string time, notyear, year, date_string, time_string;
- struct hostent *fromhost;
/*
* Convert useful notice fields to ascii and store away in
@@ -309,14 +307,8 @@ char *decode_notice(notice)
/*
* Convert host notice sent from to ascii:
*/
- if (notice->z_sender_addr.s_addr) {
- fromhost = gethostbyaddr((char *) &(notice->z_sender_addr),
- sizeof(struct in_addr), AF_INET);
- var_set_variable("fromhost", fromhost ? fromhost->h_name :
- inet_ntoa(notice->z_sender_addr));
- } else {
- var_set_variable("fromhost", inet_ntoa(notice->z_sender_addr));
- }
+ var_set_variable("fromhost", hostname ? hostname :
+ inet_ntoa(notice->z_sender_addr));
/*
* Set $message to the message field of the notice with nulls changed
diff --git a/zwgc/zephyr.c b/zwgc/zephyr.c
index d15091b..e68f01a 100644
--- a/zwgc/zephyr.c
+++ b/zwgc/zephyr.c
@@ -77,7 +77,7 @@ static string get_zwgc_port_number_filename()
static void handle_zephyr_input(notice_handler)
void (*notice_handler)();
{
- ZNotice_t notice;
+ ZNotice_t *notice;
struct sockaddr_in from;
int complete_packets_ready;
@@ -89,11 +89,12 @@ static void handle_zephyr_input(notice_handler)
if (complete_packets_ready==0)
return;
- TRAP( ZReceiveNotice(&notice, &from), "while getting zephyr notice" );
+ notice = malloc(sizeof(ZNotice_t));
+
+ TRAP( ZReceiveNotice(notice, &from), "while getting zephyr notice" );
if (!error_code) {
- notice.z_auth = ZCheckAuthentication(&notice, &from);
- notice_handler(&notice);
- ZFreeNotice(&notice);
+ notice->z_auth = ZCheckAuthentication(notice, &from);
+ notice_handler(notice);
}
}
}