forked from yaosj2k/dnsforwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerydnsbase.h
97 lines (61 loc) · 2.44 KB
/
querydnsbase.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
#ifndef _QUERY_DNS_BASE_H_
#define _QUERY_DNS_BASE_H_
#include "debug.h"
#define PRINT(...) if(ShowMassages == TRUE){ printf(__VA_ARGS__); } DEBUG_FILE(__VA_ARGS__);
#define INFO(...) if(ShowMassages == TRUE){ printf("[INFO] "__VA_ARGS__); } DEBUG_FILE(__VA_ARGS__);
#define ERRORMSG(...) if(ErrorMessages == TRUE){ fprintf(stderr, "[ERROR] "__VA_ARGS__); } DEBUG_FILE(__VA_ARGS__);
typedef enum _DnsQuaryProtocol{
DNS_QUARY_PROTOCOL_UDP = 0,
DNS_QUARY_PROTOCOL_TCP = 1
} DNSQuaryProtocol;
#include <time.h>
#include "common.h"
#include "dnscache.h"
#include "readconfig.h"
#include "extendablebuffer.h"
#include "request_response.h"
/* Global Varibles */
extern ConfigFileInfo ConfigInfo;
extern BOOL ShowMassages;
extern BOOL ErrorMessages;
typedef struct _QueryContext ThreadContext;
struct _QueryContext{
ThreadContext *Head;
ThreadContext *Previous;
SOCKET TCPSocket;
struct sockaddr *LastServer;
SOCKET UDPSocket;
sa_family_t LastFamily;
SOCKET *PrimarySocket;
SOCKET *SecondarySocket;
DNSQuaryProtocol PrimaryProtocolToServer;
char *RequestEntity;
int RequestLength;
const char *RequestingDomain;
DNSRecordType RequestingType;
int RequestingDomainHashValue;
const char *ClientIP;
BOOL Compress;
time_t CurrentTime;
ExtendableBuffer *ResponseBuffer;
/* Do not refer this, let `ResponseBuffer' point to this and use `ResponseBuffer' instead */
ExtendableBuffer ResponseBuffer_Entity;
};
void SetFallBack(BOOL FallBack);
void ShowRefusingMassage(ThreadContext *Context);
void ShowErrorMassage(ThreadContext *Context, char ProtocolCharacter);
void ShowNormalMassage(ThreadContext *Context, int32_t Offset, char ProtocolCharacter);
void ShowBlockedMessage(const char *RequestingDomain, const char *Package, const char *Message);
int DNSFetchFromCache(__in ThreadContext *Context);
int InitAddress(void);
void SetPrimaryProtocol(char *Protocol);
int FetchFromHostsAndCache(ThreadContext *Context);
#define QUERY_RESULT_DISABLE (-1)
#define QUERY_RESULT_ERROR (-2)
int QueryBase(ThreadContext *Context);
void InitContext(ThreadContext *Context, char *RequestEntity);
int GetAnswersByName(ThreadContext *Context, const char *Name, DNSRecordType Type, const char *Agent);
int GetHostsByRaw(const char *RawPackage, StringList *out);
int GetHostsByName(const char *Name, const char *Agent, StringList *out);
int GetMaximumMessageSize(SOCKET sock);
#endif /* _QUERY_DNS_BASE_H_ */