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

### Methods

== add_additional add_answer add_authority add_question decode each_additional each_answer each_authority each_question each_resource encode new

### Classes and Modules

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

### Attributes

aa | [RW] |
additional | [R] |
answer | [R] |
authority | [R] |
id | [RW] |
opcode | [RW] |
qr | [RW] |
question | [R] |
ra | [RW] |
rcode | [RW] |
rd | [RW] |
tc | [RW] |

### Public Class methods

decode(m)

[Source]

    # File resolv.rb, line 1217
          def Message.decode(m)
            o = Message.new(0)
            MessageDecoder.new(m) {|msg|
              id, flag, qdcount, ancount, nscount, arcount =
                msg.get_unpack('nnnnnn')
              o.id = id
              o.qr = (flag >> 15) & 1
              o.opcode = (flag >> 11) & 15
              o.aa = (flag >> 10) & 1
              o.tc = (flag >> 9) & 1
              o.rd = (flag >> 8) & 1
              o.ra = (flag >> 7) & 1
              o.rcode = flag & 15
              (1..qdcount).each {
                name, typeclass = msg.get_question
                o.add_question(name, typeclass)
              }
              (1..ancount).each {
                name, ttl, data = msg.get_rr
                o.add_answer(name, ttl, data)
              }
              (1..nscount).each {
                name, ttl, data = msg.get_rr
                o.add_authority(name, ttl, data)
              }
              (1..arcount).each {
                name, ttl, data = msg.get_rr
                o.add_additional(name, ttl, data)
              }
            }
            return o
          end

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

[Source]

    # File resolv.rb, line 1045
          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

### Public Instance methods

==(other)

[Source]

    # File resolv.rb, line 1063
          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)

[Source]

    # File resolv.rb, line 1108
          def add_additional(name, ttl, data)
            @additional << [Name.create(name), ttl, data]
          end

add_answer(name, ttl, data)

[Source]

    # File resolv.rb, line 1088
          def add_answer(name, ttl, data)
            @answer << [Name.create(name), ttl, data]
          end

add_authority(name, ttl, data)

[Source]

    # File resolv.rb, line 1098
          def add_authority(name, ttl, data)
            @authority << [Name.create(name), ttl, data]
          end

add_question(name, typeclass)

[Source]

    # File resolv.rb, line 1078
          def add_question(name, typeclass)
            @question << [Name.create(name), typeclass]
          end

each_additional() {|name, ttl, data| ...}

[Source]

    # File resolv.rb, line 1112
          def each_additional
            @additional.each {|name, ttl, data|
              yield name, ttl, data
            }
          end

each_answer() {|name, ttl, data| ...}

[Source]

    # File resolv.rb, line 1092
          def each_answer
            @answer.each {|name, ttl, data|
              yield name, ttl, data
            }
          end

each_authority() {|name, ttl, data| ...}

[Source]

    # File resolv.rb, line 1102
          def each_authority
            @authority.each {|name, ttl, data|
              yield name, ttl, data
            }
          end

each_question() {|name, typeclass| ...}

[Source]

    # File resolv.rb, line 1082
          def each_question
            @question.each {|name, typeclass|
              yield name, typeclass
            }
          end

each_resource() {|name, ttl, data| ...}

[Source]

    # File resolv.rb, line 1118
          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()

[Source]

    # File resolv.rb, line 1124
          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

[Validate]