| Class | Dnsruby::Header |
| In: |
lib/Dnsruby/message.rb
|
| Parent: | Object |
The header portion of a DNS packet
RFC 1035 Section 4.1.1
| MAX_ID | = | 65535 |
| qdcount | -> | zocount |
| qdcount= | -> | zocount= |
| ancount | -> | prcount |
| ancount= | -> | prcount= |
| nscount | -> | upcount |
| nscount= | -> | upcount= |
| arcount | -> | adcount |
| arcount= | -> | adcount= |
| 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 |
# 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
# 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
# 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
# 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
# File lib/Dnsruby/message.rb, line 744
744: def data
745: return MessageEncoder.new {|msg|
746: self.encode(msg)
747: }.to_s
748: end
# 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
# 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.
# File lib/Dnsruby/message.rb, line 692
692: def get_header_rcode
693: @rcode
694: end
# File lib/Dnsruby/message.rb, line 733
733: def rcode=(rcode)
734: @rcode = RCode.new(rcode)
735: end
# 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