djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
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
12void nomem(void)
13{
14 logmsg(WHO,111,FATAL,"out of memory");
15}
16
17static char seed[128];
18
19static stralloc fqdn;
20static char *q;
21static stralloc out;
22char strnum[FMT_ULONG];
23
24int 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 main()
Definition: axfrdns.c:323
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
Definition: dns_dfd.c:6
int dns_domain_todot_cat(stralloc *out, const char *d)
Definition: dns_dtda.c:11
int dns_mx(stralloc *out, const stralloc *fqdn)
Definition: dns_mx.c:43
void dns_random_init(const char data[128])
Definition: dns_random.c:37
uint32 seed[32]
Definition: dnscache-conf.c:36
char strnum[FMT_ULONG]
Definition: dnsmx.c:22
void nomem(void)
Definition: dnsmx.c:12
#define WHO
Definition: dnsmx.c:10