Class: Resolv::DNS::Message::MessageDecoder

Class | Resolv::DNS::Message::MessageDecoder
In: | resolv.rb
Parent: | Object

### Methods

get_bytes get_label get_labels get_length16 get_name get_question get_rr get_string get_string_list get_unpack new

### Public Class methods

new(data) {|self| ...}

[Source]

    # File resolv.rb, line 1251
            def initialize(data)
              @data = data
              @index = 0
              @limit = data.length
              yield self
            end

### Public Instance methods

get_bytes(len = @limit - @index)

[Source]

    # File resolv.rb, line 1272
            def get_bytes(len = @limit - @index)
              d = @data[@index, len]
              @index += len
              return d
            end

get_label()

[Source]

    # File resolv.rb, line 1343
            def get_label
              return Label::Str.new(self.get_string)
            end

get_labels(limit=nil)

[Source]

    # File resolv.rb, line 1318
            def get_labels(limit=nil)
              limit = @index if !limit || @index < limit
              d = []
              while true
                case @data[@index]
                when 0
                  @index += 1
                  return d
                when 192..255
                  idx = self.get_unpack('n')[0] & 0x3fff
                  if limit <= idx
                    raise DecodeError.new("non-backward name pointer")
                  end
                  save_index = @index
                  @index = idx
                  d += self.get_labels(limit)
                  @index = save_index
                  return d
                else
                  d << self.get_label
                end
              end
              return d
            end

get_length16() {|len| ...}

[Source]

    # File resolv.rb, line 1258
            def get_length16
              len, = self.get_unpack('n')
              save_limit = @limit
              @limit = @index + len
              d = yield(len)
              if @index < @limit
                raise DecodeError.new("junk exists")
              elsif @limit < @index
                raise DecodeError.new("limit exceeded")
              end
              @limit = save_limit
              return d
            end

get_name()

[Source]

    # File resolv.rb, line 1314
            def get_name
              return Name.new(self.get_labels)
            end

get_question()

[Source]

    # File resolv.rb, line 1347
            def get_question
              name = self.get_name
              type, klass = self.get_unpack("nn")
              return name, Resource.get_class(type, klass)
            end

get_rr()

[Source]

    # File resolv.rb, line 1353
            def get_rr
              name = self.get_name
              type, klass, ttl = self.get_unpack('nnN')
              typeclass = Resource.get_class(type, klass)
              return name, ttl, self.get_length16 {typeclass.decode_rdata(self)}
            end

get_string()

[Source]

    # File resolv.rb, line 1298
            def get_string
              len = @data[@index]
              raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len
              d = @data[@index + 1, len]
              @index += 1 + len
              return d
            end

get_string_list()

[Source]

    # File resolv.rb, line 1306
            def get_string_list
              strings = []
              while @index < @limit
                strings << self.get_string
              end
              strings
            end

get_unpack(template)

[Source]

    # File resolv.rb, line 1278
            def get_unpack(template)
              len = 0
              template.each_byte {|byte|
                case byte
                when ?c, ?C
                  len += 1
                when ?n
                  len += 2
                when ?N
                  len += 4
                else
                  raise StandardError.new("unsupported template: '#{byte.chr}' in '#{template}'")
                end
              }
              raise DecodeError.new("limit exceeded") if @limit < @index + len
              arr = @data.unpack("@#{@index}#{template}")
              @index += len
              return arr
            end

[Validate]