Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One bug fix and two suggestions #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)

5 changes: 4 additions & 1 deletion dns_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) { };
}

Expand Down Expand Up @@ -173,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);
Expand Down