From 89b9c0ef9568415f845ddc387da9a4b2c0433eee Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Wed, 6 Sep 2017 19:55:23 +0800 Subject: [PATCH] Local resolver Response flag fix --- .../itxtech/daedalus/fragment/DNSTestFragment.java | 14 +++++++------- .../org/itxtech/daedalus/provider/UdpProvider.java | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java index 9bc5123..93a28a9 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java @@ -159,13 +159,13 @@ public class DNSTestFragment extends ToolbarFragment { boolean succ = false; try { - DNSMessage.Builder message = DNSMessage.builder(); - message.addQuestion(new Question(domain, type)); - message.setId((new Random()).nextInt()); - message.setRecursionDesired(true); - message.setOpcode(DNSMessage.OPCODE.QUERY); - message.setResponseCode(DNSMessage.RESPONSE_CODE.NO_ERROR); - message.setQrFlag(false); + DNSMessage.Builder message = DNSMessage.builder() + .addQuestion(new Question(domain, type)) + .setId((new Random()).nextInt()) + .setRecursionDesired(true) + .setOpcode(DNSMessage.OPCODE.QUERY) + .setResponseCode(DNSMessage.RESPONSE_CODE.NO_ERROR) + .setQrFlag(false); long startTime = System.currentTimeMillis(); DNSMessage response = dnsQuery.query(message.build(), InetAddress.getByName(server.getAddress()), server.getPort()); diff --git a/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java b/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java index 33297f7..11cc7f2 100644 --- a/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java +++ b/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java @@ -216,12 +216,12 @@ public class UdpProvider extends Provider { * @param responsePayload The payload of the response */ void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload) { - /*try { + try { DNSMessage message = new DNSMessage(responsePayload); Logger.info(message.toString()); } catch (IOException e) { Logger.logException(e); - }*/ + } UdpPacket udpOutPacket = (UdpPacket) requestPacket.getPayload(); UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder(udpOutPacket) .srcPort(udpOutPacket.getHeader().getDstPort()) @@ -322,7 +322,7 @@ public class UdpProvider extends Provider { String response = RuleResolver.resolve(dnsQueryName, dnsMsg.getQuestion().type); if (response != null && dnsMsg.getQuestion().type == Record.TYPE.A) { Logger.info("Provider: Resolved " + dnsQueryName + " Local resolver response: " + response); - DNSMessage.Builder builder = dnsMsg.asBuilder(); + DNSMessage.Builder builder = dnsMsg.asBuilder().setQrFlag(false); int[] ip = new int[4]; byte i = 0; for (String block : response.split("\\.")) { @@ -333,7 +333,7 @@ public class UdpProvider extends Provider { handleDnsResponse(parsedPacket, builder.build().toArray()); } else if (response != null && dnsMsg.getQuestion().type == Record.TYPE.AAAA) { Logger.info("Provider: Resolved " + dnsQueryName + " Local resolver response: " + response); - DNSMessage.Builder builder = dnsMsg.asBuilder(); + DNSMessage.Builder builder = dnsMsg.asBuilder().setQrFlag(false); builder.addAnswer(new Record<>(dnsQueryName, Record.TYPE.AAAA, 1, 64, new AAAA(Inet6Address.getByName(response).getAddress()))); handleDnsResponse(parsedPacket, builder.build().toArray());