forked from yaosj2k/dnsforwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsgenerator.h
executable file
·109 lines (82 loc) · 3.31 KB
/
dnsgenerator.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef _DNS_GENERATOR_H_
#define _DNS_GENERATOR_H_
#include <string.h>
#include "dnsparser.h"
#include "array.h"
#include "stringlist.h"
#include "common.h"
#define SET_16_BIT_U_INT(here, val) (*(uint16_t *)(here) = htons((uint16_t)(val)))
#define SET_32_BIT_U_INT(here, val) (*(uint32_t *)(here) = htonl((uint32_t)(val)))
/* Handle DNS header*/
#define DNSSetQueryIdentifier(dns_start, QId) SET_16_BIT_U_INT((char *)(dns_start), QId)
#define DNSSetFlags(dns_start, Flags) SET_16_BIT_U_INT((char *)(dns_start) + 2, Flags)
#define DNSSetQuestionCount(dns_start, QC) SET_16_BIT_U_INT((char *)(dns_start) + 4, QC)
#define DNSSetAnswerCount(dns_start, AnC) SET_16_BIT_U_INT((char *)(dns_start) + 6, AnC)
#define DNSSetNameServerCount(dns_start, ASC) SET_16_BIT_U_INT((char *)(dns_start) + 8, ASC)
#define DNSSetAdditionalCount(dns_start, AdC) SET_16_BIT_U_INT((char *)(dns_start) + 10, AdC)
#define DNSLabelMakePointer(pointer_ptr, location) (((unsigned char *)(pointer_ptr))[0] = (192 + (location) / 256), ((unsigned char *)(pointer_ptr))[1] = (location) % 256)
char *DNSLabelizedName(__inout char *Origin, __in size_t OriginSpaceLength);
int DNSCompress(__inout char *DNSBody, __in int DNSBodyLength);
/**
New Implementation
*/
typedef struct _DnsGenerator DnsGenerator;
struct _DnsGenerator {
/* private */
char *Buffer;
int BufferLength;
char *Itr;
void *NumberOfRecords;
/* public */
DNSHeader *Header;
int (*Length)(DnsGenerator *g);
DnsRecordPurpose (*NextPurpose)(DnsGenerator *g);
void (*CopyHeader)(DnsGenerator *g,
const char *Source,
BOOL IncludeRecordCounts
);
void (*CopyIdentifier)(DnsGenerator *g, uint16_t Value);
int (*CopyCName)(DnsGenerator *g, DnsSimpleParserIterator *i);
int (*CopyA)(DnsGenerator *g, DnsSimpleParserIterator *i);
int (*CopyAAAA)(DnsGenerator *g, DnsSimpleParserIterator *i);
int (*Question)(DnsGenerator *g,
const char *Name,
DNSRecordType Type,
DNSRecordClass Klass
);
int (*CName)(DnsGenerator *g,
const char *Name,
const char *CName,
int Ttl
);
int (*A)(DnsGenerator *g,
const char *Name,
const char *ip,
int Ttl
);
int (*AAAA)(DnsGenerator *g,
const char *Name,
const char *ip,
int Ttl
);
int (*EDns)(DnsGenerator *g, int UdpPayloadSize);
int (*RawData)(DnsGenerator *g,
const char *Name,
DNSRecordType Type,
DNSRecordClass Klass,
const char *Data,
int DataLength,
int Ttl
);
};
int DnsGenerator_Init(DnsGenerator *g,
char *Buffer,
int BufferLength,
const char *CopyFrom,
int SourceLength,
/* Whether to remove every record except question and
answer records. Used when `CopyFrom' is not `NULL'.
*/
BOOL Strip
);
#endif /* _DNS_GENERATOR_H_ */