From 1244835690550b301f3d6585c73280d817aae798 Mon Sep 17 00:00:00 2001 From: Luke Huang Date: Wed, 23 Jan 2019 21:53:13 +0800 Subject: [PATCH] Minor changes to the async DNS query JAVA API 1. refine the naming in DnsPacket and add more comment 2. add comment in DnsResolver Test: built, flashed, booted atest DnsResolverTest DnsPacketTest Change-Id: Ib482d079d6823fd1d9bff163427b7aad38374199 --- core/java/android/net/DnsResolver.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/java/android/net/DnsResolver.java b/core/java/android/net/DnsResolver.java index 6d54264cd8..d3bc3e66fb 100644 --- a/core/java/android/net/DnsResolver.java +++ b/core/java/android/net/DnsResolver.java @@ -43,6 +43,9 @@ import java.util.function.Consumer; /** * Dns resolver class for asynchronous dns querying * + * Note that if a client sends a query with more than 1 record in the question section but + * the remote dns server does not support this, it may not respond at all, leading to a timeout. + * */ public final class DnsResolver { private static final String TAG = "DnsResolver"; @@ -226,19 +229,19 @@ public final class DnsResolver { if (mHeader.rcode != 0) { throw new ParseException("Response error, rcode:" + mHeader.rcode); } - if (mHeader.getSectionCount(ANSECTION) == 0) { + if (mHeader.getRecordCount(ANSECTION) == 0) { throw new ParseException("No available answer"); } - if (mHeader.getSectionCount(QDSECTION) == 0) { + if (mHeader.getRecordCount(QDSECTION) == 0) { throw new ParseException("No question found"); } - // Assume only one question per answer packet. (RFC1035) - mQueryType = mSections[QDSECTION].get(0).nsType; + // Expect only one question in question section. + mQueryType = mRecords[QDSECTION].get(0).nsType; } public @NonNull List getAddresses() { final List results = new ArrayList(); - for (final DnsSection ansSec : mSections[ANSECTION]) { + for (final DnsRecord ansSec : mRecords[ANSECTION]) { // Only support A and AAAA, also ignore answers if query type != answer type. int nsType = ansSec.nsType; if (nsType != mQueryType || (nsType != TYPE_A && nsType != TYPE_AAAA)) {