From 363b2dca3746c0e6a5b519b6e375a5f44799e695 Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Thu, 7 Dec 2017 22:38:21 +0300 Subject: [PATCH] Flush DNS cache if --dns-addr is used --- dnsredir.c | 16 ++++++++++++++++ dnsredir.h | 2 ++ goodbyedpi.c | 1 + 3 files changed, 19 insertions(+) diff --git a/dnsredir.c b/dnsredir.c index 3ba931d..c530592 100644 --- a/dnsredir.c +++ b/dnsredir.c @@ -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) { diff --git a/dnsredir.h b/dnsredir.h index 013048f..f23215c 100644 --- a/dnsredir.h +++ b/dnsredir.h @@ -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(); diff --git a/goodbyedpi.c b/goodbyedpi.c index 8178046..e9bb413 100644 --- a/goodbyedpi.c +++ b/goodbyedpi.c @@ -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':