lib/net/dns/header.rb in net-dns-0.7.1 vs lib/net/dns/header.rb in net-dns-0.8.0
- old
+ new
@@ -1,43 +1,34 @@
module Net
module DNS
+ # DNS packet header class
#
- # =Name
- #
- # Net::DNS::Header - DNS packet header class
- #
- # =Synopsis
- #
- # require 'net/dns/header'
- #
- # =Description
- #
# The Net::DNS::Header class represents the header portion of a
# DNS packet. An Header object is created whenever a new packet
# is parsed or as user request.
#
# header = Net::DNS::Header.new
- # # ;; id = 18123
- # # ;; qr = 0 opCode: 0 aa = 0 tc = 0 rd = 1
- # # ;; ra = 0 ad = 0 cd = 0 rcode = 0
- # # ;; qdCount = 1 anCount = 0 nsCount = 0 arCount = 0
+ # # ;; id = 18123
+ # # ;; qr = 0 opCode: 0 aa = 0 tc = 0 rd = 1
+ # # ;; ra = 0 ad = 0 cd = 0 rcode = 0
+ # # ;; qdCount = 1 anCount = 0 nsCount = 0 arCount = 0
#
# header.format
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 18123 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # |0| 0 |0|0|1|0|0| 0 | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 1 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 18123 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # |0| 0 |0|0|1|0|0| 0 | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 1 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# # packet is an instance of Net::DNS::Packet
# header = packet.header
# puts "Answer is #{header.auth? ? '' : 'non'} authoritative"
#
@@ -61,30 +52,19 @@
# Base error class.
class Error < StandardError
end
- # The requested ID is already in use.
- class DuplicateIDError < Error
- end
-
+ # DNS Header RCode handling class
#
- # = Name
- #
- # Net::DNS::Header::RCode - DNS Header RCode handling class
- #
- # =Synopsis
- #
# It should be used internally by Net::DNS::Header class. However, it's still
# possible to instantiate it directly.
#
# require 'net/dns/header'
# rcode = Net::DNS::Header::RCode.new 0
#
- # =Description
- #
# The RCode class represents the RCode field in the Header portion of a
# DNS packet. This field (called Response Code) is used to get informations
# about the status of a DNS operation, such as a query or an update. These
# are the values in the original Mockapetris's standard (RFC1035):
#
@@ -169,21 +149,20 @@
def to_s
@code.to_s
end
end
+
# Constant for +opCode+ query
QUERY = 0
# Constant for +opCode+ iquery
IQUERY = 1
# Constant for +opCode+ status
STATUS = 2
# Array with given strings
OPARR = %w[QUERY IQUERY STATUS]
- @@id_arr = []
-
# Reader for +id+ attribute
attr_reader :id
# Reader for the operational code
attr_reader :opCode
# Reader for the rCode instance
@@ -263,14 +242,14 @@
end
# Inspect method, prints out all the options and relative values.
#
# p Net::DNS::Header.new
- # # ;; id = 18123
- # # ;; qr = 0 opCode: 0 aa = 0 tc = 0 rd = 1
- # # ;; ra = 0 ad = 0 cd = 0 rcode = 0
- # # ;; qdCount = 1 anCount = 0 nsCount = 0 arCount = 0
+ # # ;; id = 18123
+ # # ;; qr = 0 opCode: 0 aa = 0 tc = 0 rd = 1
+ # # ;; ra = 0 ad = 0 cd = 0 rcode = 0
+ # # ;; qdCount = 1 anCount = 0 nsCount = 0 arCount = 0
#
# This method will maybe be changed in the future to a more pretty
# way of display output.
#
def inspect
@@ -297,23 +276,23 @@
# The Net::DNS::Header#format method prints out the header
# in a special ascii representation of data, in a way
# similar to those often found on RFCs.
#
# p Net::DNS::Header.new.format
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 18123 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # |0| 0 |0|0|1|0|0| 0 | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 1 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- # # | 0 |
- # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 18123 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # |0| 0 |0|0|1|0|0| 0 | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 1 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ # # | 0 |
+ # # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# This can be very usefull for didactical purpouses :)
#
def format
del = ("+-" * 16) + "+\n"
@@ -355,16 +334,12 @@
# Set the ID for the current header. Useful when
# performing security tests.
#
def id=(val)
- if @@id_arr.include? val
- raise DuplicateIDError, "ID `#{val}' already used"
- end
- if (1..65535).include? val
+ if (0..65535).include? val
@id = val
- @@id_arr.push val
else
raise ArgumentError, "ID `#{val}' out of range"
end
end
@@ -401,11 +376,11 @@
end
# Returns a string representation of the +opCode+
#
# puts "Packet is a #{header.opCode_str}"
- # #=> Packet is a QUERY
+ # #=> Packet is a QUERY
#
def opCode_str
OPARR[@opCode]
end
@@ -687,11 +662,11 @@
else
raise WrongCountError, "Wrong number of count: `#{val}' must be 0-65535"
end
end
- private
+ private
def new_from_scratch
@id = genID # generate ad unique id
@qr = @aa = @tc = @ra = @ad = @cd = 0
@rCode = RCode.new(0) # no error
@@ -727,13 +702,10 @@
eval "self.#{key.to_s} = val"
end
end
def genID
- while (@@id_arr.include?(q = rand(65535)))
- end
- @@id_arr.push(q)
- q
+ rand(65535)
end
end
end