Class: Nesser::AAAA

Inherits:
Object
  • Object
show all
Defined in:
lib/nesser/packets/rr_types.rb

Overview

IPv6 record, eg, “::1”.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address:) ⇒ AAAA

Returns a new instance of AAAA.



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/nesser/packets/rr_types.rb', line 289

def initialize(address:)
  if !address.is_a?(String)
    raise(DnsException, "String required!")
  end

  begin
    @address = IPAddr.new(address)
  rescue IPAddr::InvalidAddressError => e
    raise(DnsException, "Invalid address: %s" % e)
  end

  if !@address.ipv6?()
    raise(DnsException, "IPv6 address required!")
  end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



287
288
289
# File 'lib/nesser/packets/rr_types.rb', line 287

def address
  @address
end

Class Method Details

.unpack(unpacker) ⇒ Object



305
306
307
308
309
310
311
312
313
# File 'lib/nesser/packets/rr_types.rb', line 305

def self.unpack(unpacker)
  length = unpacker.unpack_one('n')
  if length != 16
    raise(DnsException, "Invalid AAAA record")
  end

  data = unpacker.unpack('a16').join()
  return self.new(address: IPAddr.ntop(data))
end

Instance Method Details

#pack(packer) ⇒ Object



315
316
317
318
319
# File 'lib/nesser/packets/rr_types.rb', line 315

def pack(packer)
  packer.pack('n', 16)

  packer.pack('C16', *@address.hton().bytes())
end

#to_sObject



322
323
324
# File 'lib/nesser/packets/rr_types.rb', line 322

def to_s()
  return "#{@address} [AAAA]"
end