浏览代码

* Eliminated dependancy on dns.mod and libresolv (wasn't even being used)

svn: 1433
Bryan Drewery 21 年之前
父节点
当前提交
4cf81065ee
共有 14 个文件被更改,包括 8 次插入2433 次删除
  1. 2 2
      Makefile.in
  2. 1 2
      autotools/configure.ac
  3. 1 1
      autotools/includes/depend.m4
  4. 0 89
      autotools/includes/dns.m4
  5. 2 987
      configure
  6. 0 1
      src/Makefile.in
  7. 0 2
      src/cmds.c
  8. 2 3
      src/dns.c
  9. 0 2
      src/main.c
  10. 0 2
      src/mod/Makefile.in
  11. 0 32
      src/mod/dns.mod/Makefile.in
  12. 0 1115
      src/mod/dns.mod/coredns.c
  13. 0 131
      src/mod/dns.mod/dns.c
  14. 0 64
      src/mod/dns.mod/dns.h

+ 2 - 2
Makefile.in

@@ -29,8 +29,8 @@ CCDEBUG = @DISTCC@ @CCDEBUG@
 LDDEBUG = @DISTCC@ @CCDEBUG@
 STRIP = @STRIP@
 
-#LIBS = @LIBS@ @ZLIB@ @SSL@ @RESLIB@
-LIBS = @LIBS@ @ZLIB@ @RESLIB@
+#LIBS = @LIBS@ @ZLIB@ @SSL@ 
+LIBS = @LIBS@ @ZLIB@ 
 
 DEBCXXFLAGS = -DDEBUG_ASSERT -DDEBUG_MEM -Dinline= -fno-inline -g3 -ggdb3
 CFLGS = @GCC3@

+ 1 - 2
autotools/configure.ac

@@ -49,7 +49,6 @@ AC_CHECK_PROG(DISTCC, distcc, distcc)
 
 # Test the os and set the module linking settings
 EGG_CHECK_OS
-EGG_CHECK_DNS
 
 # Check for IPv6 support
 #EGG_IPV6_SUPPORTED
@@ -157,5 +156,5 @@ EGG_SUBST_VERSION
 EGG_SUBST_MOD_UPDIR
 DO_DEPS
 
-AC_CONFIG_FILES([Makefile src/Makefile src/compat/Makefile src/crypto/Makefile src/mod/Makefile src/mod/dns.mod/Makefile])
+AC_CONFIG_FILES([Makefile src/Makefile src/compat/Makefile src/crypto/Makefile src/mod/Makefile])
 AC_OUTPUT

+ 1 - 1
autotools/includes/depend.m4

@@ -18,7 +18,7 @@ AC_SUBST(GCC3)dnl
 
 AC_DEFUN([DO_DEPS],
 [
-files="src/Makefile.in src/compat/Makefile.in src/crypto/Makefile.in src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/dns.mod/Makefile.in src/mod/irc.mod/Makefile src/mod/notes.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/transfer.mod/Makefile src/mod/update.mod/Makefile"
+files="src/Makefile.in src/compat/Makefile.in src/crypto/Makefile.in src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/irc.mod/Makefile src/mod/notes.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/transfer.mod/Makefile src/mod/update.mod/Makefile"
 for mf in $files; do
   # Strip MF so we end up with the name of the file.
 #  echo "MF: $mf"

+ 0 - 89
autotools/includes/dns.m4

@@ -1,89 +0,0 @@
-dnl  EGG_CHECK_DNS()
-dnl
-AC_DEFUN(EGG_CHECK_DNS, [dnl
-
-dns_reslib_avail="true"
-AC_CHECK_FUNC(res_init, ,
-  AC_CHECK_LIB(resolv, res_init, RESLIB="-lresolv",
-    AC_CHECK_LIB(bind, res_init, RESLIB="-lbind", [dnl
-      dns_reslib_avail="false";
-    ])dnl
-  )dnl
-)dnl
-
-if test "${dns_reslib_avail}" = false; then
-  dns_reslib_avail="true"
-  AC_CHECK_FUNC(__res_init, ,
-    AC_CHECK_LIB(resolv, __res_init, RESLIB="-lresolv",
-      AC_CHECK_LIB(bind, __res_init, RESLIB="-lbind", [dnl
-        dns_reslib_avail="false";
-      ])dnl
-    )dnl
-  )dnl
-fi
-
-AC_CHECK_FUNC(res_mkquery, ,
-  AC_CHECK_LIB(resolv, res_mkquery, [dnl
-    if test "x${RESLIB}" != "x-lresolv"; then
-      RESLIB="${RESLIB} -lresolv"
-    fi
-  ],
-    AC_CHECK_LIB(bind, res_mkquery, [dnl
-      if test "x${RESLIB}" != "x-lbind"; then
-        RESLIB="${RESLIB} -lbind"
-      fi
-    ], [dnl
-      dns_reslib_avail="false";
-    ])
-  )
-)
-
-if test "${dns_reslib_avail}" = false; then
-dns_reslib_avail="true" 
-AC_CHECK_FUNC(__res_mkquery, ,
-  AC_CHECK_LIB(resolv, __res_mkquery, [dnl
-    if test "x${RESLIB}" != "x-lresolv"; then
-      RESLIB="${RESLIB} -lresolv"
-    fi
-  ],
-    AC_CHECK_LIB(bind, __res_mkquery, [dnl
-      if test "x${RESLIB}" != "x-lbind"; then
-        RESLIB="${RESLIB} -lbind"
-      fi
-    ], [dnl
-      dns_reslib_avail="false";
-    ])
-  )
-)
-fi
-
-if test "${dns_reslib_avail}" = false; then
-  if test "$ac_cv_cygwin" = "yes"; then
-    AC_MSG_CHECKING(for /usr/local/bind/lib/libbind.a)
-    if test -r /usr/local/bind/lib/libbind.a; then
-      AC_MSG_RESULT(yes)
-      RESLIB="${RESLIB} -L/usr/local/bind/lib -lbind"
-      RESINCLUDE="-I/usr/local/bind/include"
-      dns_reslib_avail="true"
-    else
-      AC_MSG_RESULT(no)
-    fi
-  fi
-fi
-
-if test "${dns_reslib_avail}" = false; then
-  cat >&2 <<EOF
-configure: warning:
-
-  Your system provides no functional resolver library. 
-  One is required for buld.
-
-EOF
-  exit 1
-fi
-
-AC_SUBST(RESLIB)
-AC_SUBST(RESINCLUDE)
-])dnl
-
-

文件差异内容过多而无法显示
+ 2 - 987
configure


+ 0 - 1
src/Makefile.in

@@ -52,7 +52,6 @@ OBJS = auth.o \
 MODOBJS = mod/channels.o \
         mod/console.o \
         mod/ctcp.o \
-        mod/dns.o \
         mod/irc.o \
         mod/notes.o \
         mod/server.o \

+ 0 - 2
src/cmds.c

@@ -1094,7 +1094,6 @@ static void cmd_channels(int idx, char *par) {
 }
 
 
-int dns_report(int, int);  
 void channels_report(int, int);
 void transfer_report(int, int);
 void share_report(int, int);
@@ -1119,7 +1118,6 @@ static void cmd_status(int idx, char *par)
     putlog(LOG_CMDS, "*", "#%s# status", dcc[idx].nick);
     tell_verbose_status(idx);
   }
-  dns_report(idx, all);  
 #ifdef LEAF
   server_report(idx, all);
   irc_report(idx, all);

+ 2 - 3
src/dns.c

@@ -11,7 +11,6 @@
 #include "main.h"
 #include "net.h"
 #include "misc.h"
-#include "src/mod/dns.mod/dns.h"
 #include <netdb.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -150,7 +149,7 @@ void dcc_dnsipbyhost(char *hostn)
   de->res_data.hostname = strdup(hostn);
 
   /* Send request. */
-  dns_ipbyhost(hostn);
+//  dns_ipbyhost(hostn);
 }
 
 void dcc_dnshostbyip(in_addr_t ip)
@@ -177,7 +176,7 @@ void dcc_dnshostbyip(in_addr_t ip)
   de->res_data.ip_addr = ip;
 
   /* Send request. */
-  dns_hostbyip(ip);
+//  dns_hostbyip(ip);
 }
 
 

