本文整理汇总了Java中org.xbill.DNS.Message.addRecord方法的典型用法代码示例。如果您正苦于以下问题:Java Message.addRecord方法的具体用法?Java Message.addRecord怎么用?Java Message.addRecord使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xbill.DNS.Message
的用法示例。
在下文中一共展示了Message.addRecord方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getCached
import org.xbill.DNS.Message; //导入方法依赖的package包/类
private Message getCached(Message query) {
Cache cache = getCache();
if (cache == null)
return null;
Record question = query.getQuestion();
RRset[] rrsets = cache.findAnyRecords(question.getName(), question.getType());
if (rrsets == null)
return null;
Message msg = new Message();
for (RRset rrset : rrsets) {
@SuppressWarnings("unchecked")
Iterator<Record> recordsIter = rrset.rrs();
while (recordsIter.hasNext()) {
msg.addRecord(recordsIter.next(), Section.ANSWER);
}
}
return msg;
}
示例3: testValidAnswerToDifferentQueryTypeIsBogus
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testValidAnswerToDifferentQueryTypeIsBogus() throws IOException {
Message m = resolver.send(createMessage("www.ingotronic.ch./A"));
Message message = createMessage("www.ingotronic.ch./MX");
for (int i = 1; i < Section.ADDITIONAL; i++) {
for (Record r: m.getSectionArray(i)) {
message.addRecord(r, i);
}
}
add("www.ingotronic.ch./A", message);
Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
assertEquals("validate.response.unknown:UNKNOWN", getReason(response));
}
示例4: testUnsignedThatMustBeSigned
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testUnsignedThatMustBeSigned() throws IOException {
Name query = Name.fromString("www.ingotronic.ch.");
// prepare a faked, unsigned response message that must have a signature
// to be valid
Message message = new Message();
message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
add("www.ingotronic.ch./A", message);
Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
assertEquals("validate.bogus.missingsig", getReason(response));
}
示例5: testModifiedSignature
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testModifiedSignature() throws IOException {
Name query = Name.fromString("www.ingotronic.ch.");
// prepare a faked, unsigned response message that must have a signature
// to be valid
Message message = new Message();
message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
message.addRecord(new RRSIGRecord(query, DClass.IN, 0, Type.A, Algorithm.RSASHA256, 5, new Date(System.currentTimeMillis() + 5000), new Date(System.currentTimeMillis() - 5000), 1234, Name.fromString("ingotronic.ch."), new byte[] { 1, 2, 3 }), Section.ANSWER);
add("www.ingotronic.ch./A", message);
Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
assertTrue(getReason(response).startsWith("failed.answer.positive:{ www.ingotronic.ch."));
}
示例6: messageWithRCode
import org.xbill.DNS.Message; //导入方法依赖的package包/类
private Message messageWithRCode(String query, int rcode) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
result.getHeader().setRcode(rcode);
return result;
}
示例7: messageWithNodes
import org.xbill.DNS.Message; //导入方法依赖的package包/类
private Message messageWithNodes(String query, Iterable<String> names) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
for (String name1 : names){
result.addRecord(new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)), Section.ANSWER);
}
return result;
}
示例8: testHasSignedNsecsWithoutSignedSigsReturnsFalse
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testHasSignedNsecsWithoutSignedSigsReturnsFalse() {
Message m = new Message();
m.addRecord(new NSECRecord(Name.root, DClass.IN, 0, Name.root, new int[] { Type.A }), Section.AUTHORITY);
SMessage sm = new SMessage(m);
boolean result = new ValUtils().hasSignedNsecs(sm);
assertFalse(result);
}
示例9: stripAdditional
import org.xbill.DNS.Message; //导入方法依赖的package包/类
private Message stripAdditional(Message m) {
if (m.getQuestion().getType() == Type.RRSIG) {
return m;
}
Message copy = new Message();
copy.setHeader(m.getHeader());
for (int i = 0; i < Section.ADDITIONAL; i++) {
for (RRset set : m.getSectionRRsets(i)) {
if (set.getType() == Type.NS && m.getQuestion().getType() != Type.NS) {
continue;
}
Iterator<?> rrs = set.rrs();
while (rrs.hasNext()) {
copy.addRecord((Record)rrs.next(), i);
}
Iterator<?> sigs = set.sigs();
while (sigs.hasNext()) {
copy.addRecord((Record)sigs.next(), i);
}
}
}
return copy;
}
示例10: testGetSectionByType
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test()
public void testGetSectionByType() throws UnknownHostException {
Message m = new Message();
Record r1 = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0}));
m.addRecord(r1, Section.ANSWER);
Record r2 = new AAAARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}));
m.addRecord(r2, Section.ANSWER);
SMessage sm = new SMessage(m);
SRRset[] result = sm.getSectionRRsets(Section.ANSWER, Type.A);
assertEquals(1, result.length);
assertEquals(Type.A, result[0].getType());
}
示例11: testReturnOriginalRcodeIfPrimaryQueryFails
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test
public void testReturnOriginalRcodeIfPrimaryQueryFails() throws IOException {
Message message = new Message();
message.getHeader().setRcode(Rcode.REFUSED);
message.addRecord(Record.newRecord(Name.fromString("www.ingotronic.ch."), Type.A, DClass.IN), Section.QUESTION);
add("www.ingotronic.ch./A", message);
Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
// rfc4035#section-5.5
assertEquals(Rcode.REFUSED, response.getRcode());
assertEquals("failed.nodata", getReason(response));
}
示例12: testAnswerSectionSearchFound
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test()
public void testAnswerSectionSearchFound() throws UnknownHostException {
Message m = new Message();
Record r = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0}));
m.addRecord(r, Section.ANSWER);
SMessage sm = new SMessage(m);
SRRset result = sm.findAnswerRRset(Name.root, Type.A, DClass.IN);
assertEquals(r, result.first());
}
示例13: testAnswerSectionSearchNotFoundDifferentClass
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test()
public void testAnswerSectionSearchNotFoundDifferentClass() throws UnknownHostException {
Message m = new Message();
Record r = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0}));
m.addRecord(r, Section.ANSWER);
SMessage sm = new SMessage(m);
SRRset result = sm.findAnswerRRset(Name.root, Type.A, DClass.CH);
assertNull(result);
}
示例14: testAnswerSectionSearchNotFoundDifferentType
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test()
public void testAnswerSectionSearchNotFoundDifferentType() throws UnknownHostException {
Message m = new Message();
Record r = new ARecord(Name.root, DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0}));
m.addRecord(r, Section.ANSWER);
SMessage sm = new SMessage(m);
SRRset result = sm.findAnswerRRset(Name.root, Type.MX, DClass.IN);
assertNull(result);
}
示例15: testAnswerSectionSearchNotFoundDifferentName
import org.xbill.DNS.Message; //导入方法依赖的package包/类
@Test()
public void testAnswerSectionSearchNotFoundDifferentName() throws UnknownHostException, TextParseException {
Message m = new Message();
Record r = new ARecord(Name.fromString("asdf."), DClass.IN, 0, InetAddress.getByAddress(new byte[]{0,0,0,0}));
m.addRecord(r, Section.ANSWER);
SMessage sm = new SMessage(m);
SRRset result = sm.findAnswerRRset(Name.root, Type.MX, DClass.IN);
assertNull(result);
}