Method: Net::DNS::Header#initialize

Defined in:
lib/net/dns/header.rb

#initialize(arg = {}) ⇒ Header

Creates a new Net::DNS::Header object with the desired values, which can be specified as an Hash argument. When called without arguments, defaults are used. If a data string is passed, values are taken from parsing the string.

Examples:

# Create a new Net::DNS::Header object
header = Net::DNS::Header.new

# Create a new Net::DNS::Header object passing values
header = Net::DNS::Header.new(:opCode => 1, :rd => 0)

# Create a new Net::DNS::Header object with binary data
header = Net::DNS::Header.new(data)

Default values are:

:id => auto generated
:qr      => 0 # Query response flag
:aa      => 0 # Authoritative answer flag
:tc      => 0 # Truncated packet flag
:ra      => 0 # Recursiond available flag
:rCode   => 0 # Response code (status of the query)
:opCode  => 0 # Operational code (purpose of the query)
:cd      => 0 # Checking disable flag
:ad      => 0 # Only relevant in DNSSEC context
:rd      => 1 # Recursion desired flag
:qdCount => 1 # Number of questions in the dns packet
:anCount => 0 # Number of answer RRs in the dns packet
:nsCount => 0 # Number of authoritative RRs in the dns packet
:arCount => 0 # Number of additional RRs in the dns packet

See also each option for a detailed explanation of usage.



214
215
216
217
218
219
220
# File 'lib/net/dns/header.rb', line 214

def initialize(arg = {})
  if arg.kind_of? Hash
    new_from_hash(arg)
  else
    raise ArgumentError, "Wrong argument class `#{arg.class}'"
  end
end