Skip to content

Commit

Permalink
Merge pull request #1264 from pi-hole/new/telnet-dns-port
Browse files Browse the repository at this point in the history
Return DNS port on ">dns-port" telnet command
  • Loading branch information
DL6ER authored Dec 29, 2021
2 parents 106ef8c + 43f79ae commit e9db358
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1473,3 +1473,9 @@ void delete_lease(const char *client_message, const int *sock)
if(config.debug & DEBUG_API)
logg("...done");
}

void getDNSport(const int *sock)
{
// Return DNS port used by FTL
ssend(*sock, "%d\n", config.dns_port);
}
1 change: 1 addition & 0 deletions src/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void getUnknownQueries(const int *sock);

// DNS resolver methods (dnsmasq_interface.c)
void getCacheInformation(const int *sock);
void getDNSport(const int *sock);

// MessagePack serialization helpers
void pack_eom(const int sock);
Expand Down
5 changes: 5 additions & 0 deletions src/api/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ void process_request(const char *client_message, int *sock)
processed = true;
delete_lease(client_message, sock);
}
else if(command(client_message, ">dns-port"))
{
processed = true;
getDNSport(sock);
}

// Test only at the end if we want to quit or kill
// so things can be processed before
Expand Down
7 changes: 7 additions & 0 deletions test/test_suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
[[ ${lines[6]} == "" ]]
}

@test "DNS server port is reported" {
run bash -c 'echo ">dns-port >quit" | nc -v 127.0.0.1 4711'
printf "%s\n" "${lines[@]}"
[[ ${lines[1]} == "53" ]]
[[ ${lines[2]} == "" ]]
}

@test "Running a second instance is detected and prevented" {
run bash -c 'su pihole -s /bin/sh -c "/home/pihole/pihole-FTL -f"'
printf "%s\n" "${lines[@]}"
Expand Down

0 comments on commit e9db358

Please sign in to comment.