com.antiaction.dns
Class DNSHeader

java.lang.Object
  |
  +--com.antiaction.dns.DNSHeader
All Implemented Interfaces:
java.lang.Cloneable

public class DNSHeader
extends java.lang.Object
implements java.lang.Cloneable

DNS header container, contains the header portion of a DNS message. As defined in rfc1035.

Version:
2.00
Author:
Nicholas Clarke

Field Summary
static int HEADER_SIZE
          Header size.
static int Query
          Query header type.
static int Response
          Response header type.
 
Constructor Summary
DNSHeader()
          Instantiate and initialize a default header object.
 
Method Summary
 byte[] buildPacket()
          Build and return the header based on the internal state.
 java.lang.Object clone()
          Overrides Cloneable.
 void disassemblePacket(byte[] pDat, int pIdx, int pLen)
          Parses the header part of a message and sets the internal state accordingly.
 int getAdditionalCount()
          Get Additional resource record count.
 int getAnswerCount()
          Get Answer resource record count.
 boolean getAuthoritativeAnswer()
          Get Authoritative Answer flag.
 int getAuthorityCount()
          Get Authority resource record count.
 int getDisassembledLen()
          Returns the length of the previously disassembled header.
 int getID()
          Get the message identification.
 int getOpcode()
          Get message opcode.
 int getQueryResponse()
          Get the type of message, Query or Response.
 int getQuestionCount()
          Get Question count.
 boolean getRecursionAvailable()
          Get Recursion Available flag.
 boolean getRecursionDesired()
          Get Recursion Desired flag.
 int getResponseCode()
          Get Response Code flag.
 boolean getTrunCation()
          Get Truncation flag.
 void setAdditionalCount(int c)
          Set Additional resource record count.
 void setAnswerCount(int c)
          Set Answer resource record count.
 void setAuthoritativeAnswer(boolean aa)
          Set Authoritative Answer flag.
 void setAuthorityCount(int c)
          Set Authority resource record count.
 void setDebug(boolean b)
          Toggle debug status.
 void setID(int id)
          Set the message identification.
 void setOpcode(int i)
          Set message opcode.
 void setQueryResponse(int qr)
          Set the header to either Query or Response.
 void setQuestionCount(int c)
          Set Question count.
 void setRecursionAvailable(boolean ra)
          Set Recursion Available flag.
 void setRecursionDesired(boolean rd)
          Set Recursion Desired flag.
 void setResponseCode(int rc)
          Set Response Code flag.
 void setTrunCation(boolean tc)
          Set Truncation flag.
 java.lang.String toString()
          Returns a string representation of the internal state, mostly for debugging purposes.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEADER_SIZE

public static final int HEADER_SIZE
Header size.

Query

public static final int Query
Query header type.

Response

public static final int Response
Response header type.
Constructor Detail

DNSHeader

public DNSHeader()
Instantiate and initialize a default header object.
Method Detail

clone

public java.lang.Object clone()
Overrides Cloneable.
Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

setDebug

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

buildPacket

public byte[] buildPacket()
Build and return the header based on the internal state.
Returns:
the header part of the message as a byte array.

getDisassembledLen

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

disassemblePacket

public void disassemblePacket(byte[] pDat,
                              int pIdx,
                              int pLen)
                       throws DNSException
Parses the header part of a message and sets the internal state accordingly.
Parameters:
pDat - array containing the complete message.
pIdx - index to where in the array the header begins.
pLen - length of the whole message.
Returns:
boolean indicating success or failure.
Throws:
DNSException - if the packet is corrupted.
See Also:
getDisassembledLen()

setID

public void setID(int id)
Set the message identification.
Parameters:
id - message identification.

getID

public int getID()
Get the message identification.
Returns:
message identification.

setQueryResponse

public void setQueryResponse(int qr)
Set the header to either Query or Response.
Parameters:
qr - Query or Response.

getQueryResponse

public int getQueryResponse()
Get the type of message, Query or Response.
Returns:
message type.

setOpcode

public void setOpcode(int i)
Set message opcode.
Parameters:
i - opcode.

getOpcode

public int getOpcode()
Get message opcode.
Returns:
message opcode.

setAuthoritativeAnswer

public void setAuthoritativeAnswer(boolean aa)
Set Authoritative Answer flag.
Parameters:
aa - boolean.

getAuthoritativeAnswer

public boolean getAuthoritativeAnswer()
Get Authoritative Answer flag.
Returns:
boolean.

setTrunCation

public void setTrunCation(boolean tc)
Set Truncation flag.
Parameters:
aa - boolean.

getTrunCation

public boolean getTrunCation()
Get Truncation flag.
Returns:
boolean.

setRecursionDesired

public void setRecursionDesired(boolean rd)
Set Recursion Desired flag.
Parameters:
aa - boolean.

getRecursionDesired

public boolean getRecursionDesired()
Get Recursion Desired flag.
Returns:
boolean.

setRecursionAvailable

public void setRecursionAvailable(boolean ra)
Set Recursion Available flag.
Parameters:
aa - boolean.

getRecursionAvailable

public boolean getRecursionAvailable()
Get Recursion Available flag.
Returns:
boolean.

setResponseCode

public void setResponseCode(int rc)
Set Response Code flag.
Parameters:
aa - boolean.

getResponseCode

public int getResponseCode()
Get Response Code flag.
Returns:
boolean.

setQuestionCount

public void setQuestionCount(int c)
Set Question count.
Parameters:
c - count.

getQuestionCount

public int getQuestionCount()
Get Question count.
Returns:
c count.

setAnswerCount

public void setAnswerCount(int c)
Set Answer resource record count.
Parameters:
c - count.

getAnswerCount

public int getAnswerCount()
Get Answer resource record count.
Returns:
count.

setAuthorityCount

public void setAuthorityCount(int c)
Set Authority resource record count.
Parameters:
c - count.

getAuthorityCount

public int getAuthorityCount()
Get Authority resource record count.
Returns:
count.

setAdditionalCount

public void setAdditionalCount(int c)
Set Additional resource record count.
Parameters:
c - count.

getAdditionalCount

public int getAdditionalCount()
Get Additional resource record count.
Returns:
count.

toString

public java.lang.String toString()
Returns a string representation of the internal state, mostly for debugging purposes.
Overrides:
toString in class java.lang.Object
Returns:
debug string.