Class DNSMessage


  • public class DNSMessage
    extends java.lang.Object
    A DNS message as defined by rfc1035. The message consists of a header and 4 sections: question, answer, nameserver and addition resource record section. A message can either be parsed (parse(byte[])) or serialized (toArray()).
    • Field Detail

      • id

        protected int id
        The DNS message id.
      • query

        protected boolean query
        True if this is a query.
      • authoritativeAnswer

        protected boolean authoritativeAnswer
        True if this is a authorative response.
      • truncated

        protected boolean truncated
        True on truncate, tcp should be used.
      • recursionDesired

        protected boolean recursionDesired
        True if the server should recurse.
      • recursionAvailable

        protected boolean recursionAvailable
        True if recursion is possible.
      • authenticData

        protected boolean authenticData
        True if the server regarded the response as authentic.
      • checkDisabled

        protected boolean checkDisabled
        True if the server should not check the replies.
      • questions

        protected Question[] questions
        The question section content.
      • answers

        protected Record[] answers
        The answers section content.
      • nameserverRecords

        protected Record[] nameserverRecords
        The nameserver records.
      • additionalResourceRecords

        protected Record[] additionalResourceRecords
        Additional resousrce records.
      • receiveTimestamp

        protected long receiveTimestamp
        The receive timestamp of this message.
    • Constructor Detail

      • DNSMessage

        public DNSMessage()
    • Method Detail

      • getId

        public int getId()
        Retrieve the current DNS message id.
        Returns:
        The current DNS message id.
      • setId

        public void setId​(int id)
        Set the current DNS message id.
        Parameters:
        id - The new DNS message id.
      • getReceiveTimestamp

        public long getReceiveTimestamp()
        Get the receive timestamp if this message was created via parse. This should be used to evaluate TTLs.
        Returns:
        The receive timestamp in milliseconds.
      • isQuery

        public boolean isQuery()
        Retrieve the query type (true or false;
        Returns:
        True if this DNS message is a query.
      • setQuery

        public void setQuery​(boolean query)
        Set the query status of this message.
        Parameters:
        query - The new query status.
      • isAuthoritativeAnswer

        public boolean isAuthoritativeAnswer()
        True if the DNS message is an authoritative answer.
        Returns:
        True if this an authoritative DNS message.
      • setAuthoritativeAnswer

        public void setAuthoritativeAnswer​(boolean authoritativeAnswer)
        Set the authoritative answer flag.
        Parameters:
        authoritativeAnswer - Tge new authoritative answer value.
      • isTruncated

        public boolean isTruncated()
        Retrieve the truncation status of this message. True means that the client should try a tcp lookup.
        Returns:
        True if this message was truncated.
      • setTruncated

        public void setTruncated​(boolean truncated)
        Set the truncation bit on this DNS message.
        Parameters:
        truncated - The new truncated bit status.
      • isRecursionDesired

        public boolean isRecursionDesired()
        Check if this message preferes recursion.
        Returns:
        True if recursion is desired.
      • setRecursionDesired

        public void setRecursionDesired​(boolean recursionDesired)
        Set the recursion desired flag on this message.
        Parameters:
        recursionDesired - The new recusrion setting.
      • isRecursionAvailable

        public boolean isRecursionAvailable()
        Retrieve the recursion available flag of this DNS message.
        Returns:
        The recursion available flag of this message.
      • setRecursionAvailable

        public void setRecursionAvailable​(boolean recursionAvailable)
        Set the recursion available flog from this DNS message.
        Parameters:
        recursionAvailable - The new recursion available status.
      • isAuthenticData

        public boolean isAuthenticData()
        Retrieve the authentic data flag of this message.
        Returns:
        The authentic data flag.
      • setAuthenticData

        public void setAuthenticData​(boolean authenticData)
        Set the authentic data flag on this DNS message.
        Parameters:
        authenticData - The new authentic data flag value.
      • isCheckDisabled

        public boolean isCheckDisabled()
        Check if checks are disabled.
        Returns:
        The status of the CheckDisabled flag.
      • setCheckDisabled

        public void setCheckDisabled​(boolean checkDisabled)
        Change the check status of this packet.
        Parameters:
        checkDisabled - The new check disabled value.
      • toArray

        public byte[] toArray()
                       throws java.io.IOException
        Generate a binary dns packet out of this message.
        Returns:
        byte[] the binary representation.
        Throws:
        java.io.IOException - Should never happen.
      • parse

        public static DNSMessage parse​(byte[] data)
                                throws java.io.IOException
        Build a DNS Message based on a binary DNS message.
        Parameters:
        data - The DNS message data.
        Returns:
        Parsed DNSMessage message.
        Throws:
        java.io.IOException - On read errors.
      • setQuestions

        public void setQuestions​(Question... questions)
        Set the question part of this message.
        Parameters:
        questions - The questions.
      • getOpcode

        public DNSMessage.OPCODE getOpcode()
        Retrieve the opcode of this message.
        Returns:
        The opcode of this message.
      • getResponseCode

        public DNSMessage.RESPONSE_CODE getResponseCode()
        Retrieve the response code of this message.
        Returns:
        The response code.
      • getQuestions

        public Question[] getQuestions()
        Retrieve the question section of this message.
        Returns:
        The DNS question section.
      • getAnswers

        public Record[] getAnswers()
        Retrieve the answer records of this DNS message.
        Returns:
        The answer section of this DNS message.
      • getNameserverRecords

        public Record[] getNameserverRecords()
        Retrieve the nameserver records of this DNS message.
        Returns:
        The nameserver section of this DNS message.
      • getAdditionalResourceRecords

        public Record[] getAdditionalResourceRecords()
        Retrieve the additional resource records attached to this DNS message.
        Returns:
        The additional resource record section of this DNS message.
      • toString

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