123456789_123456789_123456789_123456789_123456789_

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

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/resolv.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(data) {|_self| ... } ⇒ MessageDecoder

Yields:

  • (_self)

Yield Parameters:

  • _self (MessageDecoder)

    the object that the method was called on

[ GitHub ]

  
# File 'lib/resolv.rb', line 1556

def initialize(data)
  @data = data
  @index = 0
  @limit = data.bytesize
  yield self
end

Instance Method Details

#get_bytes(len = @limit - @index)

Raises:

[ GitHub ]

  
# File 'lib/resolv.rb', line 1581

def get_bytes(len = @limit - @index)
  raise DecodeError.new("limit exceeded") if @limit < @index + len
  d = @data.byteslice(@index, len)
  @index += len
  return d
end

#get_label

[ GitHub ]

  
# File 'lib/resolv.rb', line 1659

def get_label
  return Label::Str.new(self.get_string)
end

#get_labels

[ GitHub ]

  
# File 'lib/resolv.rb', line 1630

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

#get_length16

[ GitHub ]

  
# File 'lib/resolv.rb', line 1567

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

[ GitHub ]

  
# File 'lib/resolv.rb', line 1626

def get_name
  return Name.new(self.get_labels)
end

#get_question

[ GitHub ]

  
# File 'lib/resolv.rb', line 1663

def get_question
  name = self.get_name
  type, klass = self.get_unpack("nn")
  return name, Resource.get_class(type, klass)
end

#get_rr

[ GitHub ]

  
# File 'lib/resolv.rb', line 1669

def get_rr
  name = self.get_name
  type, klass, ttl = self.get_unpack('nnN')
  typeclass = Resource.get_class(type, klass)
  res = self.get_length16 do
    begin
      typeclass.decode_rdata self
    rescue => e
      raise DecodeError, e.message, e.backtrace
    end
  end
  res.instance_variable_set :@ttl, ttl
  return name, ttl, res
end

#get_string

Raises:

[ GitHub ]

  
# File 'lib/resolv.rb', line 1609

def get_string
  raise DecodeError.new("limit exceeded") if @limit <= @index
  len = @data.getbyte(@index)
  raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len
  d = @data.byteslice(@index + 1, len)
  @index += 1 + len
  return d
end

#get_string_list

[ GitHub ]

  
# File 'lib/resolv.rb', line 1618

def get_string_list
  strings = []
  while @index < @limit
    strings << self.get_string
  end
  strings
end

#get_unpack(template)

Raises:

[ GitHub ]

  
# File 'lib/resolv.rb', line 1588

def get_unpack(template)
  len = 0
  template.each_byte {|byte|
    byte = "%c" % 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

#inspect

[ GitHub ]

  
# File 'lib/resolv.rb', line 1563

def inspect
  "\#<#{self.class}: #{@data.byteslice(0, @index).inspect} #{@data.byteslice(@index..-1).inspect}>"
end