diff options
author | Henryk Plötz <henryk@ploetzli.ch> | 2014-10-03 19:58:52 +0200 |
---|---|---|
committer | Henryk Plötz <henryk@ploetzli.ch> | 2014-10-03 19:58:52 +0200 |
commit | 0e5b2871ca6456b01d4bf037a6e68badf1ff1a41 (patch) | |
tree | 97b95b74c9618d85da9aa9451a55a819cd7b1c2e /dnsmx.c | |
download | tinydnssec-0e5b2871ca6456b01d4bf037a6e68badf1ff1a41.tar.gz tinydnssec-0e5b2871ca6456b01d4bf037a6e68badf1ff1a41.tar.bz2 |
Initial commit of djbdns-1.05.tar.gz
Source was http://cr.yp.to/djbdns/djbdns-1.05.tar.gz, SHA1 2efdb3a039d0c548f40936aa9cb30829e0ce8c3d
Diffstat (limited to 'dnsmx.c')
-rw-r--r-- | dnsmx.c | 64 |
1 files changed, 64 insertions, 0 deletions
@@ -0,0 +1,64 @@ +#include "buffer.h" +#include "exit.h" +#include "strerr.h" +#include "uint16.h" +#include "byte.h" +#include "str.h" +#include "fmt.h" +#include "dns.h" + +#define FATAL "dnsmx: fatal: " + +void nomem(void) +{ + strerr_die2x(111,FATAL,"out of memory"); +} + +static char seed[128]; + +static stralloc fqdn; +static char *q; +static stralloc out; +char strnum[FMT_ULONG]; + +int main(int argc,char **argv) +{ + int i; + int j; + uint16 pref; + + dns_random_init(seed); + + if (*argv) ++argv; + + while (*argv) { + if (!stralloc_copys(&fqdn,*argv)) nomem(); + if (dns_mx(&out,&fqdn) == -1) + strerr_die4sys(111,FATAL,"unable to find MX records for ",*argv,": "); + + if (!out.len) { + if (!dns_domain_fromdot(&q,*argv,str_len(*argv))) nomem(); + if (!stralloc_copys(&out,"0 ")) nomem(); + if (!dns_domain_todot_cat(&out,q)) nomem(); + if (!stralloc_cats(&out,"\n")) nomem(); + buffer_put(buffer_1,out.s,out.len); + } + else { + i = 0; + while (i + 2 < out.len) { + j = byte_chr(out.s + i + 2,out.len - i - 2,0); + uint16_unpack_big(out.s + i,&pref); + buffer_put(buffer_1,strnum,fmt_ulong(strnum,pref)); + buffer_puts(buffer_1," "); + buffer_put(buffer_1,out.s + i + 2,j); + buffer_puts(buffer_1,"\n"); + i += j + 3; + } + } + + ++argv; + } + + buffer_flush(buffer_1); + _exit(0); +} |