djbdnscurve6
45
djbdnscurve6
Loading...
Searching...
No Matches
djbdnscurve6-45
src
dns_packet.c
Go to the documentation of this file.
1
/*
2
DNS should have used LZ77 instead of its own sophomoric compression algorithm.
3
*/
4
5
#include "error.h"
6
#include "
dns.h
"
7
8
unsigned
int
dns_packet_copy
(
const
char
*
buf
,
unsigned
int
len
,
unsigned
int
pos,
char
*out,
unsigned
int
outlen)
9
{
10
while
(outlen) {
11
if
(pos >=
len
) { errno = EPROTO ;
return
0; }
12
*
out
=
buf
[pos++];
13
++
out
; --outlen;
14
}
15
return
pos;
16
}
17
18
unsigned
int
dns_packet_skipname
(
const
char
*
buf
,
unsigned
int
len
,
unsigned
int
pos)
19
{
20
unsigned
char
ch;
21
22
for
(;;) {
23
if
(pos >=
len
)
break
;
24
ch =
buf
[pos++];
25
if
(ch >= 192)
return
pos + 1;
26
if
(ch >= 64)
break
;
27
if
(!ch)
return
pos;
28
pos += ch;
29
}
30
31
errno = EPROTO;
32
return
0;
33
}
34
35
unsigned
int
dns_packet_getname
(
const
char
*
buf
,
unsigned
int
len
,
unsigned
int
pos,
char
**d)
36
{
37
unsigned
int
loop = 0;
38
unsigned
int
state = 0;
39
unsigned
int
firstcompress = 0;
40
unsigned
int
where;
41
unsigned
char
ch;
42
char
name
[511];
43
unsigned
int
namelen = 0;
44
45
for
(;;) {
46
if
(pos >=
len
)
goto
PROTO;
47
ch =
buf
[pos++];
48
if
(++loop >= 1000)
goto
PROTO;
49
50
if
(state) {
51
if
(namelen + 1 >
sizeof
(
name
))
goto
PROTO;
52
name
[namelen++] = ch;
53
--state;
54
}
else
{
55
while
(ch >= 192) {
56
where = ch; where -= 192; where <<= 8;
57
if
(pos >=
len
)
goto
PROTO;
58
ch =
buf
[pos++];
59
if
(!firstcompress) firstcompress = pos;
60
pos = where + ch;
61
if
(pos >=
len
)
goto
PROTO;
62
ch =
buf
[pos++];
63
if
(++loop >= 1000)
goto
PROTO;
64
}
65
if
(ch >= 64)
goto
PROTO;
66
if
(namelen + 1 >
sizeof
(
name
))
goto
PROTO;
67
name
[namelen++] = ch;
68
if
(!ch)
break
;
69
state = ch;
70
}
71
}
72
73
if
(!
dns_domain_copy
(
d
,
name
))
return
0;
74
75
if
(firstcompress)
return
firstcompress;
76
return
pos;
77
78
PROTO:
79
errno = EPROTO;
80
return
0;
81
}
len
uint16 len
Definition:
axfrdns.c:319
buf
char buf[MSGSIZE]
Definition:
axfrdns.c:318
dns.h
dns_domain_copy
int dns_domain_copy(char **out, const char *in)
Definition:
dns_domain.c:25
dns_packet_getname
unsigned int dns_packet_getname(const char *buf, unsigned int len, unsigned int pos, char **d)
Definition:
dns_packet.c:35
dns_packet_copy
unsigned int dns_packet_copy(const char *buf, unsigned int len, unsigned int pos, char *out, unsigned int outlen)
Definition:
dns_packet.c:8
dns_packet_skipname
unsigned int dns_packet_skipname(const char *buf, unsigned int len, unsigned int pos)
Definition:
dns_packet.c:18
name
char name[DNS_NAME6_DOMAIN]
Definition:
dnsfilter.c:52
out
void out(const char *s, unsigned int len)
Definition:
generic-conf.c:54
d
void d(const char *home, const char *subdir, int uid, int gid, int mode)
Generated on Fri Aug 30 2024 11:58:34 for djbdnscurve6 by
1.9.6