@Test
 public void testResolveLocalhost() throws Exception {
   DnsResolver resolver = new SystemDefaultDnsResolver();
   assertNotNull(resolver.resolve("127.0.0.1"));
   assertEquals("Should resolve to 1 address", 1, resolver.resolve("127.0.0.1").length);
   assertTrue("Should resolve localhost", resolver.resolve("localhost").length > 0);
 }
Ejemplo n.º 2
0
 private static SetResponse lookupRecords(
     final Message response, final Record query, final InetAddress source) {
   final Name name = query.getName();
   final int type = query.getType();
   response.getHeader().setFlag(Flags.RA); // always mark the response w/ the recursion available
   // bit
   LOG.debug("DnsResolver: " + RequestType.typeOf(type) + " " + name);
   for (final DnsResolver r : DnsResolvers.resolversFor(query, source)) {
     try {
       final DnsResponse reply = r.lookupRecords(query);
       if (reply == null) {
         LOG.debug("DnsResolver: returned null " + name + " using " + r);
         continue;
       }
       if (reply.isAuthoritative()) { // mark
         response.getHeader().setFlag(Flags.AA);
       }
       if (reply.isNxdomain()) {
         addRRset(name, response, new Record[] {DomainNameRecords.sourceOfAuthority(name)}, type);
         response.getHeader().setRcode(Rcode.NXDOMAIN);
         return SetResponse.ofType(SetResponse.NXDOMAIN);
       } else if (reply.hasAnswer()) {
         for (ResponseSection s : ResponseSection.values()) {
           Record[] records = reply.section(s);
           if (records != null) {
             addRRset(name, response, records, s.section());
           }
         }
         return SetResponse.ofType(SetResponse.SUCCESSFUL);
       }
     } catch (final Exception ex) {
       LOG.debug(
           "DnsResolver: failed for " + name + " using " + r + " because of: " + ex.getMessage(),
           ex);
     }
   }
   return SetResponse.ofType(SetResponse.UNKNOWN); // no dice, return unknown
 }