changeset 200:116b0269c934

reworked resolvtest; let it build; refactored in lookup.c the resolvtest helper and code test tool was available in the code but did not get built I moved it to resolvtest.c and included it into the build process the define RESOLV_TEST was removed
author meillo@marmaro.de
date Fri, 16 Jul 2010 12:53:07 +0200
parents a8855df82650
children 138e66e1a61f
files src/Makefile.am src/Makefile.in src/lookup.c src/lookup.h src/resolvtest.c
diffstat 5 files changed, 131 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.am	Fri Jul 16 12:39:14 2010 +0200
+++ b/src/Makefile.am	Fri Jul 16 12:53:07 2010 +0200
@@ -4,7 +4,7 @@
 
 sbin_PROGRAMS=masqmail
 bin_PROGRAMS=mservdetect
-noinst_PROGRAMS=smtpsend readtest
+noinst_PROGRAMS=smtpsend readtest resolvtest
 
 masqmail_SOURCES=\
 	dotlock.h\
@@ -76,7 +76,12 @@
 	readsock.h\
 	readtest.c
 
+resolvtest_SOURCES=\
+	resolvtest.c\
+	lookup.c
+
 masqmail_LDADD=@RESOLV_LIBS@ @GLIB_LIBS@ @LOCKFILE_LIBS@ @MD5_LIBS@ @BASE64_LIBS@ @IDENT_LIBS@
 smtpsend_LDADD=@RESOLV_LIBS@ @GLIB_LIBS@ @MD5_LIBS@ @BASE64_LIBS@
 mservdetect_LDADD=@GLIB_LIBS@
 readtest_LDADD=@GLIB_LIBS@
+resolvtest_LDADD=@RESOLV_LIBS@ @GLIB_LIBS@ @IDENT_LIBS@
--- a/src/Makefile.in	Fri Jul 16 12:39:14 2010 +0200
+++ b/src/Makefile.in	Fri Jul 16 12:53:07 2010 +0200
@@ -34,7 +34,8 @@
 POST_UNINSTALL = :
 sbin_PROGRAMS = masqmail$(EXEEXT)
 bin_PROGRAMS = mservdetect$(EXEEXT)
-noinst_PROGRAMS = smtpsend$(EXEEXT) readtest$(EXEEXT)
+noinst_PROGRAMS = smtpsend$(EXEEXT) readtest$(EXEEXT) \
+	resolvtest$(EXEEXT)
 subdir = src
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -67,6 +68,9 @@
 am_readtest_OBJECTS = readsock.$(OBJEXT) readtest.$(OBJEXT)
 readtest_OBJECTS = $(am_readtest_OBJECTS)
 readtest_DEPENDENCIES =
+am_resolvtest_OBJECTS = resolvtest.$(OBJEXT) lookup.$(OBJEXT)
+resolvtest_OBJECTS = $(am_resolvtest_OBJECTS)
+resolvtest_DEPENDENCIES =
 am_smtpsend_OBJECTS = smtpsend.$(OBJEXT) accept.$(OBJEXT) \
 	address.$(OBJEXT) child.$(OBJEXT) connect.$(OBJEXT) \
 	header.$(OBJEXT) interface.$(OBJEXT) lookup.$(OBJEXT) \
@@ -83,9 +87,9 @@
 CCLD = $(CC)
 LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
 SOURCES = $(masqmail_SOURCES) $(mservdetect_SOURCES) \
-	$(readtest_SOURCES) $(smtpsend_SOURCES)
+	$(readtest_SOURCES) $(resolvtest_SOURCES) $(smtpsend_SOURCES)
 DIST_SOURCES = $(masqmail_SOURCES) $(mservdetect_SOURCES) \
-	$(readtest_SOURCES) $(smtpsend_SOURCES)
+	$(readtest_SOURCES) $(resolvtest_SOURCES) $(smtpsend_SOURCES)
 RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
 	html-recursive info-recursive install-data-recursive \
 	install-dvi-recursive install-exec-recursive \
