djbdnscurve6
46
djbdnscurve6
Loading...
Searching...
No Matches
djbdnscurve6-46
src
response.c
Go to the documentation of this file.
1
#include "
dns.h
"
2
#include "byte.h"
3
#include "uint_t.h"
4
#include "
response.h
"
5
6
char
response
[65535];
7
unsigned
int
response_len
= 0;
/* <= 65535 */
8
unsigned
int
max_response_len
;
9
unsigned
int
do_dnssec
= 0;
10
static
unsigned
int
tctarget;
11
12
#define NAMES 100
13
static
char
name
[
NAMES
][128];
14
static
unsigned
int
name_ptr[
NAMES
];
/* each < 16384 */
15
static
unsigned
int
name_num;
16
17
int
response_addbytes
(
const
char
*
buf
,
unsigned
int
len
)
18
{
19
if
(
len
> 65535 -
response_len
)
return
0;
20
byte_copy(
response
+
response_len
,
len
,
buf
);
21
response_len
+=
len
;
22
return
1;
23
}
24
25
int
response_addname
(
const
char
*d)
26
{
27
unsigned
int
dlen
;
28
unsigned
int
i;
29
char
buf
[2];
30
31
dlen
=
dns_domain_length
(d);
32
33
while
(*d) {
34
for
(i = 0; i < name_num; ++i)
35
if
(
dns_domain_equal
(d,
name
[i])) {
36
uint16_pack_big(
buf
,49152 + name_ptr[i]);
37
return
response_addbytes
(
buf
,2);
38
}
39
if
((
dlen
<= 128) && (
response_len
< 16384))
40
if
(name_num <
NAMES
) {
41
byte_copy(
name
[name_num],
dlen
,d);
42
name_ptr[name_num] =
response_len
;
43
++name_num;
44
}
45
i = (
unsigned
char) *d;
46
++i;
47
if
(!
response_addbytes
(d,i))
return
0;
48
d += i;
49
dlen
-= i;
50
}
51
return
response_addbytes
(d,1);
52
}
53
54
int
response_query
(
const
char
*q,
const
char
qtype[2],
const
char
qclass[2])
55
{
56
response_len
= 0;
57
name_num = 0;
58
if
(!
response_addbytes
(
"\0\0\201\200\0\1\0\0\0\0\0\0"
,12))
return
0;
59
if
(!
response_addname
(q))
return
0;
60
if
(!
response_addbytes
(qtype,2))
return
0;
61
if
(!
response_addbytes
(qclass,2))
return
0;
62
tctarget =
response_len
;
63
return
1;
64
}
65
66
static
unsigned
int
dpos
;
67
68
static
int
flaghidettl = 0;
69
70
void
response_hidettl
(
void
)
71
{
72
flaghidettl = 1;
73
}
74
75
int
response_rstart
(
const
char
*d,
const
char
type
[2],uint32 ttl)
76
{
77
char
ttlstr[4];
78
if
(!
response_addname
(d))
return
0;
79
if
(!
response_addbytes
(
type
,2))
return
0;
80
if
(!
response_addbytes
(
DNS_C_IN
,2))
return
0;
81
if
(flaghidettl) ttl = 0;
82
uint32_pack_big(ttlstr,ttl);
83
if
(!
response_addbytes
(ttlstr,4))
return
0;
84
if
(!
response_addbytes
(
"\0\0"
,2))
return
0;
85
dpos
=
response_len
;
86
return
1;
87
}
88
89
void
response_rfinish
(
int
x
)
90
{
91
uint16_pack_big(
response
+
dpos
- 2,
response_len
-
dpos
);
92
if
(!++
response
[
x
+ 1]) ++
response
[
x
];
93
}
94
95
int
response_cname
(
const
char
*c,
const
char
*d,uint32 ttl)
96
{
97
if
(!
response_rstart
(c,
DNS_T_CNAME
,ttl))
return
0;
98
if
(!
response_addname
(d))
return
0;
99
response_rfinish
(
RESPONSE_ANSWER
);
100
return
1;
101
}
102
103
void
response_nxdomain
(
void
)
104
{
105
response
[3] |= 3;
106
response
[2] |= 4;
107
}
108
109
void
response_servfail
(
void
)
110
{
111
response
[3] |= 2;
112
}
113
114
void
response_id
(
const
char
id
[2])
115
{
116
byte_copy(
response
,2,
id
);
117
}
118
119
void
response_tc
(
void
)
120
{
121
response
[2] |= 2;
122
response_len
= tctarget;
123
}
len
uint16 len
Definition
axfrdns.c:319
buf
char buf[MSGSIZE]
Definition
axfrdns.c:318
dpos
uint32 dpos
Definition
axfrdns.c:132
dlen
uint32 dlen
Definition
axfrdns.c:131
dns.h
DNS_C_IN
#define DNS_C_IN
Definition
dns.h:53
DNS_T_CNAME
#define DNS_T_CNAME
Definition
dns.h:58
dns_domain_equal
int dns_domain_equal(const char *dn1, const char *dn2)
Definition
dns_domain.c:39
dns_domain_length
unsigned int dns_domain_length(const char *dn)
Definition
dns_domain.c:6
x
struct line * x
name
char name[DNS_NAME6_DOMAIN]
Definition
dnsfilter.c:52
type
char type[2]
Definition
dnsq.c:56
response_addbytes
int response_addbytes(const char *buf, unsigned int len)
Definition
response.c:17
NAMES
#define NAMES
Definition
response.c:12
response_hidettl
void response_hidettl(void)
Definition
response.c:70
response_addname
int response_addname(const char *d)
Definition
response.c:25
response_id
void response_id(const char id[2])
Definition
response.c:114
response_tc
void response_tc(void)
Definition
response.c:119
response_cname
int response_cname(const char *c, const char *d, uint32 ttl)
Definition
response.c:95
response_rfinish
void response_rfinish(int x)
Definition
response.c:89
response_query
int response_query(const char *q, const char qtype[2], const char qclass[2])
Definition
response.c:54
response_nxdomain
void response_nxdomain(void)
Definition
response.c:103
response_servfail
void response_servfail(void)
Definition
response.c:109
response_rstart
int response_rstart(const char *d, const char type[2], uint32 ttl)
Definition
response.c:75
response.h
response
char response[]
Definition
response.c:6
max_response_len
unsigned int max_response_len
Definition
response.c:8
response_len
unsigned int response_len
Definition
response.c:7
RESPONSE_ANSWER
#define RESPONSE_ANSWER
Definition
response.h:23
do_dnssec
unsigned int do_dnssec
Definition
response.c:9
Generated on
for djbdnscurve6 by
1.14.0