Flush DNS cache if --dns-addr is used

This commit is contained in:
ValdikSS 2017-12-07 22:38:21 +03:00
parent 1e8835cfe5
commit 363b2dca37
3 changed files with 19 additions and 0 deletions

View File

@ -50,6 +50,22 @@ typedef struct udp_connrecord {
static time_t last_cleanup = 0;
static udp_connrecord_t *conntrack = NULL;
void flush_dns_cache() {
BOOL WINAPI (*DnsFlushResolverCache)();
HMODULE dnsapi = LoadLibrary("dnsapi.dll");
if (dnsapi == NULL)
{
printf("Can't load dnsapi.dll to flush DNS cache!\n");
exit(EXIT_FAILURE);
}
DnsFlushResolverCache = GetProcAddress(dnsapi, "DnsFlushResolverCache");
if (DnsFlushResolverCache == NULL || !DnsFlushResolverCache())
printf("Can't flush DNS cache!");
FreeLibrary(dnsapi);
}
inline static void construct_key(const uint32_t srcip, const uint16_t srcport, char *key) {
debug("Construct key enter\n");
if (key) {

View File

@ -15,3 +15,5 @@ int dns_handle_incoming(const uint32_t srcip, const uint16_t srcport,
int dns_handle_outgoing(const uint32_t srcip, const uint16_t srcport,
const uint32_t dstip, const uint16_t dstport,
const char *packet_data, const UINT packet_dataLen);
void flush_dns_cache();

View File

@ -337,6 +337,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
add_filter_str(IPPROTO_UDP, 53);
flush_dns_cache();
}
break;
case 'g':