* Client config for internet
[citadel.git] / citadel / domain.c
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include <netinet/in.h>
4 #include <arpa/nameser.h>
5 #include <resolv.h>
6 #include "sysdep_decls.h"
7 #include "domain.h"
8
9 #define SMART_HOST      "gatekeeper.wdcs.com"
10
11 /* 
12  * getmx()
13  *
14  * Return one or more MX's for a mail destination.
15  *
16  * Upon success, it fills 'mxbuf' with one or more MX hosts, separated by
17  * vertical bar characters, and returns the number of hosts as its return
18  * value.  If no MX's are found, it returns 0.
19  *
20  */
21 int getmx(char *mxbuf, char *dest) {
22         char answer[1024];
23         int ret;
24
25
26
27         /* If we're configured to send all mail to a smart-host, then our
28          * job here is really easy.
29          */
30         if (1) {        /* FIX */
31                 strcpy(mxbuf, SMART_HOST);
32                 return(1);
33         }
34
35         /* No smart-host?  Look up the best MX for a site.
36          */
37         ret = res_query(
38                 dest,
39                 C_IN, T_MX, answer, sizeof(answer)  );
40
41         lprintf(9, "res_query() returned %d\n", ret);
42
43         if (ret < 0) {
44                 lprintf(5, "No MX found\n");
45                 return(0);
46         }
47
48         /* If we had to truncate, shrink the number to avoid fireworks */
49         if (ret > sizeof(answer))
50                 ret = sizeof(answer);
51
52         /* FIX not done yet */
53         return(0);
54 }