Class Dnsruby::Header
In: lib/Dnsruby/message.rb
Parent: Object
ResolvError EncodeError OtherResolvError ServFail FormErr DecodeError NXRRSet YXDomain NotImp NXDomain VerifyError NotAuth YXRRSet NotZone Refused TsigError Message Update CodeMapper Types MetaTypes QTypes Nsec3HashAlgorithms Algorithms OpCode Classes ExtendedRCode RCode Modes Comparable Name RRSet Resolver SingleResolver StandardError TimeoutError ResolvTimeout DNS Dnssec Hosts SelectThread\n[lib/Dnsruby/select_thread.rb\nlib/Dnsruby/select_thread.rb.michael.rb] Recursor IPv6 IPv4 ZoneTransfer MessageDecoder MessageEncoder Question Header TheLog 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/DLV.rb\nlib/Dnsruby/resource/DNSKEY.rb\nlib/Dnsruby/resource/DS.rb\nlib/Dnsruby/resource/HINFO.rb\nlib/Dnsruby/resource/IN.rb\nlib/Dnsruby/resource/ISDN.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/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] ValidatorThread PacketSender ResolverRuby Config KeyCache Cache SingleVerifier Resolv Iana lib/Dnsruby/DNS.rb lib/Dnsruby/dnssec.rb lib/Dnsruby/Hosts.rb lib/Dnsruby/select_thread.rb.michael.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/name.rb lib/dnsruby.rb lib/Dnsruby/resource/TKEY.rb lib/Dnsruby/iana_ports.rb Dnsruby dot/m_56_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]  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.)

ad  [RW]  The Authenticated Data flag
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 768
768:     def Header.decrement_arcount_encoded(bytes)
769:       header = Header.new
770:       header_end = 0
771:       MessageDecoder.new(bytes) {|msg|
772:         header.decode(msg)
773:         header_end = msg.index
774:       }
775:       header.arcount = header.arcount - 1
776:       bytes[0,header_end]=MessageEncoder.new {|msg|
777:         header.encode(msg)}.to_s
778:       return bytes
779:     end

[Source]

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

[Source]

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

Public Instance methods

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Validate]