djbdnscurve6 45
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 "
7const char *fatal = "walldns";
8const char *starting = "starting walldns";
10
11void init_server(void)
12{
13 ;
14}
15
16int respond(char *q,char qtype[2])
17{
18 int flaga;
19 int flaga4;
20 int flagptr;
21 char ip4[4];
22 char ip6[16];
23 int i, j;
24
25 flaga = byte_equal(qtype,2,DNS_T_A);
26 flaga4 = byte_equal(qtype,2,DNS_T_AAAA);
27 flagptr = byte_equal(qtype,2,DNS_T_PTR);
28 if (byte_equal(qtype,2,DNS_T_ANY)) flaga = flagptr = 1;
29
30 if (flaga || flagptr) {
31 if (dd4(q,"",ip4) == 4) {
32 if (flaga) {
33 if (!response_rstart(q,DNS_T_A,655360)) return 0;
34 if (!response_addbytes(ip4,4)) return 0;
36 }
37 return 1;
38 }
39 j = dd4(q,"\7in-addr\4arpa",ip4);
40 if (j >= 0) {
41 if (flaga && (j == 4)) {
42 if (!response_rstart(q,DNS_T_A,655360)) return 0;
43 for (i = 3; i >=0; --i)
44 if (!response_addbytes(ip4 + j,1)) return 0;
46 }
47 if (flagptr) {
48 if (!response_rstart(q,DNS_T_PTR,655360)) return 0;
49 if (!response_addname(q)) return 0;
51 }
52 return 1;
53 }
54 }
55
56 if (flaga4 || flagptr) {
57 if (dd6(q,"",ip6) == 16) {
58 if (flaga4) {
59 if (!response_rstart(q,DNS_T_AAAA,655360)) return 0;
60 if (!response_addbytes(ip6,16)) return 0;
62 }
63 return 1;
64 }
65 j = dd6(q,"\3ip6\4arpa",ip6);
66 if (j >= 0) {
67 if (flaga4 && (j == 16)) {
68 if (!response_rstart(q,DNS_T_AAAA,655360)) return 0;
69 for (i = 15; i >= 0; --i)
70 if (!response_addbytes(ip6 + j,1)) return 0;
72 }
73 if (flagptr) {
74 if (!response_rstart(q,DNS_T_PTR,655360)) return 0;
75 if (!response_addname(q)) return 0;
77 }
78 return 1;
79 }
80 }
81
82 response[2] &= ~4;
83 response[3] &= ~15;
84 response[3] |= 5;
85 return 1;
86}
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:56
#define DNS_T_ANY
Definition: dns.h:85
#define DNS_T_PTR
Definition: dns.h:60
#define DNS_T_AAAA
Definition: dns.h:67
char ip6[16]
Definition: dnsfilter.c:51
char ip4[4]
Definition: dnsfilter.c:50
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
int response_rstart(const char *, const char *, uint32)
#define RESPONSE_ANSWER
Definition: response.h:23
int flagcurved
Definition: walldns.c:9
const char * fatal
Definition: walldns.c:7
void init_server(void)
Definition: walldns.c:11
int respond(char *q, char qtype[2])
Definition: walldns.c:16
const char * starting
Definition: walldns.c:8