Class: Dnsruby::Header

### Home Classes Methods

### In Files

- lib/Dnsruby/message.rb

### Parent

Object

### Methods

- ::decrement_arcount_encoded
- ::new
- ::new_from_data
- #==
- #data
- #decode
- #encode
- #get_header_rcode
- #opcode=
- #rcode=
- #to_s
- #to_s_with_rcode

### Files

- DNSSEC
- EVENTMACHINE
- EXAMPLES
- README

### Class/Module Index

Quicksearch

- Dnsruby
- Dnsruby::Algorithms
- Dnsruby::Classes
- Dnsruby::CodeMapper
- Dnsruby::Config
- Dnsruby::DNS
- Dnsruby::DecodeError
- Dnsruby::Dnssec
- Dnsruby::Dnssec::ValidationPolicy
- Dnsruby::EncodeError
- Dnsruby::ExtendedRCode
- Dnsruby::FormErr
- Dnsruby::Header
- Dnsruby::Hosts
- Dnsruby::IPv4
- Dnsruby::IPv6
- Dnsruby::Message
- Dnsruby::Message::Section
- Dnsruby::Message::SecurityLevel
- Dnsruby::MetaTypes
- Dnsruby::Modes
- Dnsruby::NXDomain
- Dnsruby::NXRRSet
- Dnsruby::Name
- Dnsruby::Name::Label
- Dnsruby::NotAuth
- Dnsruby::NotImp
- Dnsruby::NotZone
- Dnsruby::Nsec3HashAlgorithms
- Dnsruby::OpCode
- Dnsruby::OtherResolvError
- Dnsruby::QTypes
- Dnsruby::Question
- Dnsruby::RCode
- Dnsruby::RR
- Dnsruby::RR::ANY
- Dnsruby::RR::CERT
- Dnsruby::RR::CERT::CertificateTypes
- Dnsruby::RR::CNAME
- Dnsruby::RR::DHCID
- Dnsruby::RR::DLV
- Dnsruby::RR::DNAME
- Dnsruby::RR::DNSKEY
- Dnsruby::RR::DS
- Dnsruby::RR::DS::DigestTypes
- Dnsruby::RR::DomainName
- Dnsruby::RR::Generic
- Dnsruby::RR::HINFO
- Dnsruby::RR::HIP
- Dnsruby::RR::IN
- Dnsruby::RR::IN::A
- Dnsruby::RR::IN::AAAA
- Dnsruby::RR::IN::AFSDB
- Dnsruby::RR::IN::PX
- Dnsruby::RR::IN::SRV
- Dnsruby::RR::IN::WKS
- Dnsruby::RR::IPSECKEY
- Dnsruby::RR::ISDN
- Dnsruby::RR::KX
- Dnsruby::RR::LOC
- Dnsruby::RR::MB
- Dnsruby::RR::MG
- Dnsruby::RR::MINFO
- Dnsruby::RR::MR
- Dnsruby::RR::MX
- Dnsruby::RR::NAPTR
- Dnsruby::RR::NS
- Dnsruby::RR::NSAP
- Dnsruby::RR::NSEC
- Dnsruby::RR::NSEC3
- Dnsruby::RR::NSEC3PARAM
- Dnsruby::RR::OPT
- Dnsruby::RR::PTR
- Dnsruby::RR::RP
- Dnsruby::RR::RRSIG
- Dnsruby::RR::RT
- Dnsruby::RR::SOA
- Dnsruby::RR::SPF
- Dnsruby::RR::SSHFP
- Dnsruby::RR::SSHFP::Algorithms
- Dnsruby::RR::SSHFP::FpTypes
- Dnsruby::RR::TKEY
- Dnsruby::RR::TSIG
- Dnsruby::RR::TXT
- Dnsruby::RR::X25
- Dnsruby::RRSet
- Dnsruby::Recursor
- Dnsruby::Refused
- Dnsruby::Resolv
- Dnsruby::ResolvError
- Dnsruby::ResolvTimeout
- Dnsruby::Resolver
- Dnsruby::Resolver::EventType
- Dnsruby::SelectThread
- Dnsruby::ServFail
- Dnsruby::SingleResolver
- Dnsruby::TheLog
- Dnsruby::TsigError
- Dnsruby::TsigNotSignedResponseError
- Dnsruby::Types
- Dnsruby::Update
- Dnsruby::VerifyError
- Dnsruby::YXDomain
- Dnsruby::YXRRSet
- Dnsruby::ZoneReader
- Dnsruby::ZoneReader::ParseException
- Dnsruby::ZoneSerialError
- Dnsruby::ZoneTransfer
- Dnsruby::ZoneTransfer::Delta
- Base32

No matching classes.

# Dnsruby::Header

The header portion of a DNS packet

RFC 1035 Section 4.1.1

### Constants

MAX_ID

### Attributes

aa[RW]

Authoritative answer flag

ad[RW]

The Authenticated Data flag Relevant in DNSSEC context. (The AD bit is only set on answers where signatures have been cryptographically verified or the server is authoritative for the data and is allowed to set the bit by policy.)

adcount[RW]

The number of records in the additional record section og the message

adcount=[RW]

The number of records in the additional record section og the message

ancount[RW]

The number of records in the answer section of the message

arcount[RW]

The number of records in the additional record section og the message

cd[RW]

The Checking Disabled flag

id[RW]

The header ID

nscount[RW]

The number of records in the authoriy section of the message

opcode[R]

The header opcode

prcount[RW]

The number of records in the answer section of the message

prcount=[RW]

The number of records in the answer section of the message

qdcount[RW]

The number of records in the question section of the message

qr[RW]

The query response flag

