Class Dnsruby::Header
In: lib/Dnsruby/message.rb
Parent: Object
Message Update ResolvError EncodeError OtherResolvError ServFail FormErr DecodeError NXRRSet YXDomain NotImp NXDomain VerifyError NotAuth YXRRSet NotZone Refused TsigError CodeMapper Types MetaTypes QTypes Nsec3HashAlgorithms Algorithms OpCode Classes ExtendedRCode Modes RCode Comparable Name RRSet TsigNotSignedResponseError Resolver SingleResolver StandardError TimeoutError ResolvTimeout DNS Dnssec Hosts RR\n[lib/Dnsruby/resource/A.rb\nlib/Dnsruby/resource/AAAA.rb\nlib/Dnsruby/resource/AFSDB.rb\nlib/Dnsruby/resource/CERT.rb\nlib/Dnsruby/resource/DHCID.rb\nlib/Dnsruby/resource/DLV.rb\nlib/Dnsruby/resource/DNSKEY.rb\nlib/Dnsruby/resource/DS.rb\nlib/Dnsruby/resource/HINFO.rb\nlib/Dnsruby/resource/HIP.rb\nlib/Dnsruby/resource/IN.rb\nlib/Dnsruby/resource/IPSECKEY.rb\nlib/Dnsruby/resource/ISDN.rb\nlib/Dnsruby/resource/KX.rb\nlib/Dnsruby/resource/LOC.rb\nlib/Dnsruby/resource/MINFO.rb\nlib/Dnsruby/resource/MX.rb\nlib/Dnsruby/resource/NAPTR.rb\nlib/Dnsruby/resource/NSAP.rb\nlib/Dnsruby/resource/NSEC.rb\nlib/Dnsruby/resource/NSEC3.rb\nlib/Dnsruby/resource/NSEC3PARAM.rb\nlib/Dnsruby/resource/OPT.rb\nlib/Dnsruby/resource/PX.rb\nlib/Dnsruby/resource/RP.rb\nlib/Dnsruby/resource/RRSIG.rb\nlib/Dnsruby/resource/RT.rb\nlib/Dnsruby/resource/SOA.rb\nlib/Dnsruby/resource/SPF.rb\nlib/Dnsruby/resource/SRV.rb\nlib/Dnsruby/resource/SSHFP.rb\nlib/Dnsruby/resource/TKEY.rb\nlib/Dnsruby/resource/TSIG.rb\nlib/Dnsruby/resource/TXT.rb\nlib/Dnsruby/resource/X25.rb\nlib/Dnsruby/resource/domain_name.rb\nlib/Dnsruby/resource/generic.rb\nlib/Dnsruby/resource/resource.rb] Recursor IPv6 IPv4 ZoneTransfer MessageDecoder MessageEncoder Question Header TheLog ValidatorThread PacketSender ResolverRuby Config KeyCache Cache SingleVerifier SelectThread Resolv ZoneReader lib/Dnsruby/DNS.rb lib/Dnsruby/dnssec.rb lib/Dnsruby/Hosts.rb lib/Dnsruby/resource/generic.rb lib/Dnsruby/Recursor.rb lib/Dnsruby/update.rb lib/Dnsruby/ipv6.rb lib/Dnsruby/ipv4.rb lib/Dnsruby/code_mapper.rb lib/Dnsruby/zone_transfer.rb lib/Dnsruby/message.rb lib/Dnsruby/TheLog.rb lib/Dnsruby/resource/resource.rb lib/Dnsruby/validator_thread.rb lib/Dnsruby/PacketSender.rb lib/Dnsruby/Resolver.rb lib/Dnsruby/Config.rb lib/Dnsruby/key_cache.rb lib/Dnsruby/Cache.rb lib/Dnsruby/single_verifier.rb lib/Dnsruby/SingleResolver.rb lib/Dnsruby/select_thread.rb lib/Dnsruby/name.rb lib/dnsruby.rb lib/Dnsruby/resource/TKEY.rb lib/Dnsruby/zone_reader.rb Dnsruby dot/m_61_0.png

The header portion of a DNS packet

RFC 1035 Section 4.1.1

Methods

Constants

MAX_ID = 65535

External Aliases

qdcount -> zocount
qdcount= -> zocount=
ancount -> prcount
ancount= -> prcount=
nscount -> upcount
nscount= -> upcount=
arcount -> adcount
arcount= -> adcount=

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.)
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
qdcount  [RW]  The number of records in the question section of the message
qr  [RW]  The query response flag
qr  [RW]  The query response flag
ra  [RW]  Recursion available flag
rd  [RW]  Recursion Desired flag
tc  [RW]  Truncated flag

Public Class methods

[Source]

     # File lib/Dnsruby/message.rb, line 770
770:     def Header.decrement_arcount_encoded(bytes)
771:       header = Header.new
772:       header_end = 0
773:       MessageDecoder.new(bytes) {|msg|
774:         header.decode(msg)
775:         header_end = msg.index
776:       }
777:       header.arcount = header.arcount - 1
778:       bytes[0,header_end]=MessageEncoder.new {|msg|
779:         header.encode(msg)}.to_s
780:       return bytes
781:     end

