123456789_123456789_123456789_123456789_123456789_

Class: Resolv::DNS::Message

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(id = (@@identifier += 1) & 0xffff) ⇒ Message

[ GitHub ]

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

def initialize(id = (@@identifier += 1) & 0xffff)
  @id = id
  @qr = 0
  @opcode = 0
  @aa = 0
  @tc = 0
  @rd = 0 # recursion desired
  @ra = 0 # recursion available
  @rcode = 0
  @question = []
  @answer = []
  @authority = []
  @additional = []
end

Instance Attribute Details

#aa (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

#additional (readonly)

[ GitHub ]

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

attr_reader :question, :answer, :authority, :additional

#answer (readonly)

[ GitHub ]

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

attr_reader :question, :answer, :authority, :additional

#authority (readonly)

[ GitHub ]

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

attr_reader :question, :answer, :authority, :additional

#id (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

#opcode (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

#qr (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

#question (readonly)

[ GitHub ]

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

attr_reader :question, :answer, :authority, :additional

#ra (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

#rcode (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

#rd (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

#tc (rw)

[ GitHub ]

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

attr_accessor :id, :qr, :opcode, :aa, :tc, :rd, :ra, :rcode

Instance Method Details

#==(other)

[ GitHub ]

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

def ==(other)
  return @id == other.id &&
         @qr == other.qr &&
         @opcode == other.opcode &&
         @aa == other.aa &&
         @tc == other.tc &&
         @rd == other.rd &&
         @ra == other.ra &&
         @rcode == other.rcode &&
         @question == other.question &&
         @answer == other.answer &&
         @authority == other.authority &&
         @additional == other.additional
end

#add_additional(name, ttl, data)

[ GitHub ]

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

def add_additional(name, ttl, data)
  @additional << [Name.create(name), ttl, data]
end

#add_answer(name, ttl, data)

[ GitHub ]

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

def add_answer(name, ttl, data)
  @answer << [Name.create(name), ttl, data]
end

#add_authority(name, ttl, data)

[ GitHub ]

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

def add_authority(name, ttl, data)
  @authority << [Name.create(name), ttl, data]
end

#add_question(name, typeclass)

[ GitHub ]

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

def add_question(name, typeclass)
  @question << [Name.create(name), typeclass]
end

#each_additional

[ GitHub ]

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

def each_additional
  @additional.each {|name, ttl, data|
    yield name, ttl, data
  }
end

#each_answer

[ GitHub ]

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

def each_answer
  @answer.each {|name, ttl, data|
    yield name, ttl, data
  }
end

#each_authority

[ GitHub ]

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

def each_authority
  @authority.each {|name, ttl, data|
    yield name, ttl, data
  }
end

#each_question

[ GitHub ]

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

def each_question
  @question.each {|name, typeclass|
    yield name, typeclass
  }
end

#each_resource

[ GitHub ]

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

def each_resource
  each_answer {|name, ttl, data| yield name, ttl, data}
  each_authority {|name, ttl, data| yield name, ttl, data}
  each_additional {|name, ttl, data| yield name, ttl, data}
end

#encode

[ GitHub ]

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

def encode
  return MessageEncoder.new {|msg|
    msg.put_pack('nnnnnn',
      @id,
      (@qr & 1) << 15 |
      (@opcode & 15) << 11 |
      (@aa & 1) << 10 |
      (@tc & 1) << 9 |
      (@rd & 1) << 8 |
      (@ra & 1) << 7 |
      (@rcode & 15),
      @question.length,
      @answer.length,
      @authority.length,
      @additional.length)
    @question.each {|q|
      name, typeclass = q
      msg.put_name(name)
      msg.put_pack('nn', typeclass::TypeValue, typeclass::ClassValue)
    }
    [@answer, @authority, @additional].each {|rr|
      rr.each {|r|
        name, ttl, data = r
        msg.put_name(name)
        msg.put_pack('nnN', data.class::TypeValue, data.class::ClassValue, ttl)
        msg.put_length16 {data.encode_rdata(msg)}
      }
    }
  }.to_s
end