From 0e5b2871ca6456b01d4bf037a6e68badf1ff1a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henryk=20Pl=C3=B6tz?= Date: Fri, 3 Oct 2014 19:58:52 +0200 Subject: Initial commit of djbdns-1.05.tar.gz Source was http://cr.yp.to/djbdns/djbdns-1.05.tar.gz, SHA1 2efdb3a039d0c548f40936aa9cb30829e0ce8c3d --- dnsqr.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 dnsqr.c (limited to 'dnsqr.c') diff --git a/dnsqr.c b/dnsqr.c new file mode 100644 index 0000000..ff8ea6e --- /dev/null +++ b/dnsqr.c @@ -0,0 +1,66 @@ +#include "uint16.h" +#include "strerr.h" +#include "buffer.h" +#include "scan.h" +#include "str.h" +#include "byte.h" +#include "error.h" +#include "iopause.h" +#include "printpacket.h" +#include "parsetype.h" +#include "dns.h" + +#define FATAL "dnsqr: fatal: " + +void usage(void) +{ + strerr_die1x(100,"dnsqr: usage: dnsqr type name"); +} +void oops(void) +{ + strerr_die2sys(111,FATAL,"unable to parse: "); +} + +char type[2]; +static char *q; + +static stralloc out; + +static char seed[128]; + +int main(int argc,char **argv) +{ + uint16 u16; + + dns_random_init(seed); + + if (!*argv) usage(); + if (!*++argv) usage(); + if (!parsetype(*argv,type)) usage(); + + if (!*++argv) usage(); + if (!dns_domain_fromdot(&q,*argv,str_len(*argv))) oops(); + + if (*++argv) usage(); + + if (!stralloc_copys(&out,"")) oops(); + uint16_unpack_big(type,&u16); + if (!stralloc_catulong0(&out,u16,0)) oops(); + if (!stralloc_cats(&out," ")) oops(); + if (!dns_domain_todot_cat(&out,q)) oops(); + if (!stralloc_cats(&out,":\n")) oops(); + + if (dns_resolve(q,type) == -1) { + if (!stralloc_cats(&out,error_str(errno))) oops(); + if (!stralloc_cats(&out,"\n")) oops(); + } + else { + if (dns_resolve_tx.packetlen < 4) oops(); + dns_resolve_tx.packet[2] &= ~1; + dns_resolve_tx.packet[3] &= ~128; + if (!printpacket_cat(&out,dns_resolve_tx.packet,dns_resolve_tx.packetlen)) oops(); + } + + buffer_putflush(buffer_1,out.s,out.len); + _exit(0); +} -- cgit v1.2.3