djbdnscurve6  38
djbdnscurve6
tinydns-get.c
Go to the documentation of this file.
1 #include "str.h"
2 #include "byte.h"
3 #include "scan.h"
4 #include "exit.h"
5 #include "stralloc.h"
6 #include "buffer.h"
7 #include "logmsg.h"
8 #include "uint_t.h"
9 #include "response.h"
10 #include "case.h"
11 #include "printpacket.h"
12 #include "parsetype.h"
13 #include "ip.h"
14 #include "dns.h"
15 
16 extern int respond(char *,char *,char *);
17 int rename(const char *,const char *); // keep compiler silent
18 
19 #define WHO "tinydns-get "
20 
21 void usage(void)
22 {
23  logmsg(WHO,100,USAGE,"tinydns-get type name [ip]");
24 }
25 void oops(void)
26 {
27  logmsg(WHO,111,FATAL,"unable to parse");
28 }
29 
30 static char ip[16];
31 static char type[2];
32 static char *q;
33 
34 static stralloc out;
35 
36 int main(int argc,char **argv)
37 {
38  uint16 u16;
39 
40  if (!*argv) usage();
41 
42  if (!*++argv) usage();
43  if (!parsetype(*argv,type)) usage();
44 
45  if (!*++argv) usage();
46  if (dns_domain_fromdot(&q,*argv,str_len(*argv)) <= 0) oops();
47 
48  if (*++argv)
49  if (!ip6_scan(*argv,ip)) usage();
50 
51  if (!stralloc_copys(&out,"")) oops();
52  uint16_unpack_big(type,&u16);
53  if (!stralloc_catulong0(&out,u16,0)) oops();
54  if (!stralloc_cats(&out," ")) oops();
55  if (dns_domain_todot_cat(&out,q) <= 0) oops();
56  if (!stralloc_cats(&out,":\n")) oops();
57 
58  if (!response_query(q,type,DNS_C_IN)) oops();
59  response[3] &= ~128;
60  response[2] &= ~1;
61  response[2] |= 4;
62  case_lowerb(q,dns_domain_length(q));
63 
64  if (byte_equal(type,2,DNS_T_AXFR)) {
65  response[3] &= ~15;
66  response[3] |= 4;
67  }
68  else
69  if (!respond(q,type,ip)) goto DONE;
70 
72 
73  DONE:
74  buffer_putflush(buffer_1,out.s,out.len);
75  _exit(0);
76 }
char ip[16]
Definition: axfrdns.c:126
#define DNS_T_AXFR
Definition: dns.h:65
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
#define DNS_C_IN
Definition: dns.h:34
unsigned int dns_domain_length(const char *)
Definition: dns_domain.c:6
char type[2]
Definition: dnsq.c:56
int parsetype(char *s, char type[2])
Definition: parsetype.c:8
unsigned int printpacket_cat(stralloc *out, char *buf, unsigned int len)
Definition: printpacket.c:14
char response[65535]
Definition: response.c:6
unsigned int response_len
Definition: response.c:7
int response_query(const char *q, const char qtype[2], const char qclass[2])
Definition: response.c:54
int main(int argc, char **argv)
Definition: tinydns-get.c:36
int rename(const char *, const char *)
void oops(void)
Definition: tinydns-get.c:25
int respond(char *, char *, char *)
#define WHO
Definition: tinydns-get.c:19
void usage(void)
Definition: tinydns-get.c:21