Search in sources :

Example 11 with DnsQuestion

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

the class TcpDnsServer method handleQueryResp.

private static void handleQueryResp(DefaultDnsResponse msg) {
    if (msg.count(DnsSection.QUESTION) > 0) {
        DnsQuestion question = msg.recordAt(DnsSection.QUESTION, 0);
        System.out.printf("name: %s%n", question.name());
    }
    for (int i = 0, count = msg.count(DnsSection.ANSWER); i < count; i++) {
        DnsRecord record = msg.recordAt(DnsSection.ANSWER, i);
        if (record.type() == DnsRecordType.A) {
            // just print the IP after query
            DnsRawRecord raw = (DnsRawRecord) record;
            System.out.println(NetUtil.bytesToIpAddress(ByteBufUtil.getBytes(raw.content())));
        }
    }
}
Also used : DnsRawRecord(io.netty.handler.codec.dns.DnsRawRecord) DefaultDnsRawRecord(io.netty.handler.codec.dns.DefaultDnsRawRecord) DefaultDnsQuestion(io.netty.handler.codec.dns.DefaultDnsQuestion) DnsQuestion(io.netty.handler.codec.dns.DnsQuestion) DnsRecord(io.netty.handler.codec.dns.DnsRecord)

Example 12 with DnsQuestion

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

the class DnsResolveContext method followCname.

private void followCname(DnsQuestion question, String cname, DnsQueryLifecycleObserver queryLifecycleObserver, Promise<List<T>> promise) {
    final DnsQuestion cnameQuestion;
    final DnsServerAddressStream stream;
    try {
        cname = cnameResolveFromCache(cnameCache(), cname);
        stream = getNameServers(cname);
        cnameQuestion = new DefaultDnsQuestion(cname, question.type(), dnsClass);
    } catch (Throwable cause) {
        queryLifecycleObserver.queryFailed(cause);
        PlatformDependent.throwException(cause);
        return;
    }
    query(stream, 0, cnameQuestion, queryLifecycleObserver.queryCNAMEd(cnameQuestion), true, promise, null);
}
Also used : DefaultDnsQuestion(io.netty.handler.codec.dns.DefaultDnsQuestion) DnsQuestion(io.netty.handler.codec.dns.DnsQuestion) DefaultDnsQuestion(io.netty.handler.codec.dns.DefaultDnsQuestion)

Example 13 with DnsQuestion

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

the class DnsQueryContext method query.

void query(boolean flush, ChannelPromise writePromise) {
    final DnsQuestion question = question();
    final InetSocketAddress nameServerAddr = nameServerAddr();
    final DnsQuery query = newQuery(id);
    query.setRecursionDesired(recursionDesired);
    query.addRecord(DnsSection.QUESTION, question);
    for (DnsRecord record : additionals) {
        query.addRecord(DnsSection.ADDITIONAL, record);
    }
    if (optResource != null) {
        query.addRecord(DnsSection.ADDITIONAL, optResource);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("{} WRITE: {}, [{}: {}], {}", channel(), protocol(), id, nameServerAddr, question);
    }
    sendQuery(query, flush, writePromise);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DnsQuestion(io.netty.handler.codec.dns.DnsQuestion) DnsQuery(io.netty.handler.codec.dns.DnsQuery) DnsRecord(io.netty.handler.codec.dns.DnsRecord)

Aggregations

DnsQuestion (io.netty.handler.codec.dns.DnsQuestion)13 DefaultDnsQuestion (io.netty.handler.codec.dns.DefaultDnsQuestion)11 DnsRecord (io.netty.handler.codec.dns.DnsRecord)7 DnsRawRecord (io.netty.handler.codec.dns.DnsRawRecord)4 InetSocketAddress (java.net.InetSocketAddress)3 Element (net.sf.ehcache.Element)3 AddressedEnvelope (io.netty.channel.AddressedEnvelope)2 DefaultDnsRawRecord (io.netty.handler.codec.dns.DefaultDnsRawRecord)2 DnsQuery (io.netty.handler.codec.dns.DnsQuery)2 DnsResponse (io.netty.handler.codec.dns.DnsResponse)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 DatagramDnsQuery (io.netty.handler.codec.dns.DatagramDnsQuery)1 DefaultDnsQuery (io.netty.handler.codec.dns.DefaultDnsQuery)1