org.xbill.DNS
Class Message

java.lang.Object
  |
  +--org.xbill.DNS.Message

public class Message
extends Object
implements Cloneable

A DNS Message. A message is the basic unit of communication between the client and server of a DNS operation. A message consists of a Header and 4 message sections.

See Also:
Resolver, Header, Section

Constructor Summary
Message()
          Creates a new Message with a random Message ID
Message(byte[] b)
          Creates a new Message from its DNS wire format representation
Message(int id)
          Creates a new Message with the specified Message ID
 
Method Summary
 void addRecord(Record r, int section)
          Adds a record to a section of the Message, and adjusts the header
 Object clone()
          Creates a copy of this Message.
 boolean findRecord(Record r)
          Determines if the given record is already present in any section
 boolean findRecord(Record r, int section)
          Determines if the given record is already present in the given section
 Header getHeader()
          Retrieves the Header
 OPTRecord getOPT()
          Returns the OPT record from the ADDITIONAL section, if one is present
 Record getQuestion()
          Returns the first record in the QUESTION section
 short getRcode()
          Returns the message's rcode (error code).
 Enumeration getSection(int section)
          Returns an Enumeration listing all records in the given section
 Record[] getSectionArray(int section)
          Returns an array containing all records in the given section
 TSIGRecord getTSIG()
          Returns the TSIG record from the ADDITIONAL section, if one is present
 boolean isSigned()
          Was this message signed by a TSIG?
 boolean isVerified()
          If this message was signed by a TSIG, was the TSIG verified?
static Message newQuery(Record r)
          Creates a new Message with a random Message ID suitable for sending as a query.
static Message newUpdate(Name zone)
          Creates a new Message to contain a dynamic update.
 int numBytes()
          Returns the size of the message.
 void removeAllRecords(int section)
          Removes all records from a section of the Message, and adjusts the header
 boolean removeRecord(Record r, int section)
          Removes a record from a section of the Message, and adjusts the header
 String sectionToString(int i)
          Converts the given section of the Message to a String
 void setHeader(Header h)
          Replaces the Header with a new one
 String toString()
          Converts the Message to a String
 byte[] toWire()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Message

public Message(int id)
Creates a new Message with the specified Message ID

Message

public Message()
Creates a new Message with a random Message ID

Message

public Message(byte[] b)
        throws IOException
Creates a new Message from its DNS wire format representation
Method Detail

newQuery

public static Message newQuery(Record r)
Creates a new Message with a random Message ID suitable for sending as a query.
Parameters:
r - A record containing the question

newUpdate

public static Message newUpdate(Name zone)
Creates a new Message to contain a dynamic update. A random Message ID the zone are filled in.
Parameters:
zone - The zone to be updated

setHeader

public void setHeader(Header h)
Replaces the Header with a new one
See Also:
Header

getHeader

public Header getHeader()
Retrieves the Header
See Also:
Header

addRecord

public void addRecord(Record r,
                      int section)
Adds a record to a section of the Message, and adjusts the header
See Also:
Record, Section

removeRecord

public boolean removeRecord(Record r,
                            int section)
Removes a record from a section of the Message, and adjusts the header
See Also:
Record, Section

removeAllRecords

public void removeAllRecords(int section)
Removes all records from a section of the Message, and adjusts the header
See Also:
Record, Section

findRecord

public boolean findRecord(Record r,
                          int section)
Determines if the given record is already present in the given section
See Also:
Record, Section

findRecord

public boolean findRecord(Record r)
Determines if the given record is already present in any section
See Also:
Record, Section

getQuestion

public Record getQuestion()
Returns the first record in the QUESTION section
See Also:
Record, Section

getTSIG

public TSIGRecord getTSIG()
Returns the TSIG record from the ADDITIONAL section, if one is present
See Also:
TSIGRecord, TSIG, Section

isSigned

public boolean isSigned()
Was this message signed by a TSIG?
See Also:
TSIG

isVerified

public boolean isVerified()
If this message was signed by a TSIG, was the TSIG verified?
See Also:
TSIG

getOPT

public OPTRecord getOPT()
Returns the OPT record from the ADDITIONAL section, if one is present
See Also:
OPTRecord, Section

getRcode

public short getRcode()
Returns the message's rcode (error code). This incorporates the EDNS extended rcode.

getSection

public Enumeration getSection(int section)
Returns an Enumeration listing all records in the given section
See Also:
Record, Section

getSectionArray

public Record[] getSectionArray(int section)
Returns an array containing all records in the given section
See Also:
Record, Section

toWire

public byte[] toWire()
              throws IOException

numBytes

public int numBytes()
Returns the size of the message. Only valid if the message has been converted to or from wire format.

sectionToString

public String sectionToString(int i)
Converts the given section of the Message to a String
See Also:
Section

toString

public String toString()
Converts the Message to a String
Overrides:
toString in class Object

clone

public Object clone()
Creates a copy of this Message. This is done by the Resolver before adding TSIG and OPT records, for example.
Overrides:
clone in class Object
See Also:
Resolver, TSIGRecord, OPTRecord