In Files

  • resolv.rb

Resolv::DNS::Message::MessageDecoder

Public Class Methods

new(data) click to toggle source
 
               # File resolv.rb, line 1297
def initialize(data)
  @data = data
  @index = 0
  @limit = data.length
  yield self
end
            

Public Instance Methods

get_bytes(len = @limit - @index) click to toggle source
 
               # File resolv.rb, line 1318
def get_bytes(len = @limit - @index)
  d = @data[@index, len]
  @index += len
  return d
end
            
get_label() click to toggle source
 
               # File resolv.rb, line 1389
def get_label
  return Label::Str.new(self.get_string)
end
            
get_labels(limit=nil) click to toggle source
 
               # File resolv.rb, line 1364
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() click to toggle source
 
               # File resolv.rb, line 1304
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() click to toggle source
 
               # File resolv.rb, line 1360
def get_name
  return Name.new(self.get_labels)
end
            
get_question() click to toggle source
 
               # File resolv.rb, line 1393
def get_question
  name = self.get_name
  type, klass = self.get_unpack("nn")
  return name, Resource.get_class(type, klass)
end
            
get_rr() click to toggle source
 
               # File resolv.rb, line 1399
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() click to toggle source
 
               # File resolv.rb, line 1344
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() click to toggle source
 
               # File resolv.rb, line 1352
def get_string_list
  strings = []
  while @index < @limit
    strings << self.get_string
  end
  strings
end
            
get_unpack(template) click to toggle source
 
               # File resolv.rb, line 1324
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