ra[RW]

Recursion available flag

rd[RW]

Recursion Desired flag

tc[RW]

Truncated flag

upcount[RW]

The number of records in the authoriy section of the message

upcount=[RW]

The number of records in the authoriy section of the message

zocount[RW]

The number of records in the question section of the message

zocount=[RW]

The number of records in the question section of the message

### Public Class Methods

decrement_arcount_encoded(bytes) click to toggle source

    # File lib/Dnsruby/message.rb, line 783
    def Header.decrement_arcount_encoded(bytes)
      header = Header.new
      header_end = 0
      MessageDecoder.new(bytes) {|msg|
        header.decode(msg)
        header_end = msg.index
      }
      header.arcount = header.arcount - 1
      bytes[0,header_end]=MessageEncoder.new {|msg|
        header.encode(msg)}.to_s
      return bytes
    end

new(*args) click to toggle source

    # File lib/Dnsruby/message.rb, line 723
    def initialize(*args)
      if (args.length == 0)
        @id = rand(MAX_ID)
        @qr = false
        @opcode=OpCode.Query
        @aa = false
        @ad=false
        @tc = false
        @rd = false # recursion desired
        @ra = false # recursion available
        @cd=false
        @rcode=RCode.NoError
        @qdcount = 0
        @nscount = 0
        @ancount = 0
        @arcount = 0
      elsif (args.length == 1)
        decode(args[0])
      end
    end

new_from_data(data) click to toggle source

    # File lib/Dnsruby/message.rb, line 752
    def Header.new_from_data(data)
      header = Header.new
      MessageDecoder.new(data) {|msg|
        header.decode(msg)}
      return header
    end

### Public Instance Methods

==(other) click to toggle source

    # File lib/Dnsruby/message.rb, line 796
    def ==(other)
      return @qr == other.qr &&
        @opcode == other.opcode &&
        @aa == other.aa &&
        @tc == other.tc &&
        @rd == other.rd &&
        @ra == other.ra &&
        @cd == other.cd &&
        @ad == other.ad &&
        @rcode == other.get_header_rcode
    end

data() click to toggle source

    # File lib/Dnsruby/message.rb, line 759
    def data
      return MessageEncoder.new {|msg|
        self.encode(msg)
      }.to_s
    end

decode(msg) click to toggle source

    # File lib/Dnsruby/message.rb, line 845
    def decode(msg)
      @id, flag, @qdcount, @ancount, @nscount, @arcount =
        msg.get_unpack('nnnnnn')
      @qr = (((flag >> 15)&1)==1)?true:false
      @opcode = OpCode.new((flag >> 11) & 15)
      @aa = (((flag >> 10)&1)==1)?true:false
      @tc = (((flag >> 9)&1)==1)?true:false
      @rd = (((flag >> 8)&1)==1)?true:false
      @ra = (((flag >> 7)&1)==1)?true:false
      @ad = (((flag >> 5)&1)==1)?true:false
      @cd = (((flag >> 4)&1)==1)?true:false
      @rcode = RCode.new(flag & 15)
    end

encode(msg) click to toggle source

    # File lib/Dnsruby/message.rb, line 765
    def encode(msg)
      msg.put_pack('nnnnnn',
        @id,
        (@qr ? 1:0) << 15 |
        (@opcode.code & 15) << 11 |
        (@aa ? 1:0) << 10 |
        (@tc ? 1:0) << 9 |
        (@rd ? 1:0) << 8 |
        (@ra ? 1:0) << 7 |
        (@ad ? 1:0) << 5 |
        (@cd ? 1:0) << 4 |
        (@rcode.code & 15),
        @qdcount,
        @ancount,
        @nscount,
        @arcount)
    end

get_header_rcode() click to toggle source

This new get_header_rcode method is intended for use only by the Message class. This is because the Message OPT section may contain an extended rcode (see RFC 2671 section 4.6). Using the header rcode only ignores this extension, and is not recommended.

    # File lib/Dnsruby/message.rb, line 707
    def get_header_rcode
      @rcode
    end

opcode=(op) click to toggle source

    # File lib/Dnsruby/message.rb, line 744
    def opcode=(op)
      @opcode = OpCode.new(op)
    end

rcode=(rcode) click to toggle source

    # File lib/Dnsruby/message.rb, line 748
    def rcode=(rcode)
      @rcode = RCode.new(rcode)
    end

to_s() click to toggle source

    # File lib/Dnsruby/message.rb, line 808
    def to_s
      to_s_with_rcode(@rcode)
    end

to_s_with_rcode(rcode) click to toggle source

    # File lib/Dnsruby/message.rb, line 812
    def to_s_with_rcode(rcode)
      retval = ";; id = #{@id}\n";

      if (@opcode == OpCode::Update)
        retval += ";; qr = #{@qr}    " +           "opcode = #{@opcode.string}    "+           "rcode = #{@rcode.string}\n";

        retval += ";; zocount = #{@qdcount}  "+           "prcount = #{@ancount}  " +           "upcount = #{@nscount}  "  +           "adcount = #{@arcount}\n";
      else
        retval += ";; qr = #{@qr}    "  +           "opcode = #{@opcode.string}    " +           "aa = #{@aa}    "  +           "tc = #{@tc}    " +           "rd = #{@rd}\n";

        retval += ";; ra = #{@ra}    " +           "ad = #{@ad}    "  +           "cd = #{@cd}    "  +           "rcode  = #{rcode.string}\n";

        retval += ";; qdcount = #{@qdcount}  " +           "ancount = #{@ancount}  " +           "nscount = #{@nscount}  " +           "arcount = #{@arcount}\n";
      end

      return retval;
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.