+ 0 - 2
src/main.c

@@ -668,7 +668,6 @@ int init_dcc_max(), init_userent(), init_auth(), init_config(), init_party(),
 
 static char *fake_md5 = "596a96cc7bf9108cd896f33c44aedc8a";
 
-void dns_init();
 void console_init();
 void ctcp_init();
 void update_init();
@@ -787,7 +786,6 @@ printf("out: %s\n", out);
     }
   }
 
-  dns_init();
   egg_dns_init();
 
   channels_init();

+ 0 - 2
src/mod/Makefile.in

@@ -21,7 +21,6 @@ LIBS = @LIBS@
 mods = channels.mod \
 	console.mod \
 	ctcp.mod \
-	dns.mod \
 	irc.mod \
 	notes.mod \
 	server.mod \
@@ -32,7 +31,6 @@ mods = channels.mod \
 mod_objs = channels.mod_o \
 	console.mod_o \
 	ctcp.mod_o \
-	dns.mod_o \
 	irc.mod_o \
 	notes.mod_o \
 	server.mod_o \

+ 0 - 32
src/mod/dns.mod/Makefile.in

@@ -1,32 +0,0 @@
-# Makefile for src/mod/dns.mod/
-
-RESINCLUDE = @RESINCLUDE@
-srcdir = .
-depcomp = /bin/sh ../../../autotools/depcomp
-
-#This line is simply for configure to generate .deps/
-OBJS = dns.o
-
-include ./.deps/includes
-
-doofus:
-	@echo ""
-	@echo "Let's try this from the right directory..."
-	@echo ""
-	@cd ../../../ && make
-
-static: ../dns.o
-
-../dns.o:
-	@echo -e "Compiling: \033[1mdns\033[0m"
-	source='dns.c' object='$@' depfile='.deps/dns.Po' tmpdepfile='.deps/dns.TPo' depmode=$(CCDEPMODE) $(depcomp) \
-	$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(RESINCLUDE) -c $(srcdir)/dns.c
-	@rm -f ../dns.o
-	@mv dns.o ../
-
-
-clean:
-	@rm -f .depend *.o *~
-
-distclean: clean
-

+ 0 - 1115
src/mod/dns.mod/coredns.c

