]> Pileus Git - ~andy/fetchmail/blobdiff - mxget.c
Add a few revisions (not yet workable).
[~andy/fetchmail] / mxget.c
diff --git a/mxget.c b/mxget.c
index 482ea568df5032a28b1336a2f005e57bc66a8c8d..073bbd5ca0a644f9db000ba1584c8e6d26ab5a4b 100644 (file)
--- a/mxget.c
+++ b/mxget.c
@@ -8,11 +8,25 @@
 #include "config.h"
 #ifdef HAVE_RES_SEARCH
 #include <stdio.h>
+#include <string.h>
+#ifdef HAVE_NET_SOCKET_H
+#include <net/socket.h>
+#endif
 #include <netdb.h>
 #include <sys/types.h>
 #include <netinet/in.h>
+
+#ifdef __BEOS__
+#include "beos/beos_nameser.h"
+#endif
+
+#ifdef HAVE_ARPA_NAMESER_H
 #include <arpa/nameser.h>
+#endif
+#ifdef HAVE_RESOLV_H
 #include <resolv.h>
+#endif
+
 #include "mx.h"
 
 /*
 /* 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 unsigned char *name)
+struct mxentry *getmxrecords(const char *name)
 /* get MX records for given host */
 {
-    unsigned char answer[PACKETSZ], *eom, *cp, *bp;
+    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]; 
@@ -51,9 +65,11 @@ struct mxentry *getmxrecords(const unsigned char *name)
 
     pmx->name = (char *)NULL;
     pmx->pref = -1;
-    n = res_search(name,C_IN,T_MX,(unsigned char*)&answer, sizeof(answer));
+    n = res_search(name, C_IN,T_MX, (unsigned char *)&answer, sizeof(answer));
     if (n == -1)
        return((struct mxentry *)NULL);
+    if (n > sizeof(answer))
+       n = sizeof(answer);     
 
     hp = (HEADER *)&answer;
     cp = answer + HFIXEDSZ;
@@ -88,7 +104,7 @@ struct mxentry *getmxrecords(const unsigned char *name)
        pmx[ind].pref = pref;
        ++ind;
 
-       n = strlen(bp);
+       n = strlen((const char *)bp);
        bp += n;
        *bp++ = '\0';
 
@@ -101,12 +117,19 @@ struct mxentry *getmxrecords(const unsigned char *name)
 }
 #endif /* HAVE_RES_SEARCH */
 
-#ifdef TESTMAIN
-main(int argc, char *argv[])
+#ifdef STANDALONE
+#include <stdlib.h>
+
+int main(int argc, char *argv[])
 {
     int        count, i;
     struct mxentry *responses;
 
+    if (argc != 2 || 0 == strcmp(argv[1], "-h")) {
+       fprintf(stderr, "Usage: %s domain\n", argv[0]);
+       exit(1);
+    }
+
     responses = getmxrecords(argv[1]);
     if (responses == (struct mxentry *)NULL)
        puts("No MX records found");
@@ -115,6 +138,8 @@ main(int argc, char *argv[])
            printf("%s %d\n", responses->name, responses->pref);
        } while
            ((++responses)->name);
+
+    return 0;
 }
 #endif /* TESTMAIN */