| 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 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
# 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
# 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
# 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
# File lib/Dnsruby/message.rb, line 754
754: def data
755: return MessageEncoder.new {|msg|
756: self.encode(msg)
757: }.to_s
758: end
# 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
# 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.
# File lib/Dnsruby/message.rb, line 702
702: def get_header_rcode
703: @rcode
704: end
# File lib/Dnsruby/message.rb, line 743
743: def rcode=(rcode)
744: @rcode = RCode.new(rcode)
745: end
# 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