@@ -1,1115 +0,0 @@
-/*
- * dnscore.c -- part of dns.mod
- *   This file contains all core functions needed for the eggdrop dns module.
- *   Many of them are only minimaly modified from the original source.
- *
- * Modified/written by Fabian Knittel <fknittel@gmx.de>
- *
- */
-
-/*
- * Borrowed from mtr  --  a network diagnostic tool
- * Copyright (C) 1997,1998  Matt Kimball <mkimball@xmission.com>
- * Released under the GPL, as above.
- *
- * Non-blocking DNS portion --
- * Copyright (C) 1998  Simon Kirby <sim@neato.org>
- * Released under the GPL, as above.
- */
-
-#include "src/net.h"
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <errno.h>
-
-
-/* Defines */
-
-#define BASH_SIZE	 8192		/* Size of hash tables */
-#define HOSTNAMELEN 	  255		/* From RFC */
-#define RES_RETRYDELAY      3
-#define RES_MAXSENDS        4
-#define RES_FAILEDDELAY   600		/* TTL for failed records (in
-					   seconds). */
-#define RES_MAX_TTL     86400		/* Maximum TTL (in seconds). */
-
-#define RES_ERR "DNS Resolver error: "
-#define RES_MSG "DNS Resolver: "
-#define RES_WRN "DNS Resolver warning: "
-
-#define MAX_PACKETSIZE (PACKETSZ)
-#define MAX_DOMAINLEN (MAXDNAME)
-
-/* Macros */
-
-#define nonull(s) (s) ? s : nullstring
-#define BASH_MODULO(x) ((x) & 8191)	/* Modulo for hash table size */
-
-/* Non-blocking nameserver interface routines */
-
-#ifdef DEBUG_DNS
-#  define RESPONSECODES_COUNT 6
-static char *responsecodes[RESPONSECODES_COUNT + 1] = {
-    "no error",
-    "format error in query",
-    "server failure",
-    "queried domain name does not exist",
-    "requested query type not implemented",
-    "refused by name server",
-    "unknown error",
-};
-#endif /* DEBUG_DNS */
-
-#ifdef DEBUG_DNS
-#  define RESOURCETYPES_COUNT 18
-static const char *resourcetypes[RESOURCETYPES_COUNT + 1] = {
-    "unknown type",
-    "A: host address",
-    "AAAA: host address v6",
-    "NS: authoritative name server",
-    "MD: mail destination (OBSOLETE)",
-    "MF: mail forwarder (OBSOLETE)",
-    "CNAME: name alias",
-    "SOA: authority record",
-    "MB: mailbox domain name (EXPERIMENTAL)",
-    "MG: mail group member (EXPERIMENTAL)",
-    "MR: mail rename domain name (EXPERIMENTAL)",
-    "NULL: NULL RR (EXPERIMENTAL)",
-    "WKS: well known service description",
-    "PTR: domain name pointer",
-    "HINFO: host information",
-    "MINFO: mailbox or mail list information",
-    "MX: mail exchange",
-    "TXT: text string",
-    "unknown type",
-};
-#endif /* DEBUG_DNS */
-
-#ifdef DEBUG_DNS
-#  define CLASSTYPES_COUNT 5
-static const char *classtypes[CLASSTYPES_COUNT + 1] = {
-    "unknown class",
-    "IN: the Internet",
-    "CS: CSNET (OBSOLETE)",
-    "CH: CHAOS",
-    "HS: Hesoid [Dyer 87]",
-    "unknown class"
-};
-#endif /* DEBUG_DNS */
-
-typedef struct {
-    u_16bit_t	id;			/* Packet id */
-    u_8bit_t	databyte_a;
-    /* rd:1				recursion desired
-     * tc:1				truncated message
-     * aa:1				authoritive answer
-     * opcode:4				purpose of message
-     * qr:1				response flag
-     */
-    u_8bit_t	databyte_b;
-    /* rcode:4				response code
-     * unassigned:2			unassigned bits
-     * pr:1				primary server required (non standard)
-     * ra:1				recursion available
-     */
-    u_16bit_t	qdcount;		/* Query record count */
-    u_16bit_t	ancount;		/* Answer record count */
-    u_16bit_t	nscount;		/* Authority reference record count */
-    u_16bit_t	arcount;		/* Resource reference record count */
-} packetheader;
-
-#ifndef HFIXEDSZ
-#define HFIXEDSZ (sizeof(packetheader))
-#endif
-
-/*
- * Byte order independent macros for packetheader
- */
-#define getheader_rd(x) (x->databyte_a & 1)
-#define getheader_tc(x) ((x->databyte_a >> 1) & 1)
-#define getheader_aa(x) ((x->databyte_a >> 2) & 1)
-#define getheader_opcode(x) ((x->databyte_a >> 3) & 15)
-#define getheader_qr(x) (x->databyte_a >> 7)
-#define getheader_rcode(x) (x->databyte_b & 15)
-#define getheader_pr(x) ((x->databyte_b >> 6) & 1)
-#define getheader_ra(x) (x->databyte_b >> 7)
-
-#define sucknetword(x)  ((x)+=2,((u_16bit_t)  (((x)[-2] <<  8) | ((x)[-1] <<  0))))
-#define sucknetshort(x) ((x)+=2,((short) (((x)[-2] <<  8) | ((x)[-1] <<  0))))
-#define sucknetdword(x) ((x)+=4,((dword) (((x)[-4] << 24) | ((x)[-3] << 16) | \
-                                          ((x)[-2] <<  8) | ((x)[-1] <<  0))))
-#define sucknetlong(x)  ((x)+=4,((long)  (((x)[-4] << 24) | ((x)[-3] << 16) | \
-                                          ((x)[-2] <<  8) | ((x)[-1] <<  0))))
-
-
-static u_32bit_t resrecvbuf[(MAX_PACKETSIZE + 7) >> 2];	/* MUST BE DWORD ALIGNED */
-
-static struct resolve *idbash[BASH_SIZE];
-static struct resolve *ipbash[BASH_SIZE];
-static struct resolve *hostbash[BASH_SIZE];
-static struct resolve *expireresolves = NULL;
-
-static in_addr_t localhost;
-
-static long idseed = 0xdeadbeef;
-static long aseed;
-
-static int resfd;
-
-static char tempstring[512] = "";
-static char namestring[1024 + 1] = "";
-static char stackstring[1024 + 1] = "";
-
-#ifdef DEBUG_DNS
-static char sendstring[1024 + 1] = "";
-#endif /* DEBUG_DNS */
-
-static const char nullstring[] = "";
-
-
-/*
- *    Miscellaneous helper functions
- */
-
-#ifdef DEBUG_DNS
-/* Displays the time difference passed in signeddiff.
- */
-static char *strtdiff(char *d, long signeddiff)
-{
-    u_32bit_t diff;
-    u_32bit_t seconds, minutes, hours;
-    long day;
-
-    if ((diff = labs(signeddiff))) {
-	seconds = diff % 60;
-	diff /= 60;
-	minutes = diff % 60;
-	diff /= 60;
-	hours = diff % 24;
-	day = signeddiff / 86400;
-	if (day)
-	    sprintf(d, "%lid", day);
-	else
-	    *d = '\0';
-	if (hours)
-	    sprintf(d + strlen(d), "%uh", hours);
-	if (minutes)
-	    sprintf(d + strlen(d), "%um", minutes);
-	if (seconds)
-	    sprintf(d + strlen(d), "%us", seconds);
-    } else
-	sprintf(d, "0s");
-    return d;
-}
-#endif /* DEBUG_DNS */
-
-/* Allocate memory to hold one resolve request structure.
- */
-static struct resolve *allocresolve()
-{
-    struct resolve *rp = NULL;
-
-    rp = (struct resolve *) calloc(1, sizeof(struct resolve));
-    return rp;
-}
-
-/*
- *    Hash and linked-list related functions
- */
-
-/* Return the hash bucket number for id.
- */
-inline static u_32bit_t getidbash(u_16bit_t id)
-{
-    return (u_32bit_t) BASH_MODULO(id);
-}
-
-/* Return the hash bucket number for ip.
- */
-inline static u_32bit_t getipbash(in_addr_t ip)
-{
-    return (u_32bit_t) BASH_MODULO(ip);
-}
-
-/* Return the hash bucket number for host.
- */
-static u_32bit_t gethostbash(char *host)
-{
-    u_32bit_t bashvalue = 0;
-
-    for (; *host; host++) {
-	bashvalue ^= *host;
-	bashvalue += (*host >> 1) + (bashvalue >> 1);
-    }
-    return BASH_MODULO(bashvalue);
-}
-
-/* Insert request structure addrp into the id hash table.
- */
-static void linkresolveid(struct resolve *addrp)
-{
-    struct resolve *rp = NULL;
-    u_32bit_t bashnum;
-
-    bashnum = getidbash(addrp->id);
-    rp = idbash[bashnum];
-    if (rp) {
-	while ((rp->nextid) && (addrp->id > rp->nextid->id))
-	    rp = rp->nextid;
-	while ((rp->previousid) && (addrp->id < rp->previousid->id))
-	    rp = rp->previousid;
-	if (rp->id < addrp->id) {
-	    addrp->previousid = rp;
-	    addrp->nextid = rp->nextid;
-	    if (rp->nextid)
-		rp->nextid->previousid = addrp;
-	    rp->nextid = addrp;
-	} else if (rp->id > addrp->id) {
-	    addrp->previousid = rp->previousid;
-	    addrp->nextid = rp;
-	    if (rp->previousid)
-		rp->previousid->nextid = addrp;
-	    rp->previousid = addrp;
-	} else		/* Trying to add the same id! */
-	    return;
-    } else
-	addrp->nextid = addrp->previousid = NULL;
-    idbash[bashnum] = addrp;
-}
-
-/* Remove request structure rp from the id hash table.
- */
-static void unlinkresolveid(struct resolve *rp)
-{
-    u_32bit_t bashnum;
-
-    bashnum = getidbash(rp->id);
-    if (idbash[bashnum] == rp) {
-	if (rp->previousid)
-	    idbash[bashnum] = rp->previousid;
-	else
-	    idbash[bashnum] = rp->nextid;
-    }
-    if (rp->nextid)
-	rp->nextid->previousid = rp->previousid;
-    if (rp->previousid)
-	rp->previousid->nextid = rp->nextid;
-}
-
-/* Insert request structure addrp into the host hash table.
- */
-static void linkresolvehost(struct resolve *addrp)
-{
-    struct resolve *rp = NULL;
-    u_32bit_t bashnum;
-    int ret;
-
-    bashnum = gethostbash(addrp->hostn);
-    rp = hostbash[bashnum];
-    if (rp) {
-	while ((rp->nexthost) &&
-	       (egg_strcasecmp(addrp->hostn, rp->nexthost->hostn) < 0))
-	    rp = rp->nexthost;
-	while ((rp->previoushost) &&
-	       (egg_strcasecmp(addrp->hostn, rp->previoushost->hostn) > 0))
-	    rp = rp->previoushost;
-	ret = egg_strcasecmp(addrp->hostn, rp->hostn);
-	if (ret < 0) {
-	    addrp->previoushost = rp;
-	    addrp->nexthost = rp->nexthost;
-	    if (rp->nexthost)
-		rp->nexthost->previoushost = addrp;
-	    rp->nexthost = addrp;
-	} else if (ret > 0) {
-	    addrp->previoushost = rp->previoushost;
-	    addrp->nexthost = rp;
-	    if (rp->previoushost)
-		rp->previoushost->nexthost = addrp;
-	    rp->previoushost = addrp;
-	} else		/* Trying to add the same host! */
-	    return;
-    } else
-	addrp->nexthost = addrp->previoushost = NULL;
-    hostbash[bashnum] = addrp;
-}
-
-/* Remove request structure rp from the host hash table.
- */
-static void unlinkresolvehost(struct resolve *rp)
-{
-    u_32bit_t bashnum;
-
-    bashnum = gethostbash(rp->hostn);
-    if (hostbash[bashnum] == rp) {
-	if (rp->previoushost)
-	    hostbash[bashnum] = rp->previoushost;
-	else
-	    hostbash[bashnum] = rp->nexthost;
-    }
-    if (rp->nexthost)
-	rp->nexthost->previoushost = rp->previoushost;
-    if (rp->previoushost)
-	rp->previoushost->nexthost = rp->nexthost;
-    free(rp->hostn);
-}
-
-/* Insert request structure addrp into the ip hash table.
- */
-static void linkresolveip(struct resolve *addrp)
-{
-    struct resolve *rp = NULL;
-    u_32bit_t bashnum;
-
-    bashnum = getipbash(addrp->ip);
-    rp = ipbash[bashnum];
-    if (rp) {
-	while ((rp->nextip) && (addrp->ip > rp->nextip->ip))
-	    rp = rp->nextip;
-	while ((rp->previousip) && (addrp->ip < rp->previousip->ip))
-	    rp = rp->previousip;
-	if (rp->ip < addrp->ip) {
-	    addrp->previousip = rp;
-	    addrp->nextip = rp->nextip;
-	    if (rp->nextip)
-		rp->nextip->previousip = addrp;
-	    rp->nextip = addrp;
-	} else if (rp->ip > addrp->ip) {
-	    addrp->previousip = rp->previousip;
-	    addrp->nextip = rp;
-	    if (rp->previousip)
-		rp->previousip->nextip = addrp;
-	    rp->previousip = addrp;
-	} else		/* Trying to add the same ip! */
-	    return;
-    } else
-	addrp->nextip = addrp->previousip = NULL;
-    ipbash[bashnum] = addrp;
-}
-
-/* Remove request structure rp from the ip hash table.
- */
-static void unlinkresolveip(struct resolve *rp)
-{
-    u_32bit_t bashnum;
-
-    bashnum = getipbash(rp->ip);
-    if (ipbash[bashnum] == rp) {
-	if (rp->previousip)
-	    ipbash[bashnum] = rp->previousip;
-	else
-	    ipbash[bashnum] = rp->nextip;
-    }
-    if (rp->nextip)
-	rp->nextip->previousip = rp->previousip;
-    if (rp->previousip)
-	rp->previousip->nextip = rp->nextip;
-}
-
-/* Add request structure rp to the expireresolves list. Entries are sorted
- * by expire time.
- */
-static void linkresolve(struct resolve *rp)
-{
-    struct resolve *irp = NULL;
-
-    if (expireresolves) {
-	irp = expireresolves;
-	while ((irp->next) && (rp->expiretime >= irp->expiretime))
-	    irp = irp->next;
-	if (rp->expiretime >= irp->expiretime) {
-	    rp->next = NULL;
-	    rp->previous = irp;
-	    irp->next = rp;
-	} else {
-	    rp->previous = irp->previous;
-	    rp->next = irp;
-	    if (irp->previous)
-		irp->previous->next = rp;
-	    else
-		expireresolves = rp;
-	    irp->previous = rp;
-	}
-    } else {
-	rp->next = NULL;
-	rp->previous = NULL;
-	expireresolves = rp;
-    }
-}
-
-/* Remove reqeust structure rp from the expireresolves list.
- */
-static void untieresolve(struct resolve *rp)
-{
-    if (rp->previous)
-	rp->previous->next = rp->next;
-    else
-	expireresolves = rp->next;
-    if (rp->next)
-	rp->next->previous = rp->previous;
-}
-
-/* Remove request structure rp from all lists and hash tables and
- * then delete and free the structure
- */
-static void unlinkresolve(struct resolve *rp)
-{
-
-    untieresolve(rp);		/* Not really needed. Left in to be on the
-				   safe side. */
-    unlinkresolveid(rp);
-    unlinkresolveip(rp);
-    if (rp->hostn)
-	unlinkresolvehost(rp);
-    free(rp);
-}
-
-/* Find request structure using the id.
- */
-static struct resolve *findid(u_16bit_t id)
-{
-    struct resolve *rp = NULL;
-    int bashnum;
-
-    bashnum = getidbash(id);
-    rp = idbash[bashnum];
-    if (rp) {
-	while ((rp->nextid) && (id >= rp->nextid->id))
-	    rp = rp->nextid;
-	while ((rp->previousid) && (id <= rp->previousid->id))
-	    rp = rp->previousid;
-	if (id == rp->id) {
-	    idbash[bashnum] = rp;
-	    return rp;
-	} else
-	    return NULL;
-    }
-    return rp;			/* NULL */
-}
-
-/* Find request structure using the host.
- */
-static struct resolve *findhost(char *hostn)
-{
-    struct resolve *rp = NULL;
-    int bashnum;
-
-    bashnum = gethostbash(hostn);
-    rp = hostbash[bashnum];
-    if (rp) {
-	while ((rp->nexthost)
-	       && (egg_strcasecmp(hostn, rp->nexthost->hostn) >= 0))
-	    rp = rp->nexthost;
-	while ((rp->previoushost)
-	       && (egg_strcasecmp(hostn, rp->previoushost->hostn) <= 0))
-	    rp = rp->previoushost;
-	if (egg_strcasecmp(hostn, rp->hostn))
-	    return NULL;
-	else {
-	    hostbash[bashnum] = rp;
-	    return rp;
-	}
-    }
-    return rp;			/* NULL */
-}
-
-/* Find request structure using the ip.
- */
-static struct resolve *findip(in_addr_t ip)
-{
-    struct resolve *rp = NULL;
-    u_32bit_t bashnum;
-
-    bashnum = getipbash(ip);
-    rp = ipbash[bashnum];
-    if (rp) {
-	while ((rp->nextip) && (ip >= rp->nextip->ip))
-	    rp = rp->nextip;
-	while ((rp->previousip) && (ip <= rp->previousip->ip))
-	    rp = rp->previousip;
-	if (ip == rp->ip) {
-	    ipbash[bashnum] = rp;
-	    return rp;
-	} else
-	    return NULL;
-    }
-    return rp;			/* NULL */
-}
-
-
-/*
- *    Network and resolver related functions
- */
-
-/* Create packet for the request and send it to all available nameservers.
- */
-static void dorequest(char *s, int type, u_16bit_t id)
-{
-    packetheader *hp = NULL;
-    int r, i;
-    u_8bit_t buf[(MAX_PACKETSIZE / sizeof(char)) + 1];
-
-    r = res_mkquery(QUERY, s, C_IN, type, NULL, 0, NULL, buf,
-		    MAX_PACKETSIZE);
-    if (r == -1) {
-	ddebug0(RES_ERR "Query too large.");
-	return;
-    }
-    hp = (packetheader *) buf;
-    hp->id = id;	/* htons() deliberately left out (redundant) */
-    for (i = 0; i < _res.nscount; i++)
-	(void) sendto(resfd, buf, r, 0,
-		      (struct sockaddr *) &_res.nsaddr_list[i],
-		      sizeof(struct sockaddr));
-}
-
-/* (Re-)send request with existing id.
- */
-static void resendrequest(struct resolve *rp, int type)
-{
-    rp->sends++;
-    /* Update expire time */
-    rp->expiretime = now + (RES_RETRYDELAY * rp->sends);
-    /* Add (back) to expire list */
-    linkresolve(rp);
-
-    if (type == T_A) {
-	dorequest(rp->hostn, type, rp->id);
-	ddebug1(RES_MSG "Sent domain lookup request for \"%s\".",
-		rp->hostn);
-    } else if (type == T_PTR) {
-	sprintf(tempstring, "%u.%u.%u.%u.in-addr.arpa",
-		((u_8bit_t *) & rp->ip)[3],
-		((u_8bit_t *) & rp->ip)[2],
-		((u_8bit_t *) & rp->ip)[1], ((u_8bit_t *) & rp->ip)[0]);
-	dorequest(tempstring, type, rp->id);
-	ddebug1(RES_MSG "Sent domain lookup request for \"%s\".",
-		iptostr(rp->ip));
-    }
-}
-
-/* Send request for the first time.
- */
-static void sendrequest(struct resolve *rp, int type)
-{
-    /* Create unique id */
-    do {
-	idseed = (((idseed + idseed) | (long) now)
-		  + idseed - 0x54bad4a) ^ aseed;
-	aseed ^= idseed;
-	rp->id = (u_16bit_t) idseed;
-    } while (findid(rp->id));
-    linkresolveid(rp);		/* Add id to id hash table */
-    resendrequest(rp, type);	/* Send request */
-}
-
-/* Gets called as soon as the request turns out to have failed. Calls
- * the eggdrop hook.
- */
-static void failrp(struct resolve *rp, int type)
-{
-    if (rp->state == STATE_FINISHED)
-	return;
-    rp->expiretime = now + RES_FAILEDDELAY;
-    rp->state = STATE_FAILED;
-
-    /* Expire time was changed, reinsert entry to maintain order */
-    untieresolve(rp);
-    linkresolve(rp);
-
-    ddebug0(RES_MSG "Lookup failed.");
-    dns_event_failure(rp, type);
-}
-
-/* Gets called as soon as the request turns out to be successful. Calls
- * the eggdrop hook.
- */
-static void passrp(struct resolve *rp, long ttl, int type)
-{
-    rp->state = STATE_FINISHED;
-
-    /* Do not cache entries for too long. */
-    if (ttl < RES_MAX_TTL)
-	rp->expiretime = now + (time_t) ttl;
-    else
-	rp->expiretime = now + RES_MAX_TTL;
-
-    /* Expire time was changed, reinsert entry to maintain order */
-    untieresolve(rp);
-    linkresolve(rp);
-
-    ddebug1(RES_MSG "Lookup successful: %s", rp->hostn);
-    dns_event_success(rp, type);
-}
-
-/* Parses the response packets received.
- */
-static void parserespacket(u_8bit_t *s, size_t l)
-{
-    struct resolve *rp = NULL;
-    packetheader *hp = NULL;
-    u_8bit_t *eob = NULL;
-    u_8bit_t *c = NULL;
-    long ttl;
-    int r, usefulanswer;
-    u_16bit_t rr, datatype, myclass, qdatatype, qclass;
-    u_8bit_t rdatalength;
-
-    if (l < sizeof(packetheader)) {
-	debug0(RES_ERR "Packet smaller than standard header size.");
-	return;
-    }
-    if (l == sizeof(packetheader)) {
-	debug0(RES_ERR "Packet has empty body.");
-	return;
-    }
-    hp = (packetheader *) s;
-    /* Convert data to host byte order
-     *
-     * hp->id does not need to be redundantly byte-order flipped, it
-     * is only echoed by nameserver
-     */
-    rp = findid(hp->id);
-    if (!rp)
-	return;
-    if ((rp->state == STATE_FINISHED) || (rp->state == STATE_FAILED))
-	return;
-    hp->qdcount = ntohs(hp->qdcount);
-    hp->ancount = ntohs(hp->ancount);
-    hp->nscount = ntohs(hp->nscount);
-    hp->arcount = ntohs(hp->arcount);
-    if (getheader_tc(hp)) {	/* Packet truncated */
-	ddebug0(RES_ERR "Nameserver packet truncated.");
-	return;
-    }
-    if (!getheader_qr(hp)) {	/* Not a reply */
-	ddebug0(RES_ERR "Query packet received on nameserver communication socket.");
-	return;
-    }
-    if (getheader_opcode(hp)) {	/* Not opcode 0 (standard query) */
-	ddebug0(RES_ERR "Invalid opcode in response packet.");
-	return;
-    }
-    eob = s + l;
-    c = s + HFIXEDSZ;
-    switch (getheader_rcode(hp)) {
-    case NOERROR:
-	if (hp->ancount) {
-	    ddebug4(RES_MSG
-		    "Received nameserver reply. (qd:%u an:%u ns:%u ar:%u)",
-		    hp->qdcount, hp->ancount, hp->nscount, hp->arcount);
-	    if (hp->qdcount != 1) {
-		ddebug0(RES_ERR "Reply does not contain one query.");
-		return;
-	    }
-	    if (c > eob) {
-		ddebug0(RES_ERR "Reply too short.");
-		return;
-	    }
-	    switch (rp->state) {	/* Construct expected query reply */
-	    case STATE_PTRREQ:
-		sprintf(stackstring,
-			"%u.%u.%u.%u.in-addr.arpa",
-			((u_8bit_t *) & rp->ip)[3],
-			((u_8bit_t *) & rp->ip)[2],
-			((u_8bit_t *) & rp->ip)[1], ((u_8bit_t *) & rp->ip)[0]);
-		break;
-	    case STATE_AREQ:
-		strncpy(stackstring, rp->hostn, 1024);
-	    }
-	    *namestring = '\0';
-	    r = dn_expand(s, s + l, c, namestring, MAXDNAME);
-	    if (r == -1) {
-		ddebug0(RES_ERR "dn_expand() failed while expanding query domain.");
-		return;
-	    }
-	    namestring[strlen(stackstring)] = '\0';
-	    if (egg_strcasecmp(stackstring, namestring)) {
-		ddebug2(RES_MSG "Unknown query packet dropped. (\"%s\" does not match \"%s\")", stackstring, namestring);
-		return;
-	    }
-	    ddebug1(RES_MSG "Queried domain name: \"%s\"", namestring);
-	    c += r;
-	    if (c + 4 > eob) {
-		ddebug0(RES_ERR "Query resource record truncated.");
-		return;
-	    }
-	    qdatatype = sucknetword(c);
-	    qclass = sucknetword(c);
-	    if (qclass != C_IN) {
-		ddebug2(RES_ERR "Received unsupported query class: %u (%s)",
-			qclass, qclass < CLASSTYPES_COUNT ?
-					classtypes[qclass] :
-					classtypes[CLASSTYPES_COUNT]);
-	    }
-	    switch (qdatatype) {
-	    case T_PTR:
-		if (!IS_PTR(rp)) {
-		    ddebug0(RES_WRN "Ignoring response with unexpected query type \"PTR\".");
-		    return;
-		}
-		break;
-	    case T_A:
-		if (!IS_A(rp)) {
-		    ddebug0(RES_WRN "Ignoring response with unexpected query type \"PTR\".");
-		    return;
-		}
-		break;
-	    default:
-		ddebug2(RES_ERR "Received unimplemented query type: %u (%s)",
-			qdatatype,
-			qdatatype < RESOURCETYPES_COUNT ?
-				resourcetypes[qdatatype] :
-				resourcetypes[RESOURCETYPES_COUNT]);
-	    }
-	    for (rr = hp->ancount + hp->nscount + hp->arcount; rr; rr--) {
-		if (c > eob) {
-		    ddebug0(RES_ERR "Packet does not contain all specified resouce records.");
-		    return;
-		}
-		*namestring = '\0';
-		r = dn_expand(s, s + l, c, namestring, MAXDNAME);
-		if (r == -1) {
-		    ddebug0(RES_ERR "dn_expand() failed while expanding answer domain.");
-		    return;
-		}
-		namestring[strlen(stackstring)] = '\0';
-		if (egg_strcasecmp(stackstring, namestring))
-		    usefulanswer = 0;
-		else
-		    usefulanswer = 1;
-		ddebug1(RES_MSG "answered domain query: \"%s\"", namestring);
-		c += r;
-		if (c + 10 > eob) {
-		    ddebug0(RES_ERR "Resource record truncated.");
-		    return;
-		}
-		datatype = sucknetword(c);
-		myclass = sucknetword(c);
-		ttl = sucknetlong(c);
-		rdatalength = sucknetword(c);
-		if (myclass != qclass) {
-		    ddebug2(RES_MSG "query class: %u (%s)",
-			    qclass,
-			    qclass < CLASSTYPES_COUNT ?
-				classtypes[qclass] :
-				classtypes[CLASSTYPES_COUNT]);
-		    ddebug2(RES_MSG "rr class: %u (%s)", myclass,
-			    myclass < CLASSTYPES_COUNT ?
-				classtypes[myclass] :
-				classtypes[CLASSTYPES_COUNT]);
-		    ddebug0(RES_ERR "Answered class does not match queried class.");
-		    return;
-		}
-		if (!rdatalength) {
-		    ddebug0(RES_ERR "Zero size rdata.");
-		    return;
-		}
-		if (c + rdatalength > eob) {
-		    ddebug0(RES_ERR "Specified rdata length exceeds packet size.");
-		    return;
-		}
-		if (datatype == qdatatype) {
-		    ddebug1(RES_MSG "TTL: %s", strtdiff(sendstring, ttl));
-		    ddebug1(RES_MSG "TYPE: %s", datatype < RESOURCETYPES_COUNT ?
-			    resourcetypes[datatype] :
-			    resourcetypes[RESOURCETYPES_COUNT]);
-		    if (usefulanswer)
-			switch (datatype) {
-			case T_A:
-			    if (rdatalength != 4) {
-				ddebug1(RES_ERR "Unsupported rdata format for \"A\" type. (%u bytes)", rdatalength);
-				return;
-			    }
-			    egg_memcpy(&rp->ip, (in_addr_t *) c, sizeof(in_addr_t));
-			    linkresolveip(rp);
-			    passrp(rp, ttl, T_A);
-			    return;
-			case T_PTR:
-			    *namestring = '\0';
-			    r =	dn_expand(s, s + l, c, namestring, MAXDNAME);
-			    if (r == -1) {
-				ddebug0(RES_ERR "dn_expand() failed while expanding domain in rdata.");
-				return;
-			    }
-			    ddebug1(RES_MSG "Answered domain: \"%s\"",
-				   namestring);
-			    if (r > HOSTNAMELEN) {
-				ddebug0(RES_ERR "Domain name too long.");
-				failrp(rp, T_PTR);
-				return;
-			    }
-			    if (!rp->hostn) {
-                                rp->hostn = strdup(namestring);
-				linkresolvehost(rp);
-				passrp(rp, ttl, T_PTR);
-				return;
-			    }
-			    break;
-			default:
-			    ddebug2(RES_ERR "Received unimplemented data type: %u (%s)",
-				    datatype,
-				    datatype < RESOURCETYPES_COUNT ?
-					resourcetypes[datatype] :
-					resourcetypes[RESOURCETYPES_COUNT]);
-			}
-		} else if (datatype == T_CNAME) {
-		    *namestring = '\0';
-		    r =	dn_expand(s, s + l, c, namestring, MAXDNAME);
-		    if (r == -1) {
-			ddebug0(RES_ERR "dn_expand() failed while expanding domain in rdata.");
-			return;
-		    }
-		    ddebug1(RES_MSG "answered domain is CNAME for: %s",
-			   namestring);
-		    /* The next responses will be related to the domain
-		     * pointed to by CNAME, so we need to update which
-		     * respones we regard as important.
-		     */
-		    strncpy(stackstring, namestring, 1024);
-		} else {
-		    ddebug2(RES_MSG "Ignoring resource type %u. (%s)",
-			   datatype, datatype < RESOURCETYPES_COUNT ?
-				resourcetypes[datatype] :
-				resourcetypes[RESOURCETYPES_COUNT]);
-		}
-		c += rdatalength;
-	    }
-	} else {
-	    ddebug0(RES_ERR "No error returned but no answers given.");
-        }
-	break;
-    case NXDOMAIN:
-	ddebug0(RES_MSG "Host not found.");
-	switch (rp->state) {
-	case STATE_PTRREQ:
-		failrp(rp, T_PTR);
-		break;
-	case STATE_AREQ:
-		failrp(rp, T_A);
-		break;
-	default:
-		failrp(rp, 0);
-		break;
-	}
-	break;
-    default:
-	ddebug2(RES_MSG "Received error response %u. (%s)",
-		getheader_rcode(hp),
-		getheader_rcode(hp) < RESPONSECODES_COUNT ?
-			responsecodes[getheader_rcode(hp)] :
-			responsecodes[RESPONSECODES_COUNT]);
-    }
-}
-
-/* Read data received on our dns socket. This function is called
- * as soon as traffic is detected.
- */
-static void dns_ack(void)
-{
-    struct sockaddr_in from;
-    unsigned int fromlen = sizeof(struct sockaddr_in);
-    int r, i;
-
-    r =	recvfrom(resfd, (u_8bit_t *) resrecvbuf, MAX_PACKETSIZE, 0,
-		 (struct sockaddr *) &from, &fromlen);
-    if (r <= 0) {
-	ddebug1(RES_MSG "Socket error: %s", strerror(errno));
-	return;
-    }
-    /* Check to see if this server is actually one we sent to */
-    if (from.sin_addr.s_addr == localhost) {
-        for (i = 0; i < _res.nscount; i++)
-	    /* 0.0.0.0 replies as 127.0.0.1 */
-	    if ((_res.nsaddr_list[i].sin_addr.s_addr == from.sin_addr.s_addr)
-		|| (!_res.nsaddr_list[i].sin_addr.s_addr))
-		break;
-    } else {
-        for (i = 0; i < _res.nscount; i++)
-	    if (_res.nsaddr_list[i].sin_addr.s_addr == from.sin_addr.s_addr)
-		break;
-    }
-    if (i == _res.nscount) {
-        ddebug1(RES_ERR "Received reply from unknown source: %s",
-	       iptostr(from.sin_addr.s_addr));
-    } else
-        parserespacket((u_8bit_t *) resrecvbuf, (size_t) r);
-}
-
-/* Remove or resend expired requests. Called once a second.
- */
-static void dns_check_expires(void)
-{
-    struct resolve *rp = NULL, *nextrp = NULL;
-
-    /* Walk through sorted list ... */
-    for (rp = expireresolves; (rp) && (now >= rp->expiretime);
-	 rp = nextrp) {
-	nextrp = rp->next;
-	untieresolve(rp);
-	switch (rp->state) {
-	case STATE_FINISHED:	/* TTL has expired */
-	case STATE_FAILED:	/* Fake TTL has expired */
-	    ddebug4(RES_MSG "Cache record for \"%s\" (%s) has expired. (state: %u)  Marked for expire at: %ld.",
-		   nonull(rp->hostn), iptostr(rp->ip), rp->state,
-		   rp->expiretime);
-	    unlinkresolve(rp);
-	    break;
-	case STATE_PTRREQ:	/* T_PTR send timed out */
-	    if (rp->sends <= RES_MAXSENDS) {
-	      ddebug1(RES_MSG "Resend #%d for \"PTR\" query...", rp->sends - 1);
-	      resendrequest(rp, T_PTR);
-	    } else {
-	      ddebug0(RES_MSG "\"PTR\" query timed out.");
-	      failrp(rp, T_PTR);
-	    }
-	    break;
-	case STATE_AREQ:	/* T_A send timed out */
-	    if (rp->sends <= RES_MAXSENDS) {
-	      ddebug1(RES_MSG "Resend #%d for \"A\" query...", rp->sends - 1);
-	      resendrequest(rp, T_A);
-	    } else {
-	      ddebug0(RES_MSG "\"A\" query timed out.");
-	      failrp(rp, T_A);
-	    }
-	    break;
-	default:		/* Unknown state, let it expire */
-	    ddebug1(RES_WRN "Unknown request state %d. Request expired.",
-		   rp->state);
-	    failrp(rp, 0);
-	}
-    }
-}
-
-/* Start searching for a host-name, using it's ip-address.
- */
-void dns_hostbyip(in_addr_t ip)
-{
-    struct resolve *rp = NULL;
-
-    ip = htonl(ip);
-    if ((rp = findip(ip))) {
-	if (rp->state == STATE_FINISHED || rp->state == STATE_FAILED) {
-	    if (rp->state == STATE_FINISHED && rp->hostn) {
-		ddebug2(RES_MSG "Used cached record: %s == \"%s\".",
-			    iptostr(ip), rp->hostn);
-		dns_event_success(rp, T_PTR);
-	    } else {
-		ddebug1(RES_MSG "Used failed record: %s == ???", iptostr(ip));
-		dns_event_failure(rp, T_PTR);
-	    }
-	}
-	return;
-    }
-
-    ddebug0(RES_MSG "Creating new record");
-    rp = allocresolve();
-    rp->state = STATE_PTRREQ;
-    rp->sends = 1;
-    rp->ip = ip;
-    linkresolveip(rp);
-    sendrequest(rp, T_PTR);
-}
-
-/* Start searching for an ip-address, using it's host-name.
- */
-void dns_ipbyhost(char *hostn)
-{
-    struct resolve *rp = NULL;
-    struct in_addr inaddr;
-
-    /* Check if someone passed us an IP address as hostname
-     * and return it straight away.
-     */
-    if (egg_inet_aton(hostn, &inaddr)) {
-      call_ipbyhost(hostn, ntohl(inaddr.s_addr), 1);
-      return;
-    }
-    if ((rp = findhost(hostn))) {
-	if (rp->state == STATE_FINISHED || rp->state == STATE_FAILED) {
-	    if (rp->state == STATE_FINISHED && rp->ip) {
-		ddebug2(RES_MSG "Used cached record: %s == \"%s\".", hostn,
-		       iptostr(rp->ip));
-		dns_event_success(rp, T_A);
-	    } else {
-		ddebug1(RES_MSG "Used failed record: %s == ???", hostn);
-		dns_event_failure(rp, T_A);
-	    }
-	}
-	return;
-    }
-    ddebug0(RES_MSG "Creating new record");
-    rp = allocresolve();
-    rp->state = STATE_AREQ;
-    rp->sends = 1;
-    rp->hostn = strdup(hostn);
-    linkresolvehost(rp);
-    sendrequest(rp, T_A);
-}
-
-/* Initialise the network.
- */
-static int init_dns_network(void)
-{
-    int option;
-    struct in_addr inaddr;
-
-    resfd = socket(AF_INET, SOCK_DGRAM, 0);
-    if (resfd == -1) {
-	putlog(LOG_MISC, "*",
-		"Unable to allocate socket for nameserver communication: %s",
-		strerror(errno));
-	return 0;
-    }
-    (void) allocsock(resfd, SOCK_PASS);
-    option = 1;
-    if (setsockopt(resfd, SOL_SOCKET, SO_BROADCAST, (char *) &option,
-	 sizeof(option))) {
-	putlog(LOG_MISC, "*",
-		"Unable to setsockopt() on nameserver communication socket: %s",
-		strerror(errno));
-	killsock(resfd);
-	return 0;
-    }
-
-    egg_inet_aton("127.0.0.1", &inaddr);
-    localhost = inaddr.s_addr;
-    return 1;
-}
-
-/* Initialise the core dns system, returns 1 if all goes well, 0 if not.
- */
-static int init_dns_core(void)
-{
-    int i;
-
-    /* Initialise the resolv library. */
-    res_init();
-    if (!_res.nscount) {
-	putlog(LOG_MISC, "*", "No nameservers defined.");
-	return 0;
-    }
-
-    for (i = 0; i < _res.nscount; i++) {
-      char s[102] = "";
-      egg_inet_ntop(AF_INET, &_res.nsaddr_list[i].sin_addr, s, 101);
-      sdprintf("added ns: %s", s);
-      _res.nsaddr_list[i].sin_family = AF_INET;
-    }
-
-
-    if (!init_dns_network())
-	return 0;
-
-    /* Initialise the hash tables. */
-    aseed = time(NULL) ^ (time(NULL) << 3) ^ (u_32bit_t) getpid();
-    for (i = 0; i < BASH_SIZE; i++) {
-	idbash[i] = NULL;
-	ipbash[i] = NULL;
-	hostbash[i] = NULL;
-    }
-    expireresolves = NULL;
-    return 1;
-}

