djbdnscurve6  38
djbdnscurve6
dnsmx.c
Go to the documentation of this file.
1 #include "buffer.h"
2 #include "exit.h"
3 #include "logmsg.h"
4 #include "uint_t.h"
5 #include "byte.h"
6 #include "str.h"
7 #include "fmt.h"
8 #include "dns.h"
9 
10 #define WHO "dnsmx"
11 
12 void nomem(void)
13 {
14  logmsg(WHO,111,FATAL,"out of memory");
15 }
16 
17 static char seed[128];
18 
19 static stralloc fqdn;
20 static char *q;
21 static stralloc out;
22 char strnum[FMT_ULONG];
23 
24 int main(int argc,char **argv)
25 {
26  int i;
27  int j;
28  uint16 pref;
29 
31 
32  if (*argv) ++argv;
33 
34  while (*argv) {
35  if (!stralloc_copys(&fqdn,*argv)) nomem();
36  if (dns_mx(&out,&fqdn) < 0)
37  logmsg(WHO,111,FATAL,B("unable to find MX records for: ",*argv));
38 
39  if (!out.len) {
40  if (dns_domain_fromdot(&q,*argv,str_len(*argv)) <= 0) nomem();
41  if (!stralloc_copys(&out,"0 ")) nomem();
42  if (dns_domain_todot_cat(&out,q) <= 0) nomem();
43  if (!stralloc_cats(&out,"\n")) nomem();
44  buffer_put(buffer_1,out.s,out.len);
45  }
46  else {
47  i = 0;
48  while (i + 2 < out.len) {
49  j = byte_chr(out.s + i + 2,out.len - i - 2,0);
50  uint16_unpack_big(out.s + i,&pref);
51  buffer_put(buffer_1,strnum,fmt_ulong(strnum,pref));
52  buffer_puts(buffer_1," ");
53  buffer_put(buffer_1,out.s + i + 2,j);
54  buffer_puts(buffer_1,"\n");
55  i += j + 3;
56  }
57  }
58 
59  ++argv;
60  }
61 
62  buffer_flush(buffer_1);
63  _exit(0);
64 }
int dns_domain_fromdot(char **, const char *, unsigned int)
Definition: dns_dfd.c:6
int dns_domain_todot_cat(stralloc *, const char *)
Definition: dns_dtda.c:11
int dns_mx(stralloc *, const stralloc *)
Definition: dns_mx.c:43
void dns_random_init(const char *)
uint32 seed[32]
Definition: dnscache-conf.c:36
int main(int argc, char **argv)
Definition: dnsmx.c:24
char strnum[FMT_ULONG]
Definition: dnsmx.c:22
void nomem(void)
Definition: dnsmx.c:12
#define WHO
Definition: dnsmx.c:10