Search in sources :

Example 1 with DnsRawRecord

use of io.netty.handler.codec.dns.DnsRawRecord in project netty by netty.

the class DnsNameResolverContext method parseAddress.

private InetAddress parseAddress(DnsRecord r, String name) {
    if (!(r instanceof DnsRawRecord)) {
        return null;
    }
    final ByteBuf content = ((ByteBufHolder) r).content();
    final int contentLen = content.readableBytes();
    if (contentLen != INADDRSZ4 && contentLen != INADDRSZ6) {
        return null;
    }
    final byte[] addrBytes = new byte[contentLen];
    content.getBytes(content.readerIndex(), addrBytes);
    try {
        return InetAddress.getByAddress(parent.isDecodeIdn() ? IDN.toUnicode(name) : name, addrBytes);
    } catch (UnknownHostException e) {
        // Should never reach here.
        throw new Error(e);
    }
}
Also used : DnsRawRecord(io.netty.handler.codec.dns.DnsRawRecord) UnknownHostException(java.net.UnknownHostException) ByteBufHolder(io.netty.buffer.ByteBufHolder) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with DnsRawRecord

use of io.netty.handler.codec.dns.DnsRawRecord in project netty by netty.

the class DnsNameResolverContext method buildAliasMap.

private static Map<String, String> buildAliasMap(DnsResponse response) {
    final int answerCount = response.count(DnsSection.ANSWER);
    Map<String, String> cnames = null;
    for (int i = 0; i < answerCount; i++) {
        final DnsRecord r = response.recordAt(DnsSection.ANSWER, i);
        final DnsRecordType type = r.type();
        if (type != DnsRecordType.CNAME) {
            continue;
        }
        if (!(r instanceof DnsRawRecord)) {
            continue;
        }
        final ByteBuf recordContent = ((ByteBufHolder) r).content();
        final String domainName = decodeDomainName(recordContent);
        if (domainName == null) {
            continue;
        }
        if (cnames == null) {
            cnames = new HashMap<String, String>();
        }
        cnames.put(r.name().toLowerCase(Locale.US), domainName.toLowerCase(Locale.US));
    }
    return cnames != null ? cnames : Collections.<String, String>emptyMap();
}
Also used : DnsRawRecord(io.netty.handler.codec.dns.DnsRawRecord) ByteBufHolder(io.netty.buffer.ByteBufHolder) DnsRecordType(io.netty.handler.codec.dns.DnsRecordType) DnsRecord(io.netty.handler.codec.dns.DnsRecord) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 ByteBufHolder (io.netty.buffer.ByteBufHolder)2 DnsRawRecord (io.netty.handler.codec.dns.DnsRawRecord)2 DnsRecord (io.netty.handler.codec.dns.DnsRecord)1 DnsRecordType (io.netty.handler.codec.dns.DnsRecordType)1 UnknownHostException (java.net.UnknownHostException)1