+ 0 - 131
src/mod/dns.mod/dns.c

@@ -1,131 +0,0 @@
-/*
- * dns.c -- part of dns.mod
- *   domain lookup glue code for eggdrop
- *
- * Written by Fabian Knittel <fknittel@gmx.de>
- *
- */
-
-#include "dns.h"
-#include "src/common.h"
-#include "src/dccutil.h"
-#include "src/main.h"
-#include "src/egg_timer.h"
-#include "src/types.h"
-
-static void dns_event_success(struct resolve *rp, int type);
-static void dns_event_failure(struct resolve *rp, int type);
-
-
-#include "coredns.c"
-
-/*
- *    DNS event related code
- */
-
-static void dns_event_success(struct resolve *rp, int type)
-{
-  if (!rp)
-    return;
-
-  if (type == T_PTR) {
-    debug2("DNS resolved %s to %s", iptostr(rp->ip), rp->hostn);
-    call_hostbyip(ntohl(rp->ip), rp->hostn, 1);
-  } else if (type == T_A) {
-    debug2("DNS resolved %s to %s", rp->hostn, iptostr(rp->ip));
-    call_ipbyhost(rp->hostn, ntohl(rp->ip), 1);
-  }
-}
-
-static void dns_event_failure(struct resolve *rp, int type)
-{
-  if (!rp)
-    return;
-
-  if (type == T_PTR) {
-    static char s[UHOSTLEN];
-
-    debug1("DNS resolve failed for %s", iptostr(rp->ip));
-    strcpy(s, iptostr(rp->ip));
-    call_hostbyip(ntohl(rp->ip), s, 0);
-  } else if (type == T_A) {
-    debug1("DNS resolve failed for %s", rp->hostn);
-    call_ipbyhost(rp->hostn, 0, 0);
-  } else
-    debug2("DNS resolve failed for unknown %s / %s", iptostr(rp->ip),
-	   nonull(rp->hostn));
-  return;
-}
-
-
-/*
- *    DNS Socket related code
- */
-
-static void eof_dns_socket(int idx)
-{
-  putlog(LOG_MISC, "*", "DNS Error: socket closed.");
-  killsock(dcc[idx].sock);
-  /* Try to reopen socket */
-  if (init_dns_network()) {
-    putlog(LOG_MISC, "*", "DNS socket successfully reopened!");
-    dcc[idx].sock = resfd;
-    dcc[idx].timeval = now;
-  } else
-    lostdcc(idx);
-}
-
-static void dns_socket(int idx, char *buf, int len)
-{
-  dns_ack();
-}
-
-static void display_dns_socket(int idx, char *buf)
-{
-  strcpy(buf, "dns   (ready)");
-}
-
-static struct dcc_table DCC_DNS =
-{
-  "DNS",
-  DCT_LISTEN,
-  eof_dns_socket,
-  dns_socket,
-  NULL,
-  NULL,
-  display_dns_socket,
-  NULL,
-  NULL,
-  NULL
-};
-
-
-/*
- *    DNS module related code
- */
-
-int dns_report(int idx, int details)
-{
-  if (details) {
-    dprintf(idx, "    DNS resolver is active.\n");
-  }
-  return 0;
-}
-
-void dns_init()
-{
-  int idx;
-
-  idx = new_dcc(&DCC_DNS, 0);
-  if (idx < 0)
-    fatal("NO MORE DCC CONNECTIONS -- Can't create DNS socket.", 1);
-  if (!init_dns_core()) {
-    lostdcc(idx);
-    fatal("DNS initialisation failed.", 1);
-  }
-  dcc[idx].sock = resfd;
-  dcc[idx].timeval = now;
-  strcpy(dcc[idx].nick, "(dns)");
-
-  timer_create_secs(1, "dns_check_expires", (Function) dns_check_expires);
-}

