diff --git a/dns/GNUmakefile b/dns/GNUmakefile index 04cc8c7..7041ff3 100644 --- a/dns/GNUmakefile +++ b/dns/GNUmakefile @@ -10,4 +10,11 @@ clean: distclean: clean rm -f *.d +cfg/%: + $(MAKE) -C cfg all + +gethostbyname: gethostbyname.o hstrerror.o + +hstrerror.o: cfg/have_hstrerror.h + -include *.d diff --git a/dns/cfg/GNUmakefile b/dns/cfg/GNUmakefile new file mode 100644 index 0000000..f925f23 --- /dev/null +++ b/dns/cfg/GNUmakefile @@ -0,0 +1,4 @@ +all: have_hstrerror.h + +%.h: %.sh + CC='$(CC)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' sh $^ > $@ diff --git a/dns/cfg/have_hstrerror.sh b/dns/cfg/have_hstrerror.sh new file mode 100644 index 0000000..9af42cb --- /dev/null +++ b/dns/cfg/have_hstrerror.sh @@ -0,0 +1,11 @@ +cat > has_hstrerror_$$.c < +int main(void) { hstrerror(0); } +EOF +if $CC $CFLAGS has_hstrerror_$$.c $LDFLAGS -o has_hstrerror_$$ +then + echo '#define HAVE_HSTRERROR 1' +else + echo '#define HAVE_HSTRERROR 0' +fi +rm has_hstrerror_$$.c has_hstrerror_$$ diff --git a/dns/gethostbyname.c b/dns/gethostbyname.c index 74cf781..45af0df 100644 --- a/dns/gethostbyname.c +++ b/dns/gethostbyname.c @@ -1,5 +1,8 @@ #include #include +#include + +#include "hstrerror.h" char *cmnd; @@ -36,7 +39,7 @@ int main(int argc, char **argv) { } for (a = he->h_addr_list; *a; a++) { int j; - printf("\tAddress: "); + printf("\tAddress: "); for (j = 0; j < he->h_length; j++) { printf("%s%d", j ? "." : "", (unsigned char)(*a)[j]); } diff --git a/dns/hstrerror.c b/dns/hstrerror.c new file mode 100644 index 0000000..2fc552e --- /dev/null +++ b/dns/hstrerror.c @@ -0,0 +1,11 @@ +#include "cfg/have_hstrerror.h" +#include "hstrerror.h" + +#if (!HAVE_HSTRERROR) +const char *hstrerror(int err) { + static char errstr[80]; + + snprintf(errstr, sizeof(errstr), "resolver error %d", err); + return errstr; +} +#endif diff --git a/dns/hstrerror.h b/dns/hstrerror.h new file mode 100644 index 0000000..aa0fd90 --- /dev/null +++ b/dns/hstrerror.h @@ -0,0 +1 @@ +const char * hstrerror(int err);