Record Class DnsMessage.ResourceRecord

java.lang.Object
java.lang.Record
org.microproxy.dns.DnsMessage.ResourceRecord
Record Components:
name - the owner name, in presentation format
type - the type (DnsMessage.A, ...)
dnsClass - the class (DnsMessage.IN; an OPT record's holds the UDP payload size)
ttl - the time to live in seconds, an unsigned 32-bit value (an OPT record's holds the extended RCODE and flags)
rdata - the RDATA (not copied)
Enclosing class:
DnsMessage

public static record DnsMessage.ResourceRecord(String name, int type, int dnsClass, long ttl, byte[] rdata) extends Record
A resource record. rdata holds its RDATA with embedded names expanded; data() reads it as a typed value.
  • Constructor Details

    • ResourceRecord

      public ResourceRecord(String name, int type, int dnsClass, long ttl, byte[] rdata)
      Checks the name and the RDATA's length.
      Parameters:
      name - the owner name, in presentation format
      type - the type
      dnsClass - the class
      ttl - the time to live in seconds
      rdata - the RDATA
      Throws:
      IllegalArgumentException - if the name is not a valid domain name, or the RDATA is longer than 65535 bytes
  • Method Details

    • of

      public static DnsMessage.ResourceRecord of(String name, int type, long ttl, DnsMessage.Rdata data)
      A record of class IN with typed data.
      Parameters:
      name - the owner name
      type - the type, which must suit data (DnsMessage.Address for A and AAAA, DnsMessage.Name for NS, CNAME, PTR and DNAME, ...)
      ttl - the time to live in seconds
      data - the data
      Returns:
      the record
      Throws:
      IllegalArgumentException - if data does not suit type
    • data

      public DnsMessage.Rdata data()
      The RDATA read as its type's DnsMessage.Rdata: an DnsMessage.Address for A and AAAA, a DnsMessage.Name for NS, CNAME, PTR and DNAME, DnsMessage.Mx, DnsMessage.Srv, DnsMessage.Txt and DnsMessage.Soa; DnsMessage.Opaque for other types, and for RDATA that does not parse.
      Returns:
      the data
    • typeName

      public String typeName()
      Returns the type's mnemonic, such as A, or TYPE<n>.
      Returns:
      the type's mnemonic, such as A, or TYPE<n>
    • withData

      This record with other data, encoded for its type.
      Parameters:
      data - the data
      Returns:
      the copy
      Throws:
      IllegalArgumentException - if data does not suit the type
    • withTtl

      public DnsMessage.ResourceRecord withTtl(long ttl)
      This record with another time to live.
      Parameters:
      ttl - the time to live in seconds
      Returns:
      the copy
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • type

      public int type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • dnsClass

      public int dnsClass()
      Returns the value of the dnsClass record component.
      Returns:
      the value of the dnsClass record component
    • ttl

      public long ttl()
      Returns the value of the ttl record component.
      Returns:
      the value of the ttl record component
    • rdata

      public byte[] rdata()
      Returns the value of the rdata record component.
      Returns:
      the value of the rdata record component