+ 0 - 64
src/mod/dns.mod/dns.h

@@ -1,64 +0,0 @@
-/*
- * dns.h -- part of dns.mod
- *   dns module header file
- *
- * Written by Fabian Knittel <fknittel@gmx.de>
- *
- */
-
-/*
- * Borrowed from mtr  --  a network diagnostic tool
- * Copyright (C) 1997,1998  Matt Kimball <mkimball@xmission.com>
- * Released under GPL, as above.
- *
- * Non-blocking DNS portion --
- * Copyright (C) 1998  Simon Kirby <sim@neato.org>
- * Released under GPL, as above.
- */
-
-#ifndef _EGG_MOD_DNS_DNS_H
-#define _EGG_MOD_DNS_DNS_H
-
-#include "src/common.h"
-#include "src/types.h"
-
-struct resolve {
-    struct resolve	*next;
-    struct resolve	*previous;
-    struct resolve	*nextid;
-    struct resolve	*previousid;
-    struct resolve	*nextip;
-    struct resolve	*previousip;
-    struct resolve	*nexthost;
-    struct resolve	*previoushost;
-    time_t		expiretime;
-    char		*hostn;
-    in_addr_t			ip;
-    u_16bit_t		id;
-    u_8bit_t		state;
-    u_8bit_t		sends;
-};
-
-enum resolve_states {
-    STATE_FINISHED,
-    STATE_FAILED,
-    STATE_PTRREQ,
-    STATE_AREQ
-};
-
-#define IS_PTR(x) (x->state == STATE_PTRREQ)
-#define IS_A(x)   (x->state == STATE_AREQ)
-
-#define DEBUG_DNS 1
-
-#define ddebug0(x) sdprintf(x)
-#define ddebug1(x, x1) sdprintf(x, x1)
-#define ddebug2(x, x1, x2) sdprintf(x, x1, x2)
-#define ddebug3(x, x1, x2, x3) sdprintf(x, x1, x2, x3)
-#define ddebug4(x, x1, x2, x3, x4) sdprintf(x, x1, x2, x3, x4)
-
-int dns_report(int, int);
-void dns_hostbyip(in_addr_t);
-void dns_ipbyhost(char *);
-
-#endif	/* _EGG_MOD_DNS_DNS_H */

部分文件因为文件数量过多而无法显示