Package org.xbill.DNS

Class Record

java.lang.Object
org.xbill.DNS.Record
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Record>
Direct Known Subclasses:
A6Record, AAAARecord, AFSDBRecord, APLRecord, ARecord, CAARecord, CERTRecord, CNAMERecord, DHCIDRecord, DLVRecord, DNAMERecord, DNSKEYRecord, DSRecord, GPOSRecord, HINFORecord, HIPRecord, IPSECKEYRecord, ISDNRecord, KEYRecord, KXRecord, LOCRecord, MBRecord, MDRecord, MFRecord, MGRecord, MINFORecord, MRRecord, MXRecord, NAPTRRecord, NSAP_PTRRecord, NSAPRecord, NSEC3PARAMRecord, NSEC3Record, NSECRecord, NSRecord, NULLRecord, NXTRecord, OPENPGPKEYRecord, OPTRecord, PTRRecord, PXRecord, RPRecord, RRSIGRecord, RTRecord, SIGRecord, SOARecord, SPFRecord, SRVRecord, SSHFPRecord, SVCBBase, TKEYRecord, TLSARecord, TSIGRecord, TXTRecord, UNKRecord, URIRecord, WKSRecord, X25Record, ZoneMDRecord

public abstract class Record extends Object implements Cloneable, Comparable<Record>, Serializable
A generic DNS resource record. The specific record types extend this class. A record contains a name, type, class, ttl, and rdata.
Author:
Brian Wellington
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    protected Name
     
    protected long
     
    protected int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    Record(Name name, int type, int dclass, long ttl)
    Initialize the basic fields of a record.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static byte[]
    Converts a String into a byte array.
    protected static String
    byteArrayToString(byte[] array, boolean quote)
    Converts a byte array into a String.
    int
    Compares this Record to another Object.
    boolean
    Determines if two Records are identical.
    static Record
    fromString(Name name, int type, int dclass, long ttl, String s, Name origin)
    Builds a new Record from its textual representation
    static Record
    fromString(Name name, int type, int dclass, long ttl, Tokenizer st, Name origin)
    Builds a new Record from its textual representation
    static Record
    fromWire(byte[] b, int section)
    Builds a Record from DNS uncompressed wire format.
    Returns the name for which additional data processing should be done for this record.
    int
    Returns the record's class
    Returns the record's name
    int
    Returns the type of RRset that this record would belong to.
    long
    Returns the record's TTL
    int
    Returns the record's type
    int
    Generates a hash code based on the Record's data.
    static Record
    newRecord(Name name, int type, int dclass)
    Creates a new empty record, with the given parameters.
    static Record
    newRecord(Name name, int type, int dclass, long ttl)
    Creates a new empty record, with the given parameters.
    static Record
    newRecord(Name name, int type, int dclass, long ttl, byte[] data)
    Creates a new record, with the given parameters.
    static Record
    newRecord(Name name, int type, int dclass, long ttl, int length, byte[] data)
    Creates a new record, with the given parameters.
    protected abstract void
    Converts the text format of an RR to the internal format - must be overriden
    Converts the rdata portion of a Record into a String representation
    byte[]
    Converts the rdata in a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    protected abstract void
    Converts the type-specific RR to wire format - must be overridden
    protected abstract String
    Converts the type-specific RR to text format - must be overridden.
    protected abstract void
    rrToWire(DNSOutput out, Compression c, boolean canonical)
    Converts the type-specific RR to wire format - must be overridden.
    boolean
    Determines if two Records could be part of the same RRset.
    boolean
    Determines if this Record could be part of the passed RRset.
    Converts a Record into a String representation
    byte[]
    toWire(int section)
    Converts a Record into DNS uncompressed wire format.
    byte[]
    Converts a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    protected static String
    unknownToString(byte[] data)
    Converts a byte array into the unknown RR format.
    withName(Name name)
    Creates a new record identical to the current record, but with a different name.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      protected Name name
    • type

      protected int type
    • dclass

      protected int dclass
    • ttl

      protected long ttl
  • Constructor Details

    • Record

      protected Record()
    • Record

      protected Record(Name name, int type, int dclass, long ttl)
      Initialize the basic fields of a record.
      Since:
      3.1
  • Method Details

    • rrFromWire

      protected abstract void rrFromWire(DNSInput in) throws IOException
      Converts the type-specific RR to wire format - must be overridden
      Throws:
      IOException
      Since:
      3.1
    • newRecord

      public static Record newRecord(Name name, int type, int dclass, long ttl, int length, byte[] data)
      Creates a new record, with the given parameters.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      length - The length of the record's data.
      data - The rdata of the record, in uncompressed DNS wire format. Only the first length bytes are used.
    • newRecord

      public static Record newRecord(Name name, int type, int dclass, long ttl, byte[] data)
      Creates a new record, with the given parameters.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      data - The complete rdata of the record, in uncompressed DNS wire format.
    • newRecord

      public static Record newRecord(Name name, int type, int dclass, long ttl)
      Creates a new empty record, with the given parameters.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      Returns:
      An object of a subclass of Record
    • newRecord

      public static Record newRecord(Name name, int type, int dclass)
      Creates a new empty record, with the given parameters. This method is designed to create records that will be added to the QUERY section of a message.
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      Returns:
      An object of a subclass of Record
    • fromWire

      public static Record fromWire(byte[] b, int section) throws IOException
      Builds a Record from DNS uncompressed wire format.
      Throws:
      IOException
    • toWire

      public byte[] toWire(int section)
      Converts a Record into DNS uncompressed wire format.
    • toWireCanonical

      public byte[] toWireCanonical()
      Converts a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    • rdataToWireCanonical

      public byte[] rdataToWireCanonical()
      Converts the rdata in a Record into canonical DNS uncompressed wire format (all names are converted to lowercase).
    • rrToString

      protected abstract String rrToString()
      Converts the type-specific RR to text format - must be overridden.
      Since:
      3.1
    • rdataToString

      public String rdataToString()
      Converts the rdata portion of a Record into a String representation
    • toString

      public String toString()
      Converts a Record into a String representation
      Overrides:
      toString in class Object
    • rdataFromString

      protected abstract void rdataFromString(Tokenizer st, Name origin) throws IOException
      Converts the text format of an RR to the internal format - must be overriden
      Throws:
      IOException
      Since:
      3.1
    • byteArrayFromString

      protected static byte[] byteArrayFromString(String s) throws TextParseException
      Converts a String into a byte array.
      Throws:
      TextParseException
    • byteArrayToString

      protected static String byteArrayToString(byte[] array, boolean quote)
      Converts a byte array into a String.
    • unknownToString

      protected static String unknownToString(byte[] data)
      Converts a byte array into the unknown RR format.
    • fromString

      public static Record fromString(Name name, int type, int dclass, long ttl, Tokenizer st, Name origin) throws IOException
      Builds a new Record from its textual representation
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      st - A tokenizer containing the textual representation of the rdata.
      origin - The default origin to be appended to relative domain names.
      Returns:
      The new record
      Throws:
      IOException - The text format was invalid.
    • fromString

      public static Record fromString(Name name, int type, int dclass, long ttl, String s, Name origin) throws IOException
      Builds a new Record from its textual representation
      Parameters:
      name - The owner name of the record.
      type - The record's type.
      dclass - The record's class.
      ttl - The record's time to live.
      s - The textual representation of the rdata.
      origin - The default origin to be appended to relative domain names.
      Returns:
      The new record
      Throws:
      IOException - The text format was invalid.
    • getName

      public Name getName()
      Returns the record's name
      See Also:
    • getType

      public int getType()
      Returns the record's type
      See Also:
    • getRRsetType

      public int getRRsetType()
      Returns the type of RRset that this record would belong to. For all types except SIG/RRSIG, this is equivalent to getType().
      Returns:
      The type of record
      See Also:
    • getDClass

      public int getDClass()
      Returns the record's class
    • getTTL

      public long getTTL()
      Returns the record's TTL
    • rrToWire

      protected abstract void rrToWire(DNSOutput out, Compression c, boolean canonical)
      Converts the type-specific RR to wire format - must be overridden.
      Since:
      3.1
    • sameRRset

      public boolean sameRRset(Record rec)
      Determines if two Records could be part of the same RRset. This compares the name, type, and class of the Records; the ttl and rdata are not compared.
    • sameRRset

      public boolean sameRRset(RRset set)
      Determines if this Record could be part of the passed RRset. This compares the name, type, and class of the Record and the set.
      Since:
      3.6
    • equals

      public boolean equals(Object arg)
      Determines if two Records are identical. This compares the name, type, class, and rdata (with names canonicalized). The TTLs are not compared.
      Overrides:
      equals in class Object
      Parameters:
      arg - The record to compare to
      Returns:
      true if the records are equal, false otherwise.
    • hashCode

      public int hashCode()
      Generates a hash code based on the Record's data.
      Overrides:
      hashCode in class Object
    • withName

      public Record withName(Name name)
      Creates a new record identical to the current record, but with a different name. This is most useful for replacing the name of a wildcard record.
    • compareTo

      public int compareTo(Record arg)
      Compares this Record to another Object.
      Specified by:
      compareTo in interface Comparable<Record>
      Parameters:
      arg - The Object to be compared.
      Returns:
      The value 0 if the argument is a record equivalent to this record; a value less than 0 if the argument is less than this record in the canonical ordering, and a value greater than 0 if the argument is greater than this record in the canonical ordering. The canonical ordering is defined to compare by name, class, type, and rdata.
      Throws:
      ClassCastException - if the argument is not a Record.
    • getAdditionalName

      public Name getAdditionalName()
      Returns the name for which additional data processing should be done for this record. This can be used both for building responses and parsing responses.
      Returns:
      The name to used for additional data processing, or null if this record type does not require additional data processing.