djbdnscurve6 53
djbdnscurve6
Loading...
Searching...
No Matches
walldns.c
Go to the documentation of this file.
1#include "byte.h"
2#include "dns.h"
3#include "dd.h"
4#include "response.h"
5
6#define WHO "walldns"
7
8int flagcurved = 0;
9unsigned int flagedns0 = 0;
10unsigned int msgsize = MSGSIZE;
11
12const char *server = WHO;
13
14const char *starting = "starting walldns";
15
16void init_server(void)
17{
18 ;
19}
20
21int respond(char *q,char qtype[2])
22{
23 int flaga;
24 int flaga4;
25 int flagptr;
26 char ip4[4];
27 char ip6[16];
28 int i, j;
29
30 flaga = byte_equal(qtype,2,DNS_T_A);
31 flaga4 = byte_equal(qtype,2,DNS_T_AAAA);
32 flagptr = byte_equal(qtype,2,DNS_T_PTR);
33 if (byte_equal(qtype,2,DNS_T_ANY)) flaga = flagptr = 1;
34
35 if (flaga || flagptr) {
36 if (dd4(q,"",ip4) == 4) {
37 if (flaga) {
38 if (!response_rstart(q,DNS_T_A,655360)) return 0;
39 if (!response_addbytes(ip4,4)) return 0;
41 }
42 return 1;
43 }
44 j = dd4(q,"\7in-addr\4arpa",ip4);
45 if (j >= 0) {
46 if (flaga && (j == 4)) {
47 if (!response_rstart(q,DNS_T_A,655360)) return 0;
48 for (i = 3; i >=0; --i)
49 if (!response_addbytes(ip4 + j,1)) return 0;
51 }
52 if (flagptr) {
53 if (!response_rstart(q,DNS_T_PTR,655360)) return 0;
54 if (!response_addname(q)) return 0;
56 }
57 return 1;
58 }
59 }
60
61 if (flaga4 || flagptr) {
62 if (dd6(q,"",ip6) == 16) {
63 if (flaga4) {
64 if (!response_rstart(q,DNS_T_AAAA,655360)) return 0;
65 if (!response_addbytes(ip6,16)) return 0;
67 }
68 return 1;
69 }
70 j = dd6(q,"\3ip6\4arpa",ip6);
71 if (j >= 0) {
72 if (flaga4 && (j == 16)) {
73 if (!response_rstart(q,DNS_T_AAAA,655360)) return 0;
74 for (i = 15; i >= 0; --i)
75 if (!response_addbytes(ip6 + j,1)) return 0;
77 }
78 if (flagptr) {
79 if (!response_rstart(q,DNS_T_PTR,655360)) return 0;
80 if (!response_addname(q)) return 0;
82 }
83 return 1;
84 }
85 }
86
87 response[2] &= ~4;
88 response[3] &= ~15;
89 response[3] |= 5;
90 return 1;
91}
int dd6(const char *q, const char *base, char ip[16])
Definition: dd.c:40
int dd4(const char *q, const char *base, char ip[4])
Definition: dd.c:7
#define DNS_T_A
Definition: dns.h:65
#define DNS_T_ANY
Definition: dns.h:96
#define MSGSIZE
Definition: dns.h:47
#define DNS_T_PTR
Definition: dns.h:69
#define DNS_T_AAAA
Definition: dns.h:76
char ip6[16]
Definition: dnsfilter.c:57
char ip4[4]
Definition: dnsfilter.c:56
int response_rstart(const char *, const char[2], uint32)
Definition: response.c:75
int response_addname(const char *)
Definition: response.c:25
void response_rfinish(int)
Definition: response.c:89
int response_addbytes(const char *, unsigned int)
Definition: response.c:17
char response[]
Definition: response.c:6
#define RESPONSE_ANSWER
Definition: response.h:23
int flagcurved
Definition: walldns.c:8
void init_server(void)
Definition: walldns.c:16
int respond(char *q, char qtype[2])
Definition: walldns.c:21
const char * starting
Definition: walldns.c:14
unsigned int flagedns0
Definition: walldns.c:9
const char * server
Definition: walldns.c:12
unsigned int msgsize
Definition: walldns.c:10
#define WHO
Definition: walldns.c:6