本文整理汇总了Java中org.xbill.DNS.Message.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java Message.getHeader方法的具体用法?Java Message.getHeader怎么用?Java Message.getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xbill.DNS.Message
的用法示例。
在下文中一共展示了Message.getHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: SMessage
import org.xbill.DNS.Message; //导入方法依赖的package包/类
/**
* Creates a new instance of this class.
*
* @param m The DNS message to wrap.
*/
public SMessage(Message m) {
this(m.getHeader());
this.question = m.getQuestion();
this.oPTRecord = m.getOPT();
for (int i = Section.ANSWER; i <= Section.ADDITIONAL; i++) {
RRset[] rrsets = m.getSectionRRsets(i);
for (int j = 0; j < rrsets.length; j++) {
this.addRRset(new SRRset(rrsets[j]), i);
}
}
}
示例3: 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);
}
}
示例4: getMessage
import org.xbill.DNS.Message; //导入方法依赖的package包/类
/**
* Gets this message as a standard DNSJAVA message.
*
* @return This message as a standard DNSJAVA message.
*/
public Message getMessage() {
// Generate our new message.
Message m = new Message(this.header.getID());
// Convert the header
// We do this for two reasons:
// 1) setCount() is package scope, so we can't do that, and
// 2) setting the header on a message after creating the
// message frequently gets stuff out of sync, leading to malformed wire
// format messages.
Header h = m.getHeader();
h.setOpcode(this.header.getOpcode());
h.setRcode(this.header.getRcode());
for (int i = 0; i < MAX_FLAGS; i++) {
if (Flags.isFlag(i) && this.header.getFlag(i)) {
h.setFlag(i);
}
}
// Add all the records. -- this will set the counts correctly in the
// message header.
if (this.question != null) {
m.addRecord(this.question, Section.QUESTION);
}
for (int sec = Section.ANSWER; sec <= Section.ADDITIONAL; sec++) {
List<SRRset> slist = this.getSectionRRsets(sec);
for (SRRset rrset : slist) {
for (Iterator<?> j = rrset.rrs(); j.hasNext();) {
m.addRecord((Record)j.next(), sec);
}
for (Iterator<?> j = rrset.sigs(); j.hasNext();) {
m.addRecord((Record)j.next(), sec);
}
}
}
if (this.oPTRecord != null) {
m.addRecord(this.oPTRecord, Section.ADDITIONAL);
}
return m;
}