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