-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdns-rr.c
85 lines (64 loc) · 1.76 KB
/
dns-rr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* 1996 Thomas H. Ptacek, the RDIST organization */
#include "dns-rr.h"
/* --------------------------------------------------------------------- */
/* A DNS query is a resource record with no data (and hence no length specifier).
* All queries share the same format.
*/
int dns_rr_query_len(char *name, int type, u_char *buf)
{
(void)type;
(void)buf;
return (int)strlen(name) + 1 + 4;
}
#undef NS_PUT16
#define NS_PUT16(s, cp) do { \
u_int16_t t_s = (u_int16_t)(s); \
u_char *t_cp = (u_char *)(cp); \
*t_cp++ = t_s >> 8 & 255U; \
*t_cp = t_s & 255U; \
(cp) += 2; \
} while (0)
#undef NS_PUT32
#define NS_PUT32(l, cp) do { \
u_int32_t t_l = (u_int32_t)(l); \
u_char *t_cp = (u_char *)(cp); \
*t_cp++ = t_l >> 24 & 255U; \
*t_cp++ = t_l >> 16 & 255U; \
*t_cp++ = t_l >> 8 & 255U; \
*t_cp = t_l & 255U; \
(cp) += 4; \
} while (0)
int dns_rr_query(char *name, int type, u_char *buf)
{
int len;
u_char *dp = buf;
len = dns_string(name, dp, MAXDNAME);
if (len < 0)
return 0;
dp += len;
NS_PUT16(type, dp);
len += 2;
NS_PUT16(C_IN, dp);
len += 2;
return len;
}
/* --------------------------------------------------------------------- */
/* skip over the compressed name in "buf", returning an error if it's badly encoded
* and runs over the end-of-packet specified by "eop".
*/
u_char *dns_skip(u_char *buf, u_char *eop)
{
int l;
/* jump from length byte to length byte */
for (l = *buf; l; buf += (l + 1)) {
l = *buf;
if ((buf + l + 1) > eop)
return NULL;
}
return buf;
}
/* --------------------------------------------------------------------- */
int dns_string(char *string, u_char *buf, int size)
{
return dn_comp(string, buf, size, NULL, NULL);
}