2 DNS should have used LZ77 instead of its own sophomoric compression algorithm.
8 unsigned int dns_packet_copy(const char *buf
,unsigned int len
,unsigned int pos
,char *out
,unsigned int outlen
)
11 if (pos
>= len
) { errno
= error_proto
; return 0; }
18 unsigned int dns_packet_skipname(const char *buf
,unsigned int len
,unsigned int pos
)
23 if (pos
>= len
) break;
25 if (ch
>= 192) return pos
+ 1;
35 unsigned int dns_packet_getname(const char *buf
,unsigned int len
,unsigned int pos
,char **d
)
37 unsigned int loop
= 0;
38 unsigned int state
= 0;
39 unsigned int firstcompress
= 0;
43 unsigned int namelen
= 0;
46 if (pos
>= len
) goto PROTO
; ch
= buf
[pos
++];
47 if (++loop
>= 1000) goto PROTO
;
50 if (namelen
+ 1 > sizeof name
) goto PROTO
; name
[namelen
++] = ch
;
55 where
= ch
; where
-= 192; where
<<= 8;
56 if (pos
>= len
) goto PROTO
; ch
= buf
[pos
++];
57 if (!firstcompress
) firstcompress
= pos
;
59 if (pos
>= len
) goto PROTO
; ch
= buf
[pos
++];
60 if (++loop
>= 1000) goto PROTO
;
62 if (ch
>= 64) goto PROTO
;
63 if (namelen
+ 1 > sizeof name
) goto PROTO
; name
[namelen
++] = ch
;
69 if (!dns_domain_copy(d
,name
)) return 0;
71 if (firstcompress
) return firstcompress
;