org.xbill.DNS.Message.getQuestion()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(13.9k)|赞(0)|评价(0)|浏览(253)

本文整理了Java中org.xbill.DNS.Message.getQuestion()方法的一些代码示例,展示了Message.getQuestion()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getQuestion()方法的具体详情如下:
包路径:org.xbill.DNS.Message
类名称:Message
方法名:getQuestion

Message.getQuestion介绍

暂无

代码示例

代码示例来源:origin: julian-klode/dns66

return;
if (dnsMsg.getQuestion() == null) {
  Log.i(TAG, "handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
  return;
String dnsQueryName = dnsMsg.getQuestion().getName().toString(true);
if (!ruleDatabase.isBlocked(dnsQueryName.toLowerCase(Locale.ENGLISH))) {
  Log.i(TAG, "handleDnsRequest: DNS Name " + dnsQueryName + " Allowed, sending to " + destAddr);

代码示例来源:origin: OpenNMS/opennms

public byte[] errorMessage(final Message query, final int rcode) {
    return buildErrorMessage(query.getHeader(), rcode, query.getQuestion());
  }
}

代码示例来源:origin: dnsjava/dnsjava

public byte []
errorMessage(Message query, int rcode) {
  return buildErrorMessage(query.getHeader(), rcode,
         query.getQuestion());
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

/**
 * Generate an error message based on inbound query.
 *
 * @param query the query.
 * @param rcode the response code for the specific error.
 * @return the error message.
 */
public byte[] errorMessage(Message query, int rcode) {
 return buildErrorMessage(query.getHeader(), rcode,
   query.getQuestion());
}

代码示例来源:origin: org.jboss.resteasy/resteasy-eagledns-fork

private byte[] errorMessage(Message query, int rcode) {
  return buildErrorMessage(query.getHeader(), rcode, query.getQuestion());
}

代码示例来源:origin: org.echocat.jomon.net/common

public byte[] errorMessage(Message query, int rcode) {
  return buildErrorMessage(query.getHeader(), rcode, query.getQuestion());
}

代码示例来源:origin: dnsjava/dnsjava

/**
 * Asynchronously sends a message to a single server, registering a listener
 * to receive a callback on success or exception.  Multiple asynchronous
 * lookups can be performed in parallel.  Since the callback may be invoked
 * before the function returns, external synchronization is necessary.
 * @param query The query to send
 * @param listener The object containing the callbacks.
 * @return An identifier, which is also a parameter in the callback
 */
public Object
sendAsync(final Message query, final ResolverListener listener) {
  final Object id;
  synchronized (this) {
    id = new Integer(uniqueID++);
  }
  Record question = query.getQuestion();
  String qname;
  if (question != null)
    qname = question.getName().toString();
  else
    qname = "(none)";
  String name = this.getClass() + ": " + qname;
  Thread thread = new ResolveThread(this, query, id, listener);
  thread.setName(name);
  thread.setDaemon(true);
  thread.start();
  return id;
}

代码示例来源:origin: net.sf.dnsjava-osgi/dnsjava-osgi

/**
 * Asynchronously sends a message to a single server, registering a listener
 * to receive a callback on success or exception.  Multiple asynchronous
 * lookups can be performed in parallel.  Since the callback may be invoked
 * before the function returns, external synchronization is necessary.
 * @param query The query to send
 * @param listener The object containing the callbacks.
 * @return An identifier, which is also a parameter in the callback
 */
public Object
sendAsync(final Message query, final ResolverListener listener) {
  final Object id;
  synchronized (this) {
    id = new Integer(uniqueID++);
  }
  Record question = query.getQuestion();
  String qname;
  if (question != null)
    qname = question.getName().toString();
  else
    qname = "(none)";
  String name = this.getClass() + ": " + qname;
  Thread thread = new ResolveThread(this, query, id, listener);
  thread.setName(name);
  thread.setDaemon(true);
  thread.start();
  return id;
}

代码示例来源:origin: tiandawu/IotXmpp

/**
 * Asynchronously sends a message to a single server, registering a listener
 * to receive a callback on success or exception.  Multiple asynchronous
 * lookups can be performed in parallel.  Since the callback may be invoked
 * before the function returns, external synchronization is necessary.
 * @param query The query to send
 * @param listener The object containing the callbacks.
 * @return An identifier, which is also a parameter in the callback
 */
public Object
sendAsync(final Message query, final ResolverListener listener) {
  final Object id;
  synchronized (this) {
    id = new Integer(uniqueID++);
  }
  Record question = query.getQuestion();
  String qname;
  if (question != null)
    qname = question.getName().toString();
  else
    qname = "(none)";
  String name = this.getClass() + ": " + qname;
  Thread thread = new ResolveThread(this, query, id, listener);
  thread.setName(name);
  thread.setDaemon(true);
  thread.start();
  return id;
}

代码示例来源:origin: org.littleshoot/dnsjava

/**
 * Asynchronously sends a message to a single server, registering a listener
 * to receive a callback on success or exception.  Multiple asynchronous
 * lookups can be performed in parallel.  Since the callback may be invoked
 * before the function returns, external synchronization is necessary.
 * @param query The query to send
 * @param listener The object containing the callbacks.
 * @return An identifier, which is also a parameter in the callback
 */
public Object
sendAsync(final Message query, final ResolverListener listener) {
  final Object id;
  synchronized (this) {
    id = new Integer(uniqueID++);
  }
  Record question = query.getQuestion();
  String qname;
  if (question != null)
    qname = question.getName().toString();
  else
    qname = "(none)";
  String name = this.getClass() + ": " + qname;
  Thread thread = new ResolveThread(this, query, id, listener);
  thread.setName(name);
  thread.setDaemon(true);
  thread.start();
  return id;
}

代码示例来源:origin: org.jboss.resteasy/resteasy-eagledns-fork

Message query = new Message(inDataPacket.getData());
log.debug("UDP query " + EagleDNS.toString(query.getQuestion()) + " from " + inDataPacket.getSocketAddress());

代码示例来源:origin: github/elasticsearch-srv-discovery

@Override
  public Message send(Message query) throws IOException {
    final String HOSTNAME = "localhost.";
    if (query.getQuestion().getName().toString().equals(Constants.TEST_QUERY)) {
      Record question = Record.newRecord(query.getQuestion().getName(), Type.SRV, DClass.IN);
      Message queryMessage = Message.newQuery(question);
      Message result = new Message();
      result.setHeader(queryMessage.getHeader());
      result.addRecord(question, Section.QUESTION);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_0_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_1_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_2_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_3_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      result.addRecord(new SRVRecord(query.getQuestion().getName(), DClass.IN, 1, 1, 1, Constants.NODE_4_TRANSPORT_TCP_PORT, Name.fromString(HOSTNAME)), Section.ANSWER);
      return result;
    }
    if (query.getQuestion().getName().toString().equals(HOSTNAME)) {
      Record question = Record.newRecord(query.getQuestion().getName(), Type.A, DClass.IN);
      Message queryMessage = Message.newQuery(question);
      Message result = new Message();
      result.setHeader(queryMessage.getHeader());
      result.addRecord(question, Section.QUESTION);
      result.addRecord(new ARecord(query.getQuestion().getName(), DClass.IN, 1, InetAddress.getLoopbackAddress()), Section.ANSWER);
      return result;
    }
    throw new IllegalArgumentException("Unknown test query: " + query.getQuestion().getName().toString());
  }
};

代码示例来源:origin: org.littleshoot/dnsjava

private Message
sendAXFR(Message query) throws IOException {
  Name qname = query.getQuestion().getName();
  ZoneTransferIn xfrin = ZoneTransferIn.newAXFR(qname, address, tsig);
  xfrin.setTimeout((int)(getTimeout() / 1000));
  xfrin.setLocalAddress(localAddress);
  try {
    xfrin.run();
  }
  catch (ZoneTransferException e) {
    throw new WireParseException(e.getMessage());
  }
  List records = xfrin.getAXFR();
  Message response = new Message(query.getHeader().getID());
  response.getHeader().setFlag(Flags.AA);
  response.getHeader().setFlag(Flags.QR);
  response.addRecord(query.getQuestion(), Section.QUESTION);
  Iterator it = records.iterator();
  while (it.hasNext())
    response.addRecord((Record)it.next(), Section.ANSWER);
  return response;
}

代码示例来源:origin: dnsjava/dnsjava

private Message
sendAXFR(Message query) throws IOException {
  Name qname = query.getQuestion().getName();
  ZoneTransferIn xfrin = ZoneTransferIn.newAXFR(qname, address, tsig);
  xfrin.setTimeout((int)(getTimeout() / 1000));
  xfrin.setLocalAddress(localAddress);
  try {
    xfrin.run();
  }
  catch (ZoneTransferException e) {
    throw new WireParseException(e.getMessage());
  }
  List records = xfrin.getAXFR();
  Message response = new Message(query.getHeader().getID());
  response.getHeader().setFlag(Flags.AA);
  response.getHeader().setFlag(Flags.QR);
  response.addRecord(query.getQuestion(), Section.QUESTION);
  Iterator it = records.iterator();
  while (it.hasNext())
    response.addRecord((Record)it.next(), Section.ANSWER);
  return response;
}

代码示例来源:origin: net.sf.dnsjava-osgi/dnsjava-osgi

private Message
sendAXFR(Message query) throws IOException {
  Name qname = query.getQuestion().getName();
  ZoneTransferIn xfrin = ZoneTransferIn.newAXFR(qname, address, tsig);
  xfrin.setTimeout((int)(getTimeout() / 1000));
  xfrin.setLocalAddress(localAddress);
  try {
    xfrin.run();
  }
  catch (ZoneTransferException e) {
    throw new WireParseException(e.getMessage());
  }
  List records = xfrin.getAXFR();
  Message response = new Message(query.getHeader().getID());
  response.getHeader().setFlag(Flags.AA);
  response.getHeader().setFlag(Flags.QR);
  response.addRecord(query.getQuestion(), Section.QUESTION);
  Iterator it = records.iterator();
  while (it.hasNext())
    response.addRecord((Record)it.next(), Section.ANSWER);
  return response;
}

代码示例来源:origin: tiandawu/IotXmpp

private Message
sendAXFR(Message query) throws IOException {
  Name qname = query.getQuestion().getName();
  ZoneTransferIn xfrin = ZoneTransferIn.newAXFR(qname, address, tsig);
  xfrin.setTimeout((int)(getTimeout() / 1000));
  xfrin.setLocalAddress(localAddress);
  try {
    xfrin.run();
  }
  catch (ZoneTransferException e) {
    throw new WireParseException(e.getMessage());
  }
  List records = xfrin.getAXFR();
  Message response = new Message(query.getHeader().getID());
  response.getHeader().setFlag(Flags.AA);
  response.getHeader().setFlag(Flags.QR);
  response.addRecord(query.getQuestion(), Section.QUESTION);
  Iterator it = records.iterator();
  while (it.hasNext())
    response.addRecord((Record)it.next(), Section.ANSWER);
  return response;
}

代码示例来源:origin: RIPE-NCC/hadoop-pcap

@Override
protected void processPacketPayload(Packet packet, byte[] payload) {
  String protocol = (String)packet.get(Packet.PROTOCOL);
  if (!PcapReader.PROTOCOL_UDP.equals(protocol) && !PcapReader.PROTOCOL_TCP.equals(protocol))
    return;
  DnsPacket dnsPacket = (DnsPacket)packet;
  if (DNS_PORT == (Integer)packet.get(Packet.SRC_PORT) || DNS_PORT == (Integer)packet.get(Packet.DST_PORT)) {
    if (PROTOCOL_TCP.equals(protocol) &&
      payload.length > 2) // TODO Support DNS responses with multiple messages (as used for XFRs)
      payload = Arrays.copyOfRange(payload, 2, payload.length); // First two bytes denote the size of the DNS message, ignore them
    try {
      Message msg = new Message(payload);
      Header header = msg.getHeader();
      dnsPacket.put(DnsPacket.QUERYID, header.getID());
      dnsPacket.put(DnsPacket.FLAGS, header.printFlags());
      dnsPacket.put(DnsPacket.QR, header.getFlag(Flags.QR));
      dnsPacket.put(DnsPacket.OPCODE, Opcode.string(header.getOpcode()));
      dnsPacket.put(DnsPacket.RCODE, Rcode.string(header.getRcode()));
      dnsPacket.put(DnsPacket.QUESTION, convertRecordToString(msg.getQuestion()));
      dnsPacket.put(DnsPacket.QNAME, convertRecordOwnerToString(msg.getQuestion()));
      dnsPacket.put(DnsPacket.QTYPE, convertRecordTypeToInt(msg.getQuestion()));
      dnsPacket.put(DnsPacket.ANSWER, convertRecordsToStrings(msg.getSectionArray(Section.ANSWER)));
      dnsPacket.put(DnsPacket.AUTHORITY, convertRecordsToStrings(msg.getSectionArray(Section.AUTHORITY)));
      dnsPacket.put(DnsPacket.ADDITIONAL, convertRecordsToStrings(msg.getSectionArray(Section.ADDITIONAL)));
    } catch (Exception e) {
      // If we cannot decode a DNS packet we ignore it
    }
  }
}

代码示例来源:origin: org.nhind/dns

/**
 * Processes a DNS error condition and creates an appropriate DNS response.
 * @param request The original DNS request.
 * @param error The error condition that occured.
 * @return A response to the DNS request.
 */
protected Message processError(Message request, DNSError<?> error)
{
  Message errorResponse = null;
  try
  {
    Header respHeader = new Header(request.toWire());
    Message response = new Message();
    response.setHeader(respHeader);
    for (int i = 0; i < 4; i++)
      response.removeAllRecords(i);
    response.addRecord(request.getQuestion(), Section.QUESTION);
    response.getHeader().setFlag(Flags.QR);
    if (request.getHeader().getFlag(Flags.RD))
      response.getHeader().setFlag(Flags.RD);
    respHeader.setRcode(Integer.parseInt(error.getError().toString()));
    return response;
  }
  catch (IOException e) {}
  return errorResponse;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

Record[] assertDNSQueryNotNull(String lookup, int type, int answerCount)
  throws IOException {
 Name name = Name.fromString(lookup);
 Record question = Record.newRecord(name, type, DClass.IN);
 Message query = Message.newQuery(question);
 OPTRecord optRecord = new OPTRecord(4096, 0, 0, Flags.DO, null);
 query.addRecord(optRecord, Section.ADDITIONAL);
 byte[] responseBytes = getRegistryDNS().generateReply(query, null);
 Message response = new Message(responseBytes);
 assertEquals("not successful", Rcode.NOERROR, response.getRcode());
 assertNotNull("Null response", response);
 assertEquals("Questions do not match", query.getQuestion(),
   response.getQuestion());
 Record[] recs = response.getSectionArray(Section.ANSWER);
 assertEquals(answerCount, recs.length);
 assertEquals(recs[0].getType(), type);
 return recs;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

Record[] assertDNSQuery(String lookup, int type, int numRecs)
  throws IOException {
 Name name = Name.fromString(lookup);
 Record question = Record.newRecord(name, type, DClass.IN);
 Message query = Message.newQuery(question);
 OPTRecord optRecord = new OPTRecord(4096, 0, 0, Flags.DO, null);
 query.addRecord(optRecord, Section.ADDITIONAL);
 byte[] responseBytes = getRegistryDNS().generateReply(query, null);
 Message response = new Message(responseBytes);
 assertEquals("not successful", Rcode.NOERROR, response.getRcode());
 assertNotNull("Null response", response);
 assertEquals("Questions do not match", query.getQuestion(),
   response.getQuestion());
 Record[] recs = response.getSectionArray(Section.ANSWER);
 assertEquals("wrong number of answer records",
   isSecure() ? numRecs * 2 : numRecs, recs.length);
 if (isSecure()) {
  boolean signed = false;
  for (Record record : recs) {
   signed = record.getType() == Type.RRSIG;
   if (signed) {
    break;
   }
  }
  assertTrue("No signatures found", signed);
 }
 return recs;
}

相关文章