Parent

Class Index [+]

Quicksearch

Dnsruby::Header

The header portion of a DNS packet

RFC 1035 Section 4.1.1

Constants

MAX_ID

Attributes

id[RW]

The header ID

qr[RW]

The query response flag

aa[RW]

Authoritative answer flag

tc[RW]

Truncated flag

rd[RW]

Recursion Desired flag

cd[RW]

The Checking Disabled 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.)

qr[RW]

The query response flag

ra[RW]

Recursion available flag

opcode[R]

The header opcode

qdcount[RW]

The number of records in the question section of the message

nscount[RW]

The number of records in the authoriy section of 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

Public Class Methods

decrement_arcount_encoded(bytes) click to toggle source
     # File lib/Dnsruby/message.rb, line 778
778:     def Header.decrement_arcount_encoded(bytes)
779:       header = Header.new
780:       header_end = 0
781:       MessageDecoder.new(bytes) {|msg|
782:         header.decode(msg)
783:         header_end = msg.index
784:       }
785:       header.arcount = header.arcount - 1
786:       bytes[0,header_end]=MessageEncoder.new {|msg|
787:         header.encode(msg)}.to_s
788:       return bytes
789:     end
new(*args) click to toggle source
     # File lib/Dnsruby/message.rb, line 718
718:     def initialize(*args)
719:       if (args.length == 0)
720:         @id = rand(MAX_ID)
721:         @qr = false
722:         @opcode=OpCode.Query
723:         @aa = false
724:         @ad=false
725:         @tc = false
726:         @rd = false # recursion desired
727:         @ra = false # recursion available
728:         @cd=false
729:         @rcode=RCode.NoError
730:         @qdcount = 0
731:         @nscount = 0
732:         @ancount = 0
733:         @arcount = 0
734:       elsif (args.length == 1)
735:         decode(args[0])
736:       end
737:     end
new_from_data(data) click to toggle source
     # File lib/Dnsruby/message.rb, line 747
747:     def Header.new_from_data(data)
748:       header = Header.new
749:       MessageDecoder.new(data) {|msg|
750:         header.decode(msg)}
751:       return header
752:     end

Public Instance Methods

==(other) click to toggle source
     # File lib/Dnsruby/message.rb, line 791
791:     def ==(other)
792:       return @qr == other.qr &&
793:         @opcode == other.opcode &&
794:         @aa == other.aa &&
795:         @tc == other.tc &&
796:         @rd == other.rd &&
797:         @ra == other.ra &&
798:         @cd == other.cd &&
799:         @ad == other.ad &&
800:         @rcode == other.get_header_rcode
801:     end
data() click to toggle source
     # File lib/Dnsruby/message.rb, line 754
754:     def data
755:       return MessageEncoder.new {|msg|
756:         self.encode(msg)
757:       }.to_s
758:     end
decode(msg) click to toggle source
     # File lib/Dnsruby/message.rb, line 840
840:     def decode(msg)
841:       @id, flag, @qdcount, @ancount, @nscount, @arcount =
842:         msg.get_unpack('nnnnnn')
843:       @qr = (((flag >> 15)&1)==1)?true:false
844:       @opcode = OpCode.new((flag >> 11) & 15)
845:       @aa = (((flag >> 10)&1)==1)?true:false
846:       @tc = (((flag >> 9)&1)==1)?true:false
847:       @rd = (((flag >> 8)&1)==1)?true:false
848:       @ra = (((flag >> 7)&1)==1)?true:false
849:       @ad = (((flag >> 5)&1)==1)?true:false
850:       @cd = (((flag >> 4)&1)==1)?true:false
851:       @rcode = RCode.new(flag & 15)
852:     end
encode(msg) click to toggle source
     # File lib/Dnsruby/message.rb, line 760
760:     def encode(msg)
761:       msg.put_pack('nnnnnn',
762:         @id,
763:         (@qr ? 1:0) << 15 |
764:         (@opcode.code & 15) << 11 |
765:         (@aa ? 1:0) << 10 |
766:         (@tc ? 1:0) << 9 |
767:         (@rd ? 1:0) << 8 |
768:         (@ra ? 1:0) << 7 |
769:         (@ad ? 1:0) << 5 |
770:         (@cd ? 1:0) << 4 |
771:         (@rcode.code & 15),
772:         @qdcount,
773:         @ancount,
774:         @nscount,
775:         @arcount)
776:     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 702
702:     def get_header_rcode
703:       @rcode
704:     end
opcode=(op) click to toggle source
     # File lib/Dnsruby/message.rb, line 739
739:     def opcode=(op)
740:       @opcode = OpCode.new(op)
741:     end
rcode=(rcode) click to toggle source
     # File lib/Dnsruby/message.rb, line 743
743:     def rcode=(rcode)
744:       @rcode = RCode.new(rcode)
745:     end
to_s() click to toggle source
     # File lib/Dnsruby/message.rb, line 803
803:     def to_s
804:       to_s_with_rcode(@rcode)
805:     end
to_s_with_rcode(rcode) click to toggle source
     # File lib/Dnsruby/message.rb, line 807
807:     def to_s_with_rcode(rcode)
808:       retval = ";; id = #{@id}\n";
809:       
810:       if (@opcode == OpCode::Update)
811:         retval += ";; qr = #{@qr}    " +           "opcode = #{@opcode.string}    "+           "rcode = #{@rcode.string}\n";
812:         
813:         retval += ";; zocount = #{@qdcount}  "+           "prcount = #{@ancount}  " +           "upcount = #{@nscount}  "  +           "adcount = #{@arcount}\n";
814:       else
815:         retval += ";; qr = #{@qr}    "  +           "opcode = #{@opcode.string}    " +           "aa = #{@aa}    "  +           "tc = #{@tc}    " +           "rd = #{@rd}\n";
816:         
817:         retval += ";; ra = #{@ra}    " +           "ad = #{@ad}    "  +           "cd = #{@cd}    "  +           "rcode  = #{rcode.string}\n";
818:         
819:         retval += ";; qdcount = #{@qdcount}  " +           "ancount = #{@ancount}  " +           "nscount = #{@nscount}  " +           "arcount = #{@arcount}\n";
820:       end
821:       
822:       return retval;
823:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.