[Source]

     # File lib/Dnsruby/message.rb, line 710
710:     def initialize(*args)
711:       if (args.length == 0)
712:         @id = rand(MAX_ID)
713:         @qr = false
714:         @opcode=OpCode.Query
715:         @aa = false
716:         @ad=false
717:         @tc = false
718:         @rd = false # recursion desired
719:         @ra = false # recursion available
720:         @cd=false
721:         @rcode=RCode.NoError
722:         @qdcount = 0
723:         @nscount = 0
724:         @ancount = 0
725:         @arcount = 0
726:       elsif (args.length == 1)
727:         decode(args[0])
728:       end
729:     end

[Source]

     # File lib/Dnsruby/message.rb, line 739
739:     def Header.new_from_data(data)
740:       header = Header.new
741:       MessageDecoder.new(data) {|msg|
742:         header.decode(msg)}
743:       return header
744:     end

Public Instance methods

[Source]

     # File lib/Dnsruby/message.rb, line 783
783:     def ==(other)
784:       return @qr == other.qr &&
785:         @opcode == other.opcode &&
786:         @aa == other.aa &&
787:         @tc == other.tc &&
788:         @rd == other.rd &&
789:         @ra == other.ra &&
790:         @cd == other.cd &&
791:         @ad == other.ad &&
792:         @rcode == other.get_header_rcode
793:     end

[Source]

     # File lib/Dnsruby/message.rb, line 746
746:     def data
747:       return MessageEncoder.new {|msg|
748:         self.encode(msg)
749:       }.to_s
750:     end

[Source]

     # File lib/Dnsruby/message.rb, line 832
832:     def decode(msg)
833:       @id, flag, @qdcount, @ancount, @nscount, @arcount =
834:         msg.get_unpack('nnnnnn')
835:       @qr = (((flag >> 15)&1)==1)?true:false
836:       @opcode = OpCode.new((flag >> 11) & 15)
837:       @aa = (((flag >> 10)&1)==1)?true:false
838:       @tc = (((flag >> 9)&1)==1)?true:false
839:       @rd = (((flag >> 8)&1)==1)?true:false
840:       @ra = (((flag >> 7)&1)==1)?true:false
841:       @ad = (((flag >> 5)&1)==1)?true:false
842:       @cd = (((flag >> 4)&1)==1)?true:false
843:       @rcode = RCode.new(flag & 15)
844:     end

[Source]

     # File lib/Dnsruby/message.rb, line 752
752:     def encode(msg)
753:       msg.put_pack('nnnnnn',
754:         @id,
755:         (@qr ? 1:0) << 15 |
756:         (@opcode.code & 15) << 11 |
757:         (@aa ? 1:0) << 10 |
758:         (@tc ? 1:0) << 9 |
759:         (@rd ? 1:0) << 8 |
760:         (@ra ? 1:0) << 7 |
761:         (@ad ? 1:0) << 5 |
762:         (@cd ? 1:0) << 4 |
763:         (@rcode.code & 15),
764:         @qdcount,
765:         @ancount,
766:         @nscount,
767:         @arcount)
768:     end

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.

[Source]

     # File lib/Dnsruby/message.rb, line 694
694:     def get_header_rcode
695:       @rcode
696:     end

[Source]

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

[Source]

     # File lib/Dnsruby/message.rb, line 735
735:     def rcode=(rcode)
736:       @rcode = RCode.new(rcode)
737:     end

[Source]

     # File lib/Dnsruby/message.rb, line 795
795:     def to_s
796:       to_s_with_rcode(@rcode)
797:     end

[Source]

     # File lib/Dnsruby/message.rb, line 799
799:     def to_s_with_rcode(rcode)
800:       retval = ";; id = #{@id}\n";
801:       
802:       if (@opcode == OpCode::Update)
803:         retval += ";; qr = #{@qr}    " +\
804:           "opcode = #{@opcode.string}    "+\
805:           "rcode = #{@rcode.string}\n";
806:         
807:         retval += ";; zocount = #{@qdcount}  "+\
808:           "prcount = #{@ancount}  " +\
809:           "upcount = #{@nscount}  "  +\
810:           "adcount = #{@arcount}\n";
811:       else
812:         retval += ";; qr = #{@qr}    "  +\
813:           "opcode = #{@opcode.string}    " +\
814:           "aa = #{@aa}    "  +\
815:           "tc = #{@tc}    " +\
816:           "rd = #{@rd}\n";
817:         
818:         retval += ";; ra = #{@ra}    " +\
819:           "ad = #{@ad}    "  +\
820:           "cd = #{@cd}    "  +\
821:           "rcode  = #{rcode.string}\n";
822:         
823:         retval += ";; qdcount = #{@qdcount}  " +\
824:           "ancount = #{@ancount}  " +\
825:           "nscount = #{@nscount}  " +\
826:           "arcount = #{@arcount}\n";
827:       end
828:       
829:       return retval;
830:     end

[Validate]