@@ -303,10 +307,15 @@
 	readsock.h\
 	readtest.c
 
+resolvtest_SOURCES = \
+	resolvtest.c\
+	lookup.c
+
 masqmail_LDADD = @RESOLV_LIBS@ @GLIB_LIBS@ @LOCKFILE_LIBS@ @MD5_LIBS@ @BASE64_LIBS@ @IDENT_LIBS@
 smtpsend_LDADD = @RESOLV_LIBS@ @GLIB_LIBS@ @MD5_LIBS@ @BASE64_LIBS@
 mservdetect_LDADD = @GLIB_LIBS@
 readtest_LDADD = @GLIB_LIBS@
+resolvtest_LDADD = @RESOLV_LIBS@ @GLIB_LIBS@ @IDENT_LIBS@
 all: all-recursive
 
 .SUFFIXES:
@@ -427,6 +436,9 @@
 readtest$(EXEEXT): $(readtest_OBJECTS) $(readtest_DEPENDENCIES) 
 	@rm -f readtest$(EXEEXT)
 	$(LINK) $(readtest_OBJECTS) $(readtest_LDADD) $(LIBS)
+resolvtest$(EXEEXT): $(resolvtest_OBJECTS) $(resolvtest_DEPENDENCIES) 
+	@rm -f resolvtest$(EXEEXT)
+	$(LINK) $(resolvtest_OBJECTS) $(resolvtest_LDADD) $(LIBS)
 smtpsend$(EXEEXT): $(smtpsend_OBJECTS) $(smtpsend_DEPENDENCIES) 
 	@rm -f smtpsend$(EXEEXT)
 	$(LINK) $(smtpsend_OBJECTS) $(smtpsend_LDADD) $(LIBS)
@@ -463,6 +475,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/queue.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readsock.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readtest.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resolvtest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rewrite.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/route.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smtp_in.Po@am__quote@
--- a/src/lookup.c	Fri Jul 16 12:39:14 2010 +0200
+++ b/src/lookup.c	Fri Jul 16 12:53:07 2010 +0200
@@ -22,11 +22,6 @@
 
 #include "masqmail.h"
 
-#ifdef RESOLV_TEST
-#undef DEBUG
-#define DEBUG(x) if(x > 0)
-#define debugf g_print
-#endif
 
 #ifdef ENABLE_RESOLVER
 
@@ -198,35 +193,39 @@
 }
 */
 
-static int
+int
 dns_look_ip(gchar * domain, guint32 * ip)
 {
 	gchar *n = domain;
 
 	while (TRUE) {
-		if (dns_resolve(n, T_A, FALSE) == 0) {
-			dns_next();
-			if (rr_type == T_A) {
-				if (rr_dlen < 4)
-					return -1;  /* soft */
-				*ip = *(guint32 *) (resp_pos);
+		if (dns_resolve(n, T_A, FALSE) != 0) {
+			return -1;
+		}
 
-				DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
+		dns_next();
+		if (rr_type == T_A) {
+			if (rr_dlen < 4) {
+				return -1;  /* soft */
+			}
+			*ip = *(guint32 *) (resp_pos);
+
+			DEBUG(5) debugf("DNS: dns_look_ip(): ip = %s\n", inet_ntoa(*(struct in_addr *) ip));
 
-				resp_pos += rr_dlen;
-				return 0;
-			} else if (rr_type == T_CNAME) {
-				if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0)
-					return -1;
+			resp_pos += rr_dlen;
+			return 0;
+		} else if (rr_type == T_CNAME) {
+			if (dn_expand(response.buf, resp_end, resp_pos, name, MAX_DNSNAME) < 0) {
+				return -1;
+			}
 
-				DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name);
+			DEBUG(5) debugf("DNS: (CNAME) dns_look_ip(): name = %s\n", name);
 
-				resp_pos += rr_dlen;
-				n = name;
-			} else
-				return -1;
-		} else
+			resp_pos += rr_dlen;
+			n = name;
+		} else {
 			return -1;
+		}
 	}
 }
 
@@ -333,35 +332,3 @@
 	}
 	return list;
 }
-
-#ifdef RESOLV_TEST
-int
-main(int argc, char *argv[])
-{
-	GList *addr_list = NULL, *node;
-
-	g_print("starting res_init()\n");
-	g_print("retrans = %d, retry = %d\n", _res.retrans, _res.retry);
-	if (res_init() == 0) {
-		addr_list = resolve_dns_a(NULL, argv[1]);
-		g_print("A:\n");
-		foreach(addr_list, node) {
-			mxip_addr *p_mxip = (mxip_addr *) (node->data);
-			printf("name = %s\n IP = %s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)));
-		}
-		addr_list = resolve_dns_mx(NULL, argv[1]);
-		g_print("MX:\n");
-		foreach(addr_list, node) {
-			mxip_addr *p_mxip = (mxip_addr *) (node->data);
-			printf("name = %s\n IP = %s pref = %d\n", p_mxip->name,
-			       inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref);
-		}
-		{
-			guint32 ip;
-			dns_look_ip(argv[1], &ip);
-			printf("dns_look_ip: %s\n", inet_ntoa(*((struct in_addr *) (&ip))));
-		}
-	} else
-		printf("res_init() failed.\n");
-}
-#endif
--- a/src/lookup.h	Fri Jul 16 12:39:14 2010 +0200
+++ b/src/lookup.h	Fri Jul 16 12:53:07 2010 +0200
@@ -30,3 +30,4 @@
 GList *resolve_dns_a(GList * list, gchar * domain);
 GList *resolve_dns_mx(GList * list, gchar * domain);
 GList *resolve_byname(GList * list, gchar * domain);
+int dns_look_ip(gchar * domain, guint32 * ip);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/resolvtest.c	Fri Jul 16 12:53:07 2010 +0200
@@ -0,0 +1,85 @@
+/* MasqMail Copyright (C) Oliver Kurth,
+/* Copyright (C) 2010 markus schnalke <meillo@marmaro.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <resolv.h>
+
+#include "masqmail.h"
+
+
+masqmail_conf conf;
+
+
+void
+debugf(const char *fmt, ...)
+{
+	va_list args;
+	va_start(args, fmt);
+
+	vfprintf(stdout, fmt, args);
+
+	va_end(args);
+
+}
+
+
+int
+main(int argc, char *argv[])
+{
+	GList *addr_list = NULL, *node;
+
+	conf.debug_level = -1;  /* no debug messages */
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: resolvtest HOSTNAME\n");
+		return 1;
+	}
+
+	if (res_init() != 0) {
+		printf("res_init() failed.\n");
+		return 1;
+	}
+
+	printf("A:\n");
+	addr_list = resolve_dns_a(NULL, argv[1]);
+	foreach(addr_list, node) {
+		mxip_addr *p_mxip = (mxip_addr *) (node->data);
+		printf("%s  \t%s\n", p_mxip->name, inet_ntoa(*(struct in_addr *) &(p_mxip->ip)));
+	}
+
+	printf("\nMX:\n");
+	addr_list = resolve_dns_mx(NULL, argv[1]);
+	foreach(addr_list, node) {
+		mxip_addr *p_mxip = (mxip_addr *) (node->data);
+		printf("%s  \t%s  %d\n", p_mxip->name,
+		       inet_ntoa(*(struct in_addr *) &(p_mxip->ip)), p_mxip->pref);
+	}
+
+	printf("\nIP resolved directly (assumed FQDN, no default domain added):\n");
+	{
+		guint32 ip;
+		if (dns_look_ip(argv[1], &ip) >= 0) {
+			printf("%s\n", inet_ntoa(*((struct in_addr *) (&ip))));
+		}
+	}
+
+	return 0;
+}