-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSFactory.java
More file actions
48 lines (41 loc) · 1.48 KB
/
DNSFactory.java
File metadata and controls
48 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Creates new DNSPackets containing a query.
*
* @author Chris Blades
* @version 20/3/10
*/
public class DNSFactory {
/**
* Return a new DNSPacket with a question containing the given url
* and recursion set according to recursionDesired.
*
* @param url the contents of the question in the returned DNSPacket
* @param recursionDesired wether to set the recursion desired flag
* in the returned DNSpacket.
*/
public DNSPacket getPacket(String url, boolean recursionDesired) {
DNSPacket packet = new DNSPacketImpl();
// flags field
DNSFlagsField flags = new DNSFlagsFieldImpl();
flags.setIsRequest(true);
// set recursion desired according to recursionDesired
flags.setRecursionDesired(recursionDesired);
flags.setOpcode(DNSOpcodeEnum.QUERY);
// build header, insert flags
DNSHeader header = new DNSHeaderImpl();
header.setIdentifier(1024);
header.setFlags(flags);
header.setNumQuestions(1);
// build question
DNSQuestion question = new DNSQuestionImpl();
DNSUrl questionUrl = new DNSUrlImpl(url);
DNSRecordType type = DNSRecordTypeEnum.A;
DNSRecordClass clss = DNSRecordClassEnum.IN;
question.setName(questionUrl);
question.setType(type);
question.setClass(clss);
packet.setHeader(header);
packet.setQuestion(question);
return packet;
}
}