com.antiaction.dns
Class DNSMessage

java.lang.Object
  |
  +--com.antiaction.dns.DNSMessage

public class DNSMessage
extends java.lang.Object

DNS Message, main entry point for dis/assembling DNS packets. As defined in rfc1035.

Version:
2.00
Author:
Nicholas Clarke

Field Summary
protected  java.util.ArrayList an_array
          Array of answer DNS Record objects.
protected  java.util.ArrayList ar_array
          Array of additional DNS Record objects.
protected  java.util.ArrayList arrPackets
          Array of partial packet byte arrays.
protected  DNSHeader dnsheader
          DNS Header object.
protected  DNSName dnsname
          DNS Name object used for domain name de/encoding.
protected  DNSRData dnsrdatabuilder
          DNS RData builder.
protected  java.util.ArrayList ns_array
          Array of authority DNS Record objects.
protected  java.util.ArrayList qd_array
          Array of DNS Question objects.
 
Constructor Summary
DNSMessage()
          Instantiate a new message object.
 
Method Summary
 void addAdditional(DNSRecord rec)
          Add an additional record to the message.
 void addAnswer(DNSRecord rec)
          Add an answer record to the message.
 void addAuthority(DNSRecord rec)
          Add an authority record to the message.
 void addQuestion(DNSQuestion qst)
          Add a copy of the question to the list of questions.
static java.lang.String arrayToString(byte[] pDat)
          Returns a string representation of the array, for debugging purposes.
static java.lang.String arrayToString(byte[] pDat, int pIdx, int pLen)
          Returns a string representation of the array, for debugging purposes.
static java.lang.String arrayToStringIndex(byte[] pDat)
          Returns a string representation of the array, for debugging purposes.
 byte[] assemblePacket()
          Returns a fully assembled message packet.
 void buildPacket()
          Builds the packet internally, use assemblePacket to return a fully built packet.
 void disassemblePacket(byte[] pDat)
          Parses the record header part of a packet.
 java.util.ArrayList getAdditionals()
          Get a copy of the list of additional record objects.
 java.util.ArrayList getAnswers()
          Get a copy of the list of answer record objects.
 java.util.ArrayList getAuthorities()
          Get a copy of the list of authority record objects.
 int getDisassembledLen()
          Returns the length of the previously disassembled record header.
 DNSHeader getHeader()
          Get a copy of the message header object.
 java.util.ArrayList getQuestions()
          Get a copy of the list of question objects.
 java.util.ArrayList getQuestions(java.lang.String qname, int qtype, int qclass)
          Get a copy of the Question objects that match the given arguments.
 java.util.ArrayList getRecords(java.lang.String qname, int rtype, int qtype, int qclass)
          Get a copy of the Record objects that match the given arguments.
 void reset()
          Reset the objects internal state.
 void setAdditionals(java.util.ArrayList qArr)
          Set a copy of the list of authority record objects.
 void setAnswers(java.util.ArrayList qArr)
          Set a copy of the list of answer record objects.
 void setAuthorities(java.util.ArrayList qArr)
          Set a copy of the list of authority record objects.
 void setDebug(boolean b)
          Toggle debug status.
 void setHeader(DNSHeader header)
          Set a copy of the message header object.
 void setQuestions(java.util.ArrayList qArr)
          Set a copy of the list of question objects.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dnsheader

protected DNSHeader dnsheader
DNS Header object.

dnsrdatabuilder

protected DNSRData dnsrdatabuilder
DNS RData builder.

dnsname

protected DNSName dnsname
DNS Name object used for domain name de/encoding.

qd_array

protected java.util.ArrayList qd_array
Array of DNS Question objects.

an_array

protected java.util.ArrayList an_array
Array of answer DNS Record objects.

ns_array

protected java.util.ArrayList ns_array
Array of authority DNS Record objects.

ar_array

protected java.util.ArrayList ar_array
Array of additional DNS Record objects.

arrPackets

protected java.util.ArrayList arrPackets
Array of partial packet byte arrays.
Constructor Detail

DNSMessage

public DNSMessage()
Instantiate a new message object.
Method Detail

reset

public void reset()
Reset the objects internal state.

