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/PX.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 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

[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

[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

[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

[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

[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

[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

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 702
702:     def get_header_rcode
703:       @rcode
704:     end

[Source]

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

[Source]

     # File lib/Dnsruby/message.rb, line 743
743:     def rcode=(rcode)
744:       @rcode = RCode.new(rcode)
745:     end

[Source]

     # File lib/Dnsruby/message.rb, line 803
803:     def to_s
804:       to_s_with_rcode(@rcode)
805:     end

[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}    " +\
812:           "opcode = #{@opcode.string}    "+\
813:           "rcode = #{@rcode.string}\n";
814:         
815:         retval += ";; zocount = #{@qdcount}  "+\
816:           "prcount = #{@ancount}  " +\
817:           "upcount = #{@nscount}  "  +\
818:           "adcount = #{@arcount}\n";
819:       else
820:         retval += ";; qr = #{@qr}    "  +\
821:           "opcode = #{@opcode.string}    " +\
822:           "aa = #{@aa}    "  +\
823:           "tc = #{@tc}    " +\
824:           "rd = #{@rd}\n";
825:         
826:         retval += ";; ra = #{@ra}    " +\
827:           "ad = #{@ad}    "  +\
828:           "cd = #{@cd}    "  +\
829:           "rcode  = #{rcode.string}\n";
830:         
831:         retval += ";; qdcount = #{@qdcount}  " +\
832:           "ancount = #{@ancount}  " +\
833:           "nscount = #{@nscount}  " +\
834:           "arcount = #{@arcount}\n";
835:       end
836:       
837:       return retval;
838:     end

[Validate]