aboutsummaryrefslogtreecommitdiffstats
path: root/unmime.c
Commit message (Expand)AuthorAgeFilesLines
* Kill alloca().Matthias Andree2005-07-311-106/+110
* strncat -> strlcatMatthias Andree2005-07-301-1/+1
* sprintf -> snprintfMatthias Andree2004-11-121-2/+3
* Misc. sprintf and pid_t fixes.Matthias Andree2004-11-101-2/+2
* Cast arguments of is*() ctype.h functions to unsigned char to be 8-bit safe.Matthias Andree2004-06-191-3/+3
* Fix various compiler warnings.Matthias Andree2004-06-181-1/+1
* Make it possible to build the test main.Eric S. Raymond2003-08-131-1/+1
* Guard some buffers.Eric S. Raymond2003-03-011-0/+1
* Don't pass through characters with codes < 16.Eric S. Raymond2001-10-041-1/+1
* Security audit fix.Eric S. Raymond2001-10-031-2/+2
* Add GPL license.Eric S. Raymond2001-09-301-0/+1
* Before showdots,Eric S. Raymond2000-10-081-0/+1
* Minor optimizations from Federico.Eric S. Raymond1999-12-261-3/+3
* Fix PGP-mimedecode.Eric S. Raymond1999-03-271-2/+1
* Try to fix a nasty MIME-decoding bug.Eric S. Raymond1999-03-091-10/+24
* Add Storner's sanity check.Eric S. Raymond1999-01-101-0/+3
* Henrik's fix for mimedecode.Eric S. Raymond1999-01-091-10/+55
* Progress messages now go to stdout.Eric S. Raymond1999-01-051-0/+1
* -Wall cleanup.Eric S. Raymond1998-10-201-1/+1
* Make alloca safe.Eric S. Raymond1998-10-201-10/+3
* Enable compilation under Solaris 2.6.Eric S. Raymond1998-10-161-0/+1
* Use alloca where possible.Eric S. Raymond1998-10-081-7/+10
* Henrik's fix.Eric S. Raymond1998-05-121-3/+5
* Henreik Storner's fix patch.Eric S. Raymond1998-04-191-28/+59
* Don't use inline.Eric S. Raymond1998-04-071-1/+1
* Initial revisionEric S. Raymond1998-03-261-0/+652
;netdb.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/nameser.h> #include <resolv.h> #include "mx.h" /* * This ought to be in the bind library. It's adapted from sendmail. */ /* * These are defined in RFC833. Some bind interface headers don't declare them. * Ghod help us if they're ever actually incompatible with what's in * the arpa/nameser.h header. */ #ifndef PACKETSZ #define PACKETSZ 512 /* maximum packet size */ #endif #ifndef HFIXEDSZ #define HFIXEDSZ 12 /* #/bytes of fixed data in header */ #endif #ifndef INT32SZ #define INT32SZ 4 /* for systems without 32-bit ints */ #endif #ifndef INT16SZ #define INT16SZ 2 /* for systems without 16-bit ints */ #endif /* minimum possible size of MX record in packet */ #define MIN_MX_SIZE 8 /* corresp to "a.com 0" w/ terminating space */ struct mxentry *getmxrecords(const char *name) /* get MX records for given host */ { char answer[PACKETSZ], *eom, *cp, *bp; int n, ancount, qdcount, buflen, type, pref, ind; static struct mxentry pmx[(PACKETSZ - HFIXEDSZ) / MIN_MX_SIZE]; static char MXHostBuf[PACKETSZ - HFIXEDSZ]; HEADER *hp; pmx->name = (char *)NULL; pmx->pref = -1; n = res_search(name, C_IN,T_MX, (unsigned char *)&answer, sizeof(answer)); if (n == -1) return((struct mxentry *)NULL); hp = (HEADER *)&answer; cp = answer + HFIXEDSZ; eom = answer + n; h_errno = 0; for (qdcount = ntohs(hp->qdcount); qdcount--; cp += n + QFIXEDSZ) if ((n = dn_skipname(cp, eom)) < 0) return((struct mxentry *)NULL); buflen = sizeof(MXHostBuf) - 1; bp = MXHostBuf; ind = 0; ancount = ntohs(hp->ancount); while (--ancount >= 0 && cp < eom) { if ((n = dn_expand(answer, eom, cp, bp, buflen)) < 0) break; cp += n; GETSHORT(type, cp); cp += INT16SZ + INT32SZ; GETSHORT(n, cp); if (type != T_MX) { cp += n; continue; } GETSHORT(pref, cp); if ((n = dn_expand(answer, eom, cp, bp, buflen)) < 0) break; cp += n; pmx[ind].name = bp; pmx[ind].pref = pref; ++ind; n = strlen((const char *)bp); bp += n; *bp++ = '\0'; buflen -= n + 1; } pmx[ind].name = (char *)NULL; pmx[ind].pref = -1; return(pmx); } #endif /* HAVE_RES_SEARCH */ #ifdef TESTMAIN main(int argc, char *argv[]) { int count, i; struct mxentry *responses; responses = getmxrecords(argv[1]); if (responses == (struct mxentry *)NULL) puts("No MX records found"); else do { printf("%s %d\n", responses->name, responses->pref); } while ((++responses)->name); } #endif /* TESTMAIN */ /* mxget.c ends here */