djbdnscurve6 53
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
17unsigned int flagedns0 = 0;
18unsigned int msgsize = MSGSIZE;
19
20static char seed[128];
21static stralloc fqdn;
22static char *q;
23static stralloc out;
24char strnum[FMT_ULONG];
25
26int main(int argc,char **argv)
27{
28 int i;
29 int j;
30 uint16 pref;
31
33
34 if (*argv) ++argv;
35
36 while (*argv) {
37 if (!stralloc_copys(&fqdn,*argv)) nomem();
38 if (dns_mx(&out,&fqdn) < 0)
39 logmsg(WHO,111,FATAL,B("unable to find MX records for: ",*argv));
40
41 if (!out.len) {
42 if (dns_domain_fromdot(&q,*argv,str_len(*argv)) <= 0) nomem();
43 if (!stralloc_copys(&out,"0 ")) nomem();
44 if (dns_domain_todot_cat(&out,q) <= 0) nomem();
45 if (!stralloc_cats(&out,"\n")) nomem();
46 buffer_put(buffer_1,out.s,out.len);
47 }
48 else {
49 i = 0;
50 while (i + 2 < out.len) {
51 j = byte_chr(out.s + i + 2,out.len - i - 2,0);
52 uint16_unpack_big(out.s + i,&pref);
53 buffer_put(buffer_1,strnum,fmt_ulong(strnum,pref));
54 buffer_puts(buffer_1," ");
55 buffer_put(buffer_1,out.s + i + 2,j);
56 buffer_puts(buffer_1,"\n");
57 i += j + 3;
58 }
59 }
60
61 ++argv;
62 }
63
64 buffer_flush(buffer_1);
65 _exit(0);
66}
int main()
Definition: axfrdns.c:326
#define MSGSIZE
Definition: dns.h:47
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:36
uint32 seed[32]
Definition: dnscache-conf.c:36
char strnum[FMT_ULONG]
Definition: dnsmx.c:24
void nomem(void)
Definition: dnsmx.c:12
unsigned int flagedns0
Definition: dnsmx.c:17
unsigned int msgsize
Definition: dnsmx.c:18
#define WHO
Definition: dnsmx.c:10