forked from yaosj2k/dnsforwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsgenerator.h
executable file
·100 lines (70 loc) · 2.98 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
#ifndef _DNS_GENERATOR_H_
#define _DNS_GENERATOR_H_
#include <string.h>
#include "dnsparser.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)
extern const char OptPseudoRecord[];
#define OPT_PSEUDORECORD_LENGTH 11
char *DNSLabelizedName(__inout char *Origin, __in size_t OriginSpaceLength);
int DNSCompress(__inout char *DNSBody, __in int DNSBodyLength);
int DNSGenerateData(__in char *Data,
__out void *Buffer,
__in size_t BufferLength,
__in const ElementDescriptor *Descriptor
);
char *DNSGenHeader( __out char *Buffer,
__in unsigned short QueryIdentifier,
__in DNSFlags Flags,
__in unsigned short QuestionCount,
__in unsigned short AnswerCount,
__in unsigned short NameServerCount,
__in unsigned short AdditionalCount
);
int DNSGenQuestionRecord(__out char *Buffer,
__in int BufferLength,
__in const char *Name,
__in uint16_t Type,
__in uint16_t Class
);
int DNSGenResourceRecord( __out char *Buffer,
__in int BufferLength,
__in const char *Name,
__in uint16_t Type,
__in uint16_t Class,
__in uint32_t TTL,
__in const void *Data,
__in uint16_t DataLength,
__in BOOL LablelizedData
);
#define DNSSetName(here, labeled_name) (memcpy((here), (labeled_name), strlen(labeled_name) + 1), \
((char *)here) + strlen(labeled_name) + 1)
#define DNSSetResourceDataLength(ans_start_ptr, len) SET_16_BIT_U_INT(DNSJumpOverName(ans_start_ptr) + 8, len)
int DNSAppendAnswerRecord(__inout char *OriginBody, __in char *Record, __in int RecordLength);
#define EDNS_REMOVED 1
#define EDNS_NO_AR 0
#define EDNS_NOT_EDNS (-1)
int DNSRemoveEDNSPseudoRecord(char *RequestContent, int *RequestLength);
void DNSAppendEDNSPseudoRecord(char *RequestContent, int *RequestLength);
/**
New Implementation
*/
typedef struct _DnsGenerator DnsGenerator;
struct _DnsGenerator {
/* private */
char *Buffer;
int BufferLength;
char *Itr;
void *NumberOfRecords;
/* public */
DNSHeader *Header;
};
#endif /* _DNS_GENERATOR_H_ */