Class: Dnsruby::Prefixes

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsruby/resource/APL.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefixes) ⇒ Prefixes

Returns a new instance of Prefixes.



93
94
95
# File 'lib/dnsruby/resource/APL.rb', line 93

def initialize(prefixes)
  @prefixes = prefixes
end

Instance Attribute Details

#prefixesObject

Returns the value of attribute prefixes.



54
55
56
# File 'lib/dnsruby/resource/APL.rb', line 54

def prefixes
  @prefixes
end

Class Method Details

.create(arg) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dnsruby/resource/APL.rb', line 56

def create(arg)
  case arg
  when Prefixes
    return arg
  when String
    prefixes = arg.split(/\s/).map { |prefix| Prefix.create(prefix) }
  when Array
    prefixes = arg.map { |prefix| Prefix.create(prefix) }
  else
    raise ArgumentError.new("APL format erro #{arg}")
  end
  Prefixes.new(prefixes)
end

.create_from_message(msg) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dnsruby/resource/APL.rb', line 69

def create_from_message(msg)
  prefixes = []
  while(msg.has_remaining?) do
    negative = nil
    af,prefix_length,flag = msg.get_unpack('nCC')
    negative = '!' if 0x80 & flag == 0x80
    address_length = flag & 0x7f

    case(af)
    when 1
      addr = msg.get_bytes(address_length) + "\0" * (4 - address_length)
      address = IPv4.new(addr)
    when 2
      addr = msg.get_bytes(address_length) + "\0" * (16 - address_length)
      address = IPv6.new(addr)
    else
      raise ArgumentError.new("APL format error")
    end
    prefixes.push(Prefix.new(af, prefix_length, negative, address_length, address))
  end

  Prefixes.new(prefixes)
end

Instance Method Details

#encode_rdata(msg, _canonical = false) ⇒ Object

:nodoc: all



101
102
103
104
105
# File 'lib/dnsruby/resource/APL.rb', line 101

def encode_rdata(msg, _canonical = false) #:nodoc: all
  @prefixes.each do |prefix|
    prefix.put_msg(msg)
  end
end

#to_sObject



97
98
99
# File 'lib/dnsruby/resource/APL.rb', line 97

def to_s
  @prefixes.map(&:to_s).join(' ')
end