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] | 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 |
# 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
# 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
# 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
# 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
# File lib/Dnsruby/message.rb, line 746 746: def data 747: return MessageEncoder.new {|msg| 748: self.encode(msg) 749: }.to_s 750: end
# 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
# 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.
# File lib/Dnsruby/message.rb, line 694 694: def get_header_rcode 695: @rcode 696: end
# File lib/Dnsruby/message.rb, line 735 735: def rcode=(rcode) 736: @rcode = RCode.new(rcode) 737: end
# 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