From 2211385a61fac480d31a28b9570198696107c61f Mon Sep 17 00:00:00 2001 From: "Danilo E. F. Bento" Date: Tue, 21 Mar 2017 21:18:58 -0300 Subject: [PATCH 1/3] circunvent compilation alerts --- dns_proxy.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dns_proxy.c b/dns_proxy.c index 214f2db..4538b8c 100644 --- a/dns_proxy.c +++ b/dns_proxy.c @@ -146,6 +146,9 @@ void parse_resolv_conf() { // handle children void reaper_handle (int sig) { + // use sig as a source for an assignment to circunvent an unused parameter warning + // add 1 to sig in the assignment to circunvent a self assign warning + sig = sig + 1; while (waitpid(-1, NULL, WNOHANG) > 0) { }; } From 998c08980f35fe917c2ede8c8393474ab4930a21 Mon Sep 17 00:00:00 2001 From: "Danilo E. F. Bento" Date: Tue, 21 Mar 2017 21:36:40 -0300 Subject: [PATCH 2/3] add all to .PHONY, CFLAGS from environment if defined, compiler (CC) from environment or make utility, rm -f to avoid errors if already removed --- Makefile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 6452bd1..f12d5e0 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ -FLAGS=-Wall -Wextra -all: - gcc $(FLAGS) -o dns_proxy dns_proxy.c -.PHONY : clean +.PHONY : all clean + +CFLAGS ?= -Wall -Wextra + +daemon_name = dns_proxy + +all: $(daemon_name) + +$(daemon_name): $(daemon_name).c + clean : - -rm dns_proxy + -rm -f $(daemon_name) From e0e232be6d9a7c3933624b4310f93c6076075677 Mon Sep 17 00:00:00 2001 From: "Danilo E. F. Bento" Date: Tue, 21 Mar 2017 21:44:42 -0300 Subject: [PATCH 3/3] it was not using the last DNS server from the DNS servers list, X % N results [0, N) --- dns_proxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dns_proxy.c b/dns_proxy.c index 4538b8c..231f039 100644 --- a/dns_proxy.c +++ b/dns_proxy.c @@ -176,7 +176,7 @@ void tcp_query(void *query, response *buffer, int len) { srand(time(NULL)); // select random dns server - in_addr_t remote_dns = inet_addr(dns_servers[rand() % (NUM_DNS - 1)]); + in_addr_t remote_dns = inet_addr(dns_servers[rand() % NUM_DNS]); memcpy(tmp, "\x05\x01\x00\x01", 4); memcpy(tmp + 4, &remote_dns, 4); memcpy(tmp + 8, "\x00\x35", 2);