djbdnscurve6 45
djbdnscurve6
Loading...
Searching...
No Matches
dnsq.c
Go to the documentation of this file.
1#include "uint_t.h"
2#include "logmsg.h"
3#include "buffer.h"
4#include "scan.h"
5#include "str.h"
6#include "byte.h"
7#include "ip.h"
8#include "iopause.h"
9#include "printpacket.h"
10#include "parsetype.h"
11#include "dns.h"
12#include "ip.h"
13#include "exit.h"
14#include "curvedns.h"
15
16#define WHO "dnsq"
17
18void usage(void)
19{
20 logmsg(WHO,100,USAGE,"type name server");
21}
22void oops(void)
23{
24 logmsg(WHO,111,FATAL,"unable to parse");
25}
26
27static struct dns_transmit tx;
28
29int resolve(char *q,char qtype[2],char servers[QUERY_MAXIPLEN])
30{
31 struct taia stamp;
32 struct taia deadline;
33 iopause_fd x[1];
34 int r;
35
36 if (cns_transmit_start(&tx,servers,0,q,qtype,V6any,0,0,0) < 0) return DNS_COM;
37
38 for (;;) {
39 taia_now(&stamp);
40 taia_uint(&deadline,120);
41 taia_add(&deadline,&deadline,&stamp);
42 dns_transmit_io(&tx,x,&deadline);
43 iopause(x,1,&deadline,&stamp);
44 r = dns_transmit_get(&tx,x,&stamp);
45 if (r < 0) return DNS_ERR;
46 if (r == 1) break;
47 }
48
49 return 0;
50}
51
53static stralloc ip;
54static stralloc fqdn;
55
56char type[2];
57static char *q;
58
59static stralloc out;
60
61static char seed[128];
62
63int main(int argc,char **argv)
64{
65 uint16 u16;
66
68
69 if (!*argv) usage();
70 if (!*++argv) usage();
71 if (!parsetype(*argv,type)) usage();
72
73 if (!*++argv) usage();
74 if (dns_domain_fromdot(&q,*argv,str_len(*argv)) <= 0) oops();
75
76 if (!*++argv) usage();
77 if (!stralloc_copys(&out,*argv)) oops();
78 if (dns_ip_qualify(&ip,&fqdn,&out) < 0) oops();
79 if (ip.len >= QUERY_MAXIPLEN) ip.len = QUERY_MAXIPLEN;
80 byte_zero(servers,QUERY_MAXIPLEN);
81 byte_copy(servers,ip.len,ip.s);
82
83 if (!stralloc_copys(&out,"")) oops();
84 uint16_unpack_big(type,&u16);
85 if (!stralloc_catulong0(&out,u16,0)) oops();
86 if (!stralloc_cats(&out," ")) oops();
87 if (dns_domain_todot_cat(&out,q) <= 0) oops();
88 if (!stralloc_cats(&out,":\n")) oops();
89
90 if (resolve(q,type,servers) < 0) {
91 if (!stralloc_cats(&out,errstr(errno))) oops();
92 if (!stralloc_cats(&out,"\n")) oops();
93 }
94 else {
95 if (!printpacket_cat(&out,tx.packet,tx.packetlen)) oops();
96 }
97
98 buffer_putflush(buffer_1,out.s,out.len);
99 _exit(0);
100}
char ip[16]
Definition: axfrdns.c:125
int main()
Definition: axfrdns.c:323
int cns_transmit_start(struct dns_transmit *d, const char servers[QUERY_MAXIPLEN], int flagrecursive, const char *q, const char qtype[2], const char localip[16], const char keys[1024], const char pubkey[32], const char *suffix)
Definition: curvedns.c:246
#define DNS_ERR
Definition: dns.h:32
#define QUERY_MAXIPLEN
Definition: dns.h:45
#define DNS_COM
Definition: dns.h:33
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_ip_qualify(stralloc *ipout, stralloc *fqdn, const stralloc *in)
Definition: dns_ipq.c:228
void dns_random_init(const char data[128])
Definition: dns_random.c:37
void dns_transmit_io(struct dns_transmit *d, iopause_fd *x, struct taia *deadline)
Definition: dns_transmit.c:279
int dns_transmit_get(struct dns_transmit *d, const iopause_fd *x, const struct taia *when)
Definition: dns_transmit.c:296
uint32 seed[32]
Definition: dnscache-conf.c:36
struct line * x
void oops(void)
Definition: dnsq.c:22
int resolve(char *q, char qtype[2], char servers[QUERY_MAXIPLEN])
Definition: dnsq.c:29
char servers[QUERY_MAXIPLEN]
Definition: dnsq.c:52
char type[2]
Definition: dnsq.c:56
#define WHO
Definition: dnsq.c:16
void usage(void)
Definition: dnsq.c:18
int parsetype(char *, char *)
unsigned int printpacket_cat(stralloc *, char *, unsigned int)
Definition: printpacket.c:14
char qtype[2]
Definition: dns.h:112
unsigned int packetlen
Definition: dns.h:96
char * packet
Definition: dns.h:95