当前位置: 首页>>代码示例>>Java>>正文


Java Message.toWire方法代码示例

本文整理汇总了Java中org.xbill.DNS.Message.toWire方法的典型用法代码示例。如果您正苦于以下问题:Java Message.toWire方法的具体用法?Java Message.toWire怎么用?Java Message.toWire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xbill.DNS.Message的用法示例。


在下文中一共展示了Message.toWire方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.xbill.DNS.Message; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	try (DatagramSocket socket = new DatagramSocket()) {
		Message message = new Message();
		Header header = message.getHeader();
		header.setOpcode(Opcode.QUERY);
		header.setID(1);
		header.setRcode(Rcode.NOERROR);
		header.setFlag(Flags.RD);
		message.addRecord(Record.newRecord(new Name("www.xqbase.com."), Type.A, DClass.IN), Section.QUESTION);
		byte[] data = message.toWire();
		DatagramPacket packet = new DatagramPacket(data, data.length, new InetSocketAddress("localhost", 53));
		socket.send(packet);
		data = new byte[65536];
		packet = new DatagramPacket(data, data.length);
		socket.setSoTimeout(2000);
		socket.receive(packet);
		Message response = new Message(Bytes.left(data, packet.getLength()));
		System.out.println(response);
	}
}
 
开发者ID:xqbase,项目名称:ddns,代码行数:21,代码来源:TestDatagram.java

示例2: writeMessage

import org.xbill.DNS.Message; //导入方法依赖的package包/类
private void writeMessage(OutputStream outputStream, Message message) throws IOException {
  byte[] messageData = message.toWire();
  checkArgument(
      messageData.length <= MESSAGE_MAXIMUM_LENGTH,
      "DNS request message larger than maximum of %s: %s",
      MESSAGE_MAXIMUM_LENGTH,
      messageData.length);
  ByteBuffer buffer = ByteBuffer.allocate(messageData.length + MESSAGE_LENGTH_FIELD_BYTES);
  buffer.putShort((short) messageData.length);
  buffer.put(messageData);
  outputStream.write(buffer.array());
}
 
开发者ID:google,项目名称:nomulus,代码行数:13,代码来源:DnsMessageTransport.java

示例3: messageToBytesWithLength

import org.xbill.DNS.Message; //导入方法依赖的package包/类
private byte[] messageToBytesWithLength(Message message) {
  byte[] bytes = message.toWire();
  ByteBuffer buffer =
      ByteBuffer.allocate(bytes.length + DnsMessageTransport.MESSAGE_LENGTH_FIELD_BYTES);
  buffer.putShort((short) bytes.length);
  buffer.put(bytes);
  return buffer.array();
}
 
开发者ID:google,项目名称:nomulus,代码行数:9,代码来源:DnsMessageTransportTest.java

示例4: sendQuery

import org.xbill.DNS.Message; //导入方法依赖的package包/类
protected static void sendQuery(Connection connection, Message query) {
    if (connection != null) {
        byte[] out = query.toWire(Message.MAXLENGTH);
        connection.send(out);
    }
}
 
开发者ID:jyeary,项目名称:dnsjnio,代码行数:7,代码来源:AbstractTransaction.java

示例5: process

import org.xbill.DNS.Message; //导入方法依赖的package包/类
/**
 * Processes a DNS query.
 *
 * @param sock
 *            Socket to listen to
 */
private void process(DatagramSocket sock) {
    try {
        byte[] in = new byte[UDP_SIZE];

        // Read the question
        DatagramPacket indp = new DatagramPacket(in, UDP_SIZE);
        indp.setLength(UDP_SIZE);
        sock.receive(indp);
        Message msg = new Message(in);
        Header header = msg.getHeader();

        Record question = msg.getQuestion();

        // Prepare a response
        Message response = new Message(header.getID());
        response.getHeader().setFlag(Flags.QR);
        response.addRecord(question, Section.QUESTION);

        Name name = question.getName();
        boolean hasRecords = false;

        String txt = txtRecords.get(name.toString(true));
        if (question.getType() == Type.TXT && txt != null) {
            response.addRecord(new TXTRecord(name, DClass.IN, TTL, txt), Section.ANSWER);
            hasRecords = true;
            LOG.info("dns-01: {} {} IN TXT \"{}\"", name, TTL, txt);
        }

        InetAddress a = aRecords.get(name.toString(true));
        if (question.getType() == Type.A && a != null) {
            response.addRecord(new ARecord(name, DClass.IN, TTL, a), Section.ANSWER);
            hasRecords = true;
            LOG.info("dns-01: {} {} IN A {}", name, TTL, a.getHostAddress());
        }

        if (!hasRecords) {
            response.getHeader().setRcode(Rcode.NXDOMAIN);
            LOG.warn("dns-01: Cannot answer: {}", question);
        }

        // Send the response
        byte[] resp = response.toWire();
        DatagramPacket outdp = new DatagramPacket(resp, resp.length, indp.getAddress(), indp.getPort());
        sock.send(outdp);
    } catch (Exception ex) {
        LOG.error("Failed to process query", ex);
    }
}
 
开发者ID:shred,项目名称:acme4j,代码行数:55,代码来源:DnsServer.java


注:本文中的org.xbill.DNS.Message.toWire方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。