djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
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
16extern int respond(char *,char *,char *);
17int rename(const char *,const char *); // keep compiler silent
18
19#define WHO "tinydns-get "
20
21void usage(void)
22{
23 logmsg(WHO,100,USAGE,"tinydns-get type name [ip]");
24}
25void oops(void)
26{
27 logmsg(WHO,111,FATAL,"unable to parse");
28}
29
30static char ip[16];
31static char type[2];
32static char *q;
33
34static stralloc out;
35
36int 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
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:125
int main()
Definition: axfrdns.c:323
#define DNS_T_AXFR
Definition: dns.h:84
#define DNS_C_IN
Definition: dns.h:53
int dns_domain_fromdot(char **out, const char *buf, unsigned int n)
Definition: dns_dfd.c:6
unsigned int dns_domain_length(const char *dn)
Definition: dns_domain.c:6
int dns_domain_todot_cat(stralloc *out, const char *d)
Definition: dns_dtda.c:11
char type[2]
Definition: dnsq.c:56
int parsetype(char *, char *)
unsigned int printpacket_cat(stralloc *, char *, unsigned int)
Definition: printpacket.c:14
char response[]
Definition: response.c:6
unsigned int response_len
Definition: response.c:7
int response_query(const char *, const char *, const char *)
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