X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=mxget.c;h=4529c223bea99e1abc838837d7dc88f8907df295;hb=d31db10231e9ed89f64fdf6e0fb7cae182aa377e;hp=5cc41064d6f7225687875287b5b9784bb76906a0;hpb=54ca6ff94a75ae09aad7d8a47cd6b55562f6cfe7;p=~andy%2Ffetchmail diff --git a/mxget.c b/mxget.c index 5cc41064..4529c223 100644 --- a/mxget.c +++ b/mxget.c @@ -1,14 +1,16 @@ /* * mxget.c -- fetch MX records for given DNS name * - * Copyright 1997 by Eric S. Raymond + * Copyright (C) 1996, 1997, 1998, 2000, 2002 by Eric S. Raymond + * Copyright (C) 2005, 2006, 2007 by Matthias Andree * For license terms, see the file COPYING in this directory. */ #include "config.h" -#ifdef HAVE_RES_SEARCH +#include "fetchmail.h" #include #include +#ifdef HAVE_RES_SEARCH #ifdef HAVE_NET_SOCKET_H #include #endif @@ -68,7 +70,7 @@ struct mxentry *getmxrecords(const char *name) n = res_search(name, C_IN,T_MX, (unsigned char *)&answer, sizeof(answer)); if (n == -1) return((struct mxentry *)NULL); - if (n > sizeof(answer)) + if ((size_t)n > sizeof(answer)) n = sizeof(answer); hp = (HEADER *)&answer; @@ -76,7 +78,7 @@ struct mxentry *getmxrecords(const char *name) eom = answer + n; h_errno = 0; for (qdcount = ntohs(hp->qdcount); qdcount--; cp += n + QFIXEDSZ) - if ((n = dn_skipname(cp, eom)) < 0) + if ((n = dn_skipname((unsigned char *)cp, (unsigned char *)eom)) < 0) return((struct mxentry *)NULL); buflen = sizeof(MXHostBuf) - 1; bp = MXHostBuf; @@ -84,7 +86,8 @@ struct mxentry *getmxrecords(const char *name) ancount = ntohs(hp->ancount); while (--ancount >= 0 && cp < eom) { - if ((n = dn_expand(answer, eom, cp, bp, buflen)) < 0) + if ((n = dn_expand((unsigned char *)answer, (unsigned char *)eom, + (unsigned char *)cp, bp, buflen)) < 0) break; cp += n; GETSHORT(type, cp); @@ -96,7 +99,8 @@ struct mxentry *getmxrecords(const char *name) continue; } GETSHORT(pref, cp); - if ((n = dn_expand(answer, eom, cp, bp, buflen)) < 0) + if ((n = dn_expand((unsigned char *)answer, (unsigned char *)eom, + (unsigned char *)cp, bp, buflen)) < 0) break; cp += n; @@ -117,20 +121,34 @@ struct mxentry *getmxrecords(const char *name) } #endif /* HAVE_RES_SEARCH */ -#ifdef TESTMAIN -main(int argc, char *argv[]) +#ifdef STANDALONE +#include + +int main(int argc, char *argv[]) { - int count, i; +#ifdef HAVE_RES_SEARCH struct mxentry *responses; +#endif + if (argc != 2 || 0 == strcmp(argv[1], "-h")) { + fprintf(stderr, "Usage: %s domain\n", argv[0]); + exit(1); + } + +#ifdef HAVE_RES_SEARCH responses = getmxrecords(argv[1]); - if (responses == (struct mxentry *)NULL) + if (responses == (struct mxentry *)NULL) { puts("No MX records found"); - else + } else { do { printf("%s %d\n", responses->name, responses->pref); - } while - ((++responses)->name); + } while ((++responses)->name); + } +#else + puts("This program was compiled without HAS_RES_SEARCH and does nothing."); +#endif + + return 0; } #endif /* TESTMAIN */