Search in sources :

Example 1 with RRWithTarget

use of org.minidns.record.RRWithTarget in project minidns by MiniDNS.

the class IterativeDNSClient method resolveIpRecursive.

private IpResultSet resolveIpRecursive(ResolutionState resolutionState, DNSName name) throws IOException {
    IpResultSet.Builder res = newIpResultSetBuilder();
    if (ipVersionSetting.v4) {
        // TODO Try to retrieve A records for name out from cache.
        Question question = new Question(name, TYPE.A);
        final DNSMessage query = getQueryFor(question);
        DNSMessage aMessage = queryRecursive(resolutionState, query);
        if (aMessage != null) {
            for (Record<? extends Data> answer : aMessage.answerSection) {
                if (answer.isAnswer(question)) {
                    InetAddress inetAddress = inetAddressFromRecord(name.ace, (A) answer.payloadData);
                    res.ipv4Addresses.add(inetAddress);
                } else if (answer.type == TYPE.CNAME && answer.name.equals(name)) {
                    return resolveIpRecursive(resolutionState, ((RRWithTarget) answer.payloadData).target);
                }
            }
        }
    }
    if (ipVersionSetting.v6) {
        // TODO Try to retrieve AAAA records for name out from cache.
        Question question = new Question(name, TYPE.AAAA);
        final DNSMessage query = getQueryFor(question);
        DNSMessage aMessage = queryRecursive(resolutionState, query);
        if (aMessage != null) {
            for (Record<? extends Data> answer : aMessage.answerSection) {
                if (answer.isAnswer(question)) {
                    InetAddress inetAddress = inetAddressFromRecord(name.ace, (AAAA) answer.payloadData);
                    res.ipv6Addresses.add(inetAddress);
                } else if (answer.type == TYPE.CNAME && answer.name.equals(name)) {
                    return resolveIpRecursive(resolutionState, ((RRWithTarget) answer.payloadData).target);
                }
            }
        }
    }
    return res.build();
}
Also used : RRWithTarget(org.minidns.record.RRWithTarget) Question(org.minidns.dnsmessage.Question) InetAddress(java.net.InetAddress) DNSMessage(org.minidns.dnsmessage.DNSMessage)

Example 2 with RRWithTarget

use of org.minidns.record.RRWithTarget in project minidns by MiniDNS.

the class DNSMessageTest method testALookup.

@Test
public void testALookup() throws Exception {
    DNSMessage m = getMessageFromResource("sun-a");
    assertFalse(m.authoritativeAnswer);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(2, answers.size());
    Record<? extends Data> cname = answers.get(0);
    Record<? extends Data> a = answers.get(1);
    assertTrue(cname.getPayload() instanceof RRWithTarget);
    assertEquals(TYPE.CNAME, cname.getPayload().getType());
    assertCsEquals("legacy-sun.oraclegha.com", ((RRWithTarget) (cname.getPayload())).target);
    assertCsEquals("legacy-sun.oraclegha.com", a.name);
    assertTrue(a.getPayload() instanceof A);
    assertEquals(TYPE.A, a.getPayload().getType());
    assertCsEquals("156.151.59.35", a.getPayload().toString());
}
Also used : AAAA(org.minidns.record.AAAA) SOA(org.minidns.record.SOA) A(org.minidns.record.A) RRWithTarget(org.minidns.record.RRWithTarget) Record(org.minidns.record.Record) Data(org.minidns.record.Data) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Aggregations

DNSMessage (org.minidns.dnsmessage.DNSMessage)2 RRWithTarget (org.minidns.record.RRWithTarget)2 InetAddress (java.net.InetAddress)1 Test (org.junit.Test)1 Question (org.minidns.dnsmessage.Question)1 A (org.minidns.record.A)1 AAAA (org.minidns.record.AAAA)1 Data (org.minidns.record.Data)1 Record (org.minidns.record.Record)1 SOA (org.minidns.record.SOA)1