setDebug

public void setDebug(boolean b)
Toggle debug status.
Parameters:
b - boolean.

buildPacket

public void buildPacket()
                 throws DNSNameException
Builds the packet internally, use assemblePacket to return a fully built packet.
Throws:
DNSNameException - if the domain name is invalid.
See Also:
assemblePacket()

assemblePacket

public byte[] assemblePacket()
                      throws DNSException
Returns a fully assembled message packet.
Returns:
message packet.
See Also:
buildPacket()

getDisassembledLen

public int getDisassembledLen()
Returns the length of the previously disassembled record header.
See Also:
disassemblePacket(byte[])

disassemblePacket

public void disassemblePacket(byte[] pDat)
                       throws DNSException,
                              DNSNameException,
                              DNSRDataException
Parses the record header part of a packet.
Parameters:
pDat - array containing the complete packet.
Throws:
DNSException - if the packet is corrupted.
DNSNameException - if the domain name is invalid.
See Also:
getDisassembledLen()

setHeader

public void setHeader(DNSHeader header)
Set a copy of the message header object.
Parameters:
header - header object.

getHeader

public DNSHeader getHeader()
Get a copy of the message header object.
Returns:
header object.

addQuestion

public void addQuestion(DNSQuestion qst)
Add a copy of the question to the list of questions.
Parameters:
qst - question object.

getQuestions

public java.util.ArrayList getQuestions()
Get a copy of the list of question objects.
Returns:
list of question objects.

setQuestions

public void setQuestions(java.util.ArrayList qArr)
Set a copy of the list of question objects.
Parameters:
qArr - list of question objects.

addAnswer

public void addAnswer(DNSRecord rec)
Add an answer record to the message.
Parameters:
rec - record container object.

getAnswers

public java.util.ArrayList getAnswers()
Get a copy of the list of answer record objects.
Returns:
list of answer record objects.

setAnswers

public void setAnswers(java.util.ArrayList qArr)
Set a copy of the list of answer record objects.
Parameters:
qArr - list of answer record objects.

addAuthority

public void addAuthority(DNSRecord rec)
Add an authority record to the message.
Parameters:
rec - record container object.

getAuthorities

public java.util.ArrayList getAuthorities()
Get a copy of the list of authority record objects.
Returns:
list of authority record objects.

setAuthorities

public void setAuthorities(java.util.ArrayList qArr)
Set a copy of the list of authority record objects.
Parameters:
qArr - list of authority record objects.

addAdditional

public void addAdditional(DNSRecord rec)
Add an additional record to the message.
Parameters:
rec - record container object.

getAdditionals

public java.util.ArrayList getAdditionals()
Get a copy of the list of additional record objects.
Returns:
list of additional record objects.

setAdditionals

public void setAdditionals(java.util.ArrayList qArr)
Set a copy of the list of authority record objects.
Parameters:
qArr - list of authority record objects.

getQuestions

public java.util.ArrayList getQuestions(java.lang.String qname,
                                        int qtype,
                                        int qclass)
Get a copy of the Question objects that match the given arguments.
Returns:
a list of Question objects.

getRecords

public java.util.ArrayList getRecords(java.lang.String qname,
                                      int rtype,
                                      int qtype,
                                      int qclass)
Get a copy of the Record objects that match the given arguments.
Returns:
a list of Record objects.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

arrayToString

public static java.lang.String arrayToString(byte[] pDat)
Returns a string representation of the array, for debugging purposes.
Parameters:
pDat - byte array.
Returns:
debug string.
See Also:
arrayToString(byte[], int, int)

arrayToString

public static java.lang.String arrayToString(byte[] pDat,
                                             int pIdx,
                                             int pLen)
Returns a string representation of the array, for debugging purposes.
Parameters:
pDat - byte array.
pIdx - index to where in the array to begin displaying from.
pLen - bytes to display.
Returns:
debug string.
See Also:
arrayToString(byte[])

arrayToStringIndex

public static java.lang.String arrayToStringIndex(byte[] pDat)
Returns a string representation of the array, for debugging purposes.
Parameters:
pDat - byte array.
Returns:
debug string.
See Also:
arrayToString(byte[], int, int)