Skip to content

Commit

Permalink
[client] Log which DNS-server lookup mechanism return which IPs
Browse files Browse the repository at this point in the history
Related to issue #131.
  • Loading branch information
Flowdalic committed Jun 9, 2024
1 parent cae24db commit 3363d8e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions minidns-client/src/main/java/org/minidns/DnsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,33 @@ protected MiniDnsFuture<DnsQueryResult, IOException> queryAsync(DnsMessage.Build
*/
public static List<String> findDNS() {
List<String> res = null;
final Level TRACE_LOG_LEVEL = Level.FINE;
for (DnsServerLookupMechanism mechanism : LOOKUP_MECHANISMS) {
try {
res = mechanism.getDnsServerAddresses();
} catch (SecurityException exception) {
LOGGER.log(Level.WARNING, "Could not lookup DNS server", exception);
}
if (res == null) {
LOGGER.log(TRACE_LOG_LEVEL, "DnsServerLookupMechanism '" + mechanism.getName() + "' did not return any DNS server");
continue;
}

if (LOGGER.isLoggable(TRACE_LOG_LEVEL)) {
// TODO: Use String.join() once MiniDNS is Android API 26 (or higher).
StringBuilder sb = new StringBuilder();
for (Iterator<String> it = res.iterator(); it.hasNext();) {
String s = it.next();
sb.append(s);
if (it.hasNext()) {
sb.append(", ");
}
}
String dnsServers = sb.toString();
LOGGER.log(TRACE_LOG_LEVEL, "DnsServerLookupMechanism '{0}' returned the following DNS servers: {1}",
new Object[] { mechanism.getName(), dnsServers });
}

assert !res.isEmpty();

// We could cache if res only contains IP addresses and avoid the verification in case. Not sure if its really that beneficial
Expand Down

0 comments on commit 3363d8e

Please sign in to comment.