diff --git a/smmapdfw/libsmmapdfw/Makefile.am b/smmapdfw/libsmmapdfw/Makefile.am index 3e5d4c3..e0d1b42 100644 --- a/smmapdfw/libsmmapdfw/Makefile.am +++ b/smmapdfw/libsmmapdfw/Makefile.am @@ -2,8 +2,10 @@ include_HEADERS=containers_public.h queue.h smtp.h cfg.h count.h safe_write.h su lib_LTLIBRARIES = libsmmapdfw.la libsmmapdfw_la_SOURCES = cfg.c queue.c count.c safe_write.c config_public.c htdns.c smtp.c htmalloc.c stats.c htcache.c htbuffer.c libsmmapdfw_la_LIBADD = @BDB_LIBS@ -bin_PROGRAMS = htcachetest htbuffertest +bin_PROGRAMS = htcachetest htbuffertest htdnstest htcachetest_SOURCES = htcachetest.c htcachetest_LDADD = libsmmapdfw.la htbuffertest_SOURCES = htbuffertest.c htbuffertest_LDADD = libsmmapdfw.la +htdnstest_SOURCES = htdnstest.c +htdnstest_LDADD = libsmmapdfw.la diff --git a/smmapdfw/libsmmapdfw/Makefile.in b/smmapdfw/libsmmapdfw/Makefile.in index d754fc2..87d950d 100644 --- a/smmapdfw/libsmmapdfw/Makefile.in +++ b/smmapdfw/libsmmapdfw/Makefile.in @@ -91,11 +91,13 @@ include_HEADERS = containers_public.h queue.h smtp.h cfg.h count.h safe_write.h lib_LTLIBRARIES = libsmmapdfw.la libsmmapdfw_la_SOURCES = cfg.c queue.c count.c safe_write.c config_public.c htdns.c smtp.c htmalloc.c stats.c htcache.c htbuffer.c libsmmapdfw_la_LIBADD = @BDB_LIBS@ -bin_PROGRAMS = htcachetest htbuffertest +bin_PROGRAMS = htcachetest htbuffertest htdnstest htcachetest_SOURCES = htcachetest.c htcachetest_LDADD = libsmmapdfw.la htbuffertest_SOURCES = htbuffertest.c htbuffertest_LDADD = libsmmapdfw.la +htdnstest_SOURCES = htdnstest.c +htdnstest_LDADD = libsmmapdfw.la mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../config.h CONFIG_CLEAN_FILES = @@ -111,7 +113,8 @@ libsmmapdfw_la_DEPENDENCIES = libsmmapdfw_la_OBJECTS = cfg.lo queue.lo count.lo safe_write.lo \ config_public.lo htdns.lo smtp.lo htmalloc.lo stats.lo htcache.lo \ htbuffer.lo -bin_PROGRAMS = htcachetest$(EXEEXT) htbuffertest$(EXEEXT) +bin_PROGRAMS = htcachetest$(EXEEXT) htbuffertest$(EXEEXT) \ +htdnstest$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) htcachetest_OBJECTS = htcachetest.$(OBJEXT) @@ -120,6 +123,9 @@ htcachetest_LDFLAGS = htbuffertest_OBJECTS = htbuffertest.$(OBJEXT) htbuffertest_DEPENDENCIES = libsmmapdfw.la htbuffertest_LDFLAGS = +htdnstest_OBJECTS = htdnstest.$(OBJEXT) +htdnstest_DEPENDENCIES = libsmmapdfw.la +htdnstest_LDFLAGS = CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -136,10 +142,10 @@ TAR = tar GZIP_ENV = --best DEP_FILES = .deps/cfg.P .deps/config_public.P .deps/count.P \ .deps/htbuffer.P .deps/htbuffertest.P .deps/htcache.P \ -.deps/htcachetest.P .deps/htdns.P .deps/htmalloc.P .deps/queue.P \ -.deps/safe_write.P .deps/smtp.P .deps/stats.P -SOURCES = $(libsmmapdfw_la_SOURCES) $(htcachetest_SOURCES) $(htbuffertest_SOURCES) -OBJECTS = $(libsmmapdfw_la_OBJECTS) $(htcachetest_OBJECTS) $(htbuffertest_OBJECTS) +.deps/htcachetest.P .deps/htdns.P .deps/htdnstest.P .deps/htmalloc.P \ +.deps/queue.P .deps/safe_write.P .deps/smtp.P .deps/stats.P +SOURCES = $(libsmmapdfw_la_SOURCES) $(htcachetest_SOURCES) $(htbuffertest_SOURCES) $(htdnstest_SOURCES) +OBJECTS = $(libsmmapdfw_la_OBJECTS) $(htcachetest_OBJECTS) $(htbuffertest_OBJECTS) $(htdnstest_OBJECTS) all: all-redirect .SUFFIXES: @@ -251,6 +257,10 @@ htbuffertest$(EXEEXT): $(htbuffertest_OBJECTS) $(htbuffertest_DEPENDENCIES) @rm -f htbuffertest$(EXEEXT) $(LINK) $(htbuffertest_LDFLAGS) $(htbuffertest_OBJECTS) $(htbuffertest_LDADD) $(LIBS) +htdnstest$(EXEEXT): $(htdnstest_OBJECTS) $(htdnstest_DEPENDENCIES) + @rm -f htdnstest$(EXEEXT) + $(LINK) $(htdnstest_LDFLAGS) $(htdnstest_OBJECTS) $(htdnstest_LDADD) $(LIBS) + install-includeHEADERS: $(include_HEADERS) @$(NORMAL_INSTALL) $(mkinstalldirs) $(DESTDIR)$(includedir) diff --git a/smmapdfw/libsmmapdfw/htdns.c b/smmapdfw/libsmmapdfw/htdns.c index cf1f6eb..7c17241 100644 --- a/smmapdfw/libsmmapdfw/htdns.c +++ b/smmapdfw/libsmmapdfw/htdns.c @@ -72,7 +72,6 @@ static int get_domain_name(answer_t *answer, int offset, char **name) { name_buf = NULL; - while (0 != (len = answer->buf[offset++])) { if (0xC0 == (len & 0xC0)) { if (NULL != name) { /* if we don't need the result, we don't need to recurse, since a ... */ @@ -103,7 +102,8 @@ static int get_domain_name(answer_t *answer, int offset, char **name) { } } if (NULL != name) { - name_buf[strlen(name_buf)-1] = '\0'; /* remove the final dot */ + if (name_buf != NULL) /* we can do this of course only if there is something */ + name_buf[strlen(name_buf)-1] = '\0'; /* remove the final dot */ *name = name_buf; } return offset; @@ -112,6 +112,7 @@ static int get_domain_name(answer_t *answer, int offset, char **name) { static int get_mx_rdata(answer_t *answer, int offset, int len, mx_rdata_t **resp) { *resp = (mx_rdata_t*) htmalloc(sizeof(mx_rdata_t)); (*resp)->preference = get16(answer->buf, offset); + (*resp)->exchange = NULL; get_domain_name(answer, offset+2, &(*resp)->exchange); (*resp)->type = T_MX; @@ -135,6 +136,7 @@ static int get_a_rdata(answer_t *answer, int offset, int len, a_rdata_t **resp) static int get_cname_rdata(answer_t *answer, int offset, int len, cname_rdata_t **resp) { *resp = (cname_rdata_t*) htmalloc(sizeof(cname_rdata_t)); + (*resp)->cname = NULL; get_domain_name(answer, offset, &(*resp)->cname); (*resp)->type = T_CNAME; diff --git a/smmapdfw/libsmmapdfw/htdnstest.c b/smmapdfw/libsmmapdfw/htdnstest.c new file mode 100644 index 0000000..3a4c6d0 --- /dev/null +++ b/smmapdfw/libsmmapdfw/htdnstest.c @@ -0,0 +1,60 @@ +/* + Copyright (C) 2004,2005 Wolfgang Hottgenroth + + This file is part of smmapdfw. + + smmapdfw 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. + + smmapdfw 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 smmapdfw. If not, write to the Free Software Foundation, 59 + Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include + +#include "htdns.h" + + + + +int main(int argc, char **args) { + if (argc != 2) { + printf("give domain to test on commandline\n"); + exit(1); + } + + char *domain = args[1]; + + mx_rdata_t **mx_rdata = get_best_mx_rrs(domain); + if (mx_rdata == NULL) { + printf("no mx-rr found\n"); + } else { + mx_rdata_t **mx_rdata2; + for (mx_rdata2 = mx_rdata; *mx_rdata2 != NULL; mx_rdata2++) { + printf("--> %d, %s\n", (*mx_rdata2)->preference, (*mx_rdata2)->exchange); + } + + free_rrs((void**)mx_rdata); + } +} + + + + + +