net-dns 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -6
- data/.travis.yml +14 -0
- data/CHANGELOG.md +79 -0
- data/Gemfile +4 -0
- data/Rakefile +56 -66
- data/demo/check_soa.rb +1 -1
- data/demo/threads.rb +1 -1
- data/lib/net/dns.rb +24 -22
- data/lib/net/dns/header.rb +77 -103
- data/lib/net/dns/{names/names.rb → names.rb} +19 -20
- data/lib/net/dns/packet.rb +231 -256
- data/lib/net/dns/question.rb +11 -40
- data/lib/net/dns/resolver.rb +248 -250
- data/lib/net/dns/resolver/socks.rb +6 -6
- data/lib/net/dns/resolver/timeouts.rb +1 -1
- data/lib/net/dns/rr.rb +112 -117
- data/lib/net/dns/rr/a.rb +98 -89
- data/lib/net/dns/rr/aaaa.rb +84 -68
- data/lib/net/dns/rr/classes.rb +91 -106
- data/lib/net/dns/rr/cname.rb +64 -45
- data/lib/net/dns/rr/hinfo.rb +90 -50
- data/lib/net/dns/rr/mr.rb +61 -44
- data/lib/net/dns/rr/mx.rb +73 -48
- data/lib/net/dns/rr/ns.rb +60 -46
- data/lib/net/dns/rr/null.rb +11 -12
- data/lib/net/dns/rr/ptr.rb +47 -34
- data/lib/net/dns/rr/soa.rb +5 -6
- data/lib/net/dns/rr/srv.rb +1 -4
- data/lib/net/dns/rr/txt.rb +14 -14
- data/lib/net/dns/rr/types.rb +13 -13
- data/lib/net/dns/version.rb +8 -14
- data/net-dns.gemspec +35 -0
- data/setup.rb +3 -2
- data/test/header_test.rb +18 -18
- data/test/names_test.rb +21 -0
- data/test/packet_test.rb +38 -31
- data/test/question_test.rb +23 -24
- data/test/resolver/timeouts_test.rb +13 -13
- data/test/resolver_test.rb +28 -20
- data/test/rr/a_test.rb +70 -23
- data/test/rr/aaaa_test.rb +109 -0
- data/test/rr/classes_test.rb +61 -49
- data/test/rr/cname_test.rb +97 -0
- data/test/rr/hinfo_test.rb +117 -0
- data/test/rr/mr_test.rb +105 -0
- data/test/rr/mx_test.rb +112 -0
- data/test/rr/ns_test.rb +34 -12
- data/test/rr/types_test.rb +4 -4
- data/test/rr_test.rb +1 -1
- metadata +77 -52
- data/AUTHORS.rdoc +0 -7
- data/CHANGELOG.rdoc +0 -46
- data/VERSION.yml +0 -5
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
|
4
|
+
## Release 0.7.0
|
5
|
+
|
6
|
+
* ADDED: Added (experimental) Support for HINFO record.
|
7
|
+
|
8
|
+
* FIXED: Use Net::DNS::Resolver::Error class (not ResolverError, which does not exist).
|
9
|
+
|
10
|
+
* FIXED: Cleaned up require dependency and recursive require statements.
|
11
|
+
|
12
|
+
* FIXED: Use RbConfig instead of obsolete and deprecated Config (GH-28, GH-33) [Thanks @shadowbq, @eik3]
|
13
|
+
|
14
|
+
* FIXED: SRV record not required by Net::DNS::RR (GH-27) [Thanks @sebastian]
|
15
|
+
|
16
|
+
* FIXED: Resolver now supports IPv6 (GH-32) [Thanks @jamesotron]
|
17
|
+
|
18
|
+
* FIXED: Net::DNS::RR::PTR references an invalid parameter (GH-19) [Thanks @dd23]
|
19
|
+
|
20
|
+
* FIXED: Net::DNS::Question changes input arguments (GH-7) [Thanks @gfarfl]
|
21
|
+
|
22
|
+
* CHANGED: Refactoring unit test to follow most used Ruby conventions.
|
23
|
+
|
24
|
+
* CHANGED: Rewritten and simplified Net::DNS::Classes. Improved test harness.
|
25
|
+
|
26
|
+
* CHANGED: Removed Jeweler development dependency.
|
27
|
+
|
28
|
+
* CHANGED: The library is now compatible with Bundler.
|
29
|
+
|
30
|
+
* CHANGED: Minimum supported Ruby version changed to Ruby 1.8.7.
|
31
|
+
|
32
|
+
* CHANGED: Rescue NameError so unsupported record types only result in a warning.
|
33
|
+
|
34
|
+
* CHANGED: Renamed Net::DNS::Resolver#send to Net::DNS::Resolver#query to avoid overriding default meaning of send method.
|
35
|
+
|
36
|
+
|
37
|
+
## Release 0.6.1
|
38
|
+
|
39
|
+
* ADDED: Net::DNS::Packet#to_s method (alias of #inspect)
|
40
|
+
|
41
|
+
* FIXED: typo in lib/net/dns/rr/ptr.rb [Thanks Chris Lundquist]
|
42
|
+
|
43
|
+
* FIXED: warning: method redefined; discarding old inspect (GH-3) [Thanks Kevin Baker]
|
44
|
+
|
45
|
+
* FIXED: issue with rescue ArgumentError (GH-5) and with IPAddr handling (GH-6)
|
46
|
+
|
47
|
+
|
48
|
+
## Release 0.6.0
|
49
|
+
|
50
|
+
*WARNING:* If you are upgrading from a previous minor release, check out the Compatibility issue list below.
|
51
|
+
|
52
|
+
* FIXED: Added missing #to_s method to Net::DNS::Question.
|
53
|
+
|
54
|
+
* FIXED: Compatibility with Ruby 1.9
|
55
|
+
|
56
|
+
* FIXED: Types regexp order issue
|
57
|
+
|
58
|
+
* CHANGED: Refactoring unit test to follow most used Ruby conventions
|
59
|
+
|
60
|
+
* CHANGED: default timeout is now 5 seconds for both UDP and TCP
|
61
|
+
|
62
|
+
* CHANGED: Moved main dns.rb file to lib/net folder as default for GEMs. In this way it can be autoloaded when the gem is required.
|
63
|
+
|
64
|
+
### Compatibility issues
|
65
|
+
|
66
|
+
* CHANGED: RR#set_stype scope is now private to prevent invalid usage.
|
67
|
+
|
68
|
+
* CHANGED: DnsTimeout#timeout now raises LocalJumpError instead of DnsTimeoutArgumentError when block is missing.
|
69
|
+
|
70
|
+
* CHANGED: Renamed Net::DNS::RR::Types::Types to Net::DNS::RR::Types::TYPES to follow Ruby coding standards.
|
71
|
+
|
72
|
+
|
73
|
+
## Release 0.4
|
74
|
+
|
75
|
+
* many bug fixes (thanks guys!)
|
76
|
+
* a whole new class Net::DNS::Header::RCode
|
77
|
+
* new methods in Net::DNS::Resolver class to do AXFR queries
|
78
|
+
* a new SRV resource record written by Dan Janowski
|
79
|
+
* more documentation written and corrected
|
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,80 +1,70 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
5
|
+
require 'net/dns'
|
6
|
+
|
7
|
+
|
8
|
+
# Common package properties
|
9
|
+
PKG_NAME = ENV['PKG_NAME'] || 'net-dns'
|
10
|
+
PKG_VERSION = ENV['PKG_VERSION'] || Net::DNS::VERSION
|
11
|
+
|
12
|
+
|
13
|
+
# Run test by default.
|
14
|
+
task :default => :test
|
15
|
+
|
16
|
+
|
17
|
+
spec = Gem::Specification.new do |s|
|
18
|
+
s.name = PKG_NAME
|
19
|
+
s.version = PKG_VERSION
|
20
|
+
s.summary = "Pure Ruby DNS library."
|
21
|
+
s.description = "Net::DNS is a pure Ruby DNS library, with a clean OO interface and an extensible API."
|
22
|
+
|
23
|
+
s.required_ruby_version = ">= 1.8.7"
|
24
|
+
|
25
|
+
s.authors = ["Marco Ceresa", "Simone Carletti"]
|
26
|
+
s.email = ["ceresa@gmail.com", "weppos@weppos.net"]
|
27
|
+
s.homepage = "http://github.com/bluemonk/net-dns"
|
28
|
+
s.rubyforge_project = "net-dns"
|
29
|
+
|
30
|
+
s.add_development_dependency "rake", "~> 0.9"
|
31
|
+
s.add_development_dependency "yard"
|
32
|
+
|
33
|
+
s.files = `git ls-files`.split("\n")
|
34
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
35
|
+
s.require_paths = %w( lib )
|
22
36
|
end
|
23
37
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
38
|
+
|
39
|
+
require 'rubygems/package_task'
|
40
|
+
|
41
|
+
Gem::PackageTask.new(spec) do |pkg|
|
42
|
+
pkg.gem_spec = spec
|
29
43
|
end
|
30
44
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
test.pattern = 'test/**/*_test.rb'
|
36
|
-
test.verbose = true
|
37
|
-
end
|
38
|
-
rescue LoadError
|
39
|
-
task :rcov => :check_dependencies
|
45
|
+
desc "Build the gemspec file #{spec.name}.gemspec"
|
46
|
+
task :gemspec do
|
47
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
48
|
+
File.open(file, "w") {|f| f << spec.to_ruby }
|
40
49
|
end
|
41
50
|
|
42
|
-
task :default => :test
|
43
51
|
|
44
|
-
require 'rake/
|
45
|
-
Rake::RDocTask.new do |rdoc|
|
46
|
-
if File.exist?('VERSION.yml')
|
47
|
-
config = YAML.load(File.read('VERSION.yml'))
|
48
|
-
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
49
|
-
else
|
50
|
-
puts "VERSION.yml not found!"
|
51
|
-
version = ""
|
52
|
-
end
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "net-dns #{version}"
|
56
|
-
rdoc.rdoc_files.include('*.rdoc')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
-
end
|
52
|
+
require 'rake/testtask'
|
59
53
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
open(fn) do |f|
|
66
|
-
while line = f.gets
|
67
|
-
count += 1
|
68
|
-
if line =~ pattern
|
69
|
-
puts "#{fn}:#{count}:#{line}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
egrep /(FIXME|TODO|TBD)/
|
54
|
+
# Run all the tests in the /test folder
|
55
|
+
Rake::TestTask.new do |t|
|
56
|
+
t.libs << "test"
|
57
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
58
|
+
t.verbose = true
|
76
59
|
end
|
77
60
|
|
61
|
+
|
62
|
+
require 'yard'
|
63
|
+
require 'yard/rake/yardoc_task'
|
64
|
+
|
65
|
+
YARD::Rake::YardocTask.new(:yardoc)
|
66
|
+
|
67
|
+
|
78
68
|
desc "Open an irb session preloaded with this library"
|
79
69
|
task :console do
|
80
70
|
sh "irb -rubygems -I lib -r net/dns.rb"
|
data/demo/check_soa.rb
CHANGED
data/demo/threads.rb
CHANGED
data/lib/net/dns.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
require 'net/dns/core_ext'
|
2
2
|
require 'net/dns/version'
|
3
|
+
require 'net/dns/resolver'
|
3
4
|
|
4
|
-
module Net
|
5
|
+
module Net
|
5
6
|
module DNS
|
6
|
-
|
7
|
+
|
7
8
|
# Packet size in bytes
|
8
|
-
PACKETSZ
|
9
|
-
|
10
|
-
# Size of the header
|
11
|
-
HFIXEDSZ
|
12
|
-
|
9
|
+
PACKETSZ = 512
|
10
|
+
|
11
|
+
# Size of the header
|
12
|
+
HFIXEDSZ = 12
|
13
|
+
|
13
14
|
# Size of the question portion (type and class)
|
14
|
-
QFIXEDSZ
|
15
|
-
|
15
|
+
QFIXEDSZ = 4
|
16
|
+
|
16
17
|
# Size of an RR portion (type,class,lenght and ttl)
|
17
18
|
RRFIXEDSZ = 10
|
18
|
-
|
19
|
+
|
19
20
|
# Size of an int 32 bit
|
20
|
-
INT32SZ
|
21
|
-
|
21
|
+
INT32SZ = 4
|
22
|
+
|
22
23
|
# Size of a short int
|
23
|
-
INT16SZ
|
24
|
+
INT16SZ = 2
|
24
25
|
|
25
26
|
|
26
27
|
module QueryTypes
|
27
|
-
|
28
|
+
|
28
29
|
SIGZERO = 0
|
29
30
|
A = 1
|
30
31
|
NS = 2
|
@@ -83,28 +84,29 @@ module Net # :nodoc:
|
|
83
84
|
ANY = 255
|
84
85
|
|
85
86
|
end
|
86
|
-
|
87
|
+
|
87
88
|
module QueryClasses
|
88
|
-
|
89
|
+
|
89
90
|
# Internet class
|
90
91
|
IN = 1
|
91
|
-
|
92
|
+
|
92
93
|
# Chaos class
|
93
94
|
CH = 3
|
94
|
-
|
95
|
+
|
95
96
|
# Hesiod class
|
96
97
|
HS = 4
|
97
|
-
|
98
|
+
|
98
99
|
# None class
|
99
100
|
NONE = 254
|
100
|
-
|
101
|
+
|
101
102
|
# Any class
|
102
103
|
ANY = 255
|
103
|
-
|
104
|
+
|
104
105
|
end
|
105
|
-
|
106
|
+
|
106
107
|
include QueryTypes
|
107
108
|
include QueryClasses
|
108
109
|
|
109
110
|
end
|
111
|
+
|
110
112
|
end
|
data/lib/net/dns/header.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
module Net # :nodoc:
|
5
|
-
module DNS
|
1
|
+
module Net
|
2
|
+
module DNS
|
6
3
|
|
7
4
|
#
|
8
5
|
# =Name
|
@@ -10,15 +7,15 @@ module Net # :nodoc:
|
|
10
7
|
# Net::DNS::Header - DNS packet header class
|
11
8
|
#
|
12
9
|
# =Synopsis
|
13
|
-
#
|
10
|
+
#
|
14
11
|
# require 'net/dns/header'
|
15
12
|
#
|
16
13
|
# =Description
|
17
|
-
#
|
18
|
-
# The Net::DNS::Header class represents the header portion of a
|
14
|
+
#
|
15
|
+
# The Net::DNS::Header class represents the header portion of a
|
19
16
|
# DNS packet. An Header object is created whenever a new packet
|
20
17
|
# is parsed or as user request.
|
21
|
-
#
|
18
|
+
#
|
22
19
|
# header = Net::DNS::Header.new
|
23
20
|
# # ;; id = 18123
|
24
21
|
# # ;; qr = 0 opCode: 0 aa = 0 tc = 0 rd = 1
|
@@ -46,53 +43,30 @@ module Net # :nodoc:
|
|
46
43
|
#
|
47
44
|
# A lot of methods were written to keep a compatibility layer with
|
48
45
|
# the Perl version of the library, as long as methods name which are
|
49
|
-
# more or less the same.
|
50
|
-
#
|
51
|
-
# =Error classes
|
52
|
-
#
|
53
|
-
# Some error classes has been defined for the Net::DNS::Header class,
|
54
|
-
# which are listed here to keep a light and browsable main documentation.
|
55
|
-
# We have:
|
56
|
-
#
|
57
|
-
# ArgumentError:: Argument Error for class Net::DNS::Packet
|
58
|
-
# WrongCountError:: A wrong +count+ parameter has been passed
|
59
|
-
# WrongRecursiveError:: A wrong +recursive+ parameter has been passed
|
60
|
-
# WrongOpcodeError:: A not valid +opCode+ has been specified
|
61
|
-
# DuplicateIDError:: The requested ID is already in use
|
62
|
-
#
|
63
|
-
# =Copyright
|
64
|
-
#
|
65
|
-
# Copyright (c) 2006 Marco Ceresa
|
66
|
-
#
|
67
|
-
# All rights reserved. This program is free software; you may redistribute
|
68
|
-
# it and/or modify it under the same terms as Ruby itself.
|
46
|
+
# more or less the same.
|
69
47
|
#
|
70
48
|
class Header
|
71
|
-
|
72
|
-
#
|
73
|
-
class ArgumentError < ArgumentError
|
74
|
-
end
|
75
|
-
|
76
|
-
# A wrong +count+ parameter has been passed-
|
49
|
+
|
50
|
+
# A wrong +count+ parameter has been passed.
|
77
51
|
class WrongCountError < ArgumentError
|
78
52
|
end
|
79
|
-
|
80
|
-
# A wrong +recursive+ parameter has been passed
|
53
|
+
|
54
|
+
# A wrong +recursive+ parameter has been passed.
|
81
55
|
class WrongRecursiveError < ArgumentError
|
82
56
|
end
|
83
|
-
|
57
|
+
|
84
58
|
# An invalid +opCode+ has been specified.
|
85
59
|
class WrongOpcodeError < ArgumentError
|
86
60
|
end
|
87
|
-
|
61
|
+
|
88
62
|
# Base error class.
|
89
63
|
class Error < StandardError
|
90
64
|
end
|
91
|
-
|
65
|
+
|
92
66
|
# The requested ID is already in use.
|
93
67
|
class DuplicateIDError < Error
|
94
68
|
end
|
95
|
-
|
69
|
+
|
96
70
|
|
97
71
|
#
|
98
72
|
# = Name
|
@@ -109,13 +83,13 @@ module Net # :nodoc:
|
|
109
83
|
#
|
110
84
|
# =Description
|
111
85
|
#
|
112
|
-
# The RCode class represents the RCode field in the Header portion of a
|
113
|
-
# DNS packet. This field (called Response Code) is used to get informations
|
86
|
+
# The RCode class represents the RCode field in the Header portion of a
|
87
|
+
# DNS packet. This field (called Response Code) is used to get informations
|
114
88
|
# about the status of a DNS operation, such as a query or an update. These
|
115
89
|
# are the values in the original Mockapetris's standard (RFC1035):
|
116
90
|
#
|
117
91
|
# * 0 No error condition
|
118
|
-
# * 1 Format error - The name server was unable to interpret
|
92
|
+
# * 1 Format error - The name server was unable to interpret
|
119
93
|
# the query.
|
120
94
|
# * 2 Server failure - The name server was
|
121
95
|
# unable to process this query due to a
|
@@ -137,7 +111,7 @@ module Net # :nodoc:
|
|
137
111
|
# transfer) for particular data.
|
138
112
|
# * 6-15 Reserved for future use.
|
139
113
|
#
|
140
|
-
# In the next DNS RFCs, codes 6-15 has been assigned to the following
|
114
|
+
# In the next DNS RFCs, codes 6-15 has been assigned to the following
|
141
115
|
# errors:
|
142
116
|
#
|
143
117
|
# * 6 YXDomain
|
@@ -149,7 +123,7 @@ module Net # :nodoc:
|
|
149
123
|
# More RCodes has to come for TSIGs and other operations.
|
150
124
|
#
|
151
125
|
class RCode
|
152
|
-
|
126
|
+
|
153
127
|
# Constant for +rcode+ Response Code No Error
|
154
128
|
NOERROR = 0
|
155
129
|
# Constant for +rcode+ Response Code Format Error
|
@@ -164,10 +138,10 @@ module Net # :nodoc:
|
|
164
138
|
REFUSED = 5
|
165
139
|
|
166
140
|
|
167
|
-
|
168
|
-
RCodeType = %w[NoError FormErr ServFail NXDomain NotImp
|
169
|
-
Refused YXDomain YXRRSet NXRRSet NotAuth NotZone]
|
170
|
-
|
141
|
+
|
142
|
+
RCodeType = %w[NoError FormErr ServFail NXDomain NotImp
|
143
|
+
Refused YXDomain YXRRSet NXRRSet NotAuth NotZone]
|
144
|
+
|
171
145
|
RCodeErrorString = ["No errors",
|
172
146
|
"The name server was unable to interpret the query",
|
173
147
|
"The name server was unable to process this query due to problem with the name server",
|
@@ -179,24 +153,24 @@ module Net # :nodoc:
|
|
179
153
|
"",
|
180
154
|
"",
|
181
155
|
""]
|
182
|
-
|
156
|
+
|
183
157
|
attr_reader :code, :type, :explanation
|
184
158
|
|
185
159
|
def initialize(code)
|
186
160
|
if (0..10).include? code
|
187
161
|
@code = code
|
188
162
|
@type = RCodeType[code]
|
189
|
-
@explanation = RCodeErrorString[code]
|
163
|
+
@explanation = RCodeErrorString[code]
|
190
164
|
else
|
191
165
|
raise ArgumentError, "RCode `#{code}' out of range"
|
192
166
|
end
|
193
167
|
end
|
194
|
-
|
168
|
+
|
195
169
|
def to_s
|
196
170
|
@code.to_s
|
197
171
|
end
|
198
172
|
end
|
199
|
-
|
173
|
+
|
200
174
|
# Constant for +opCode+ query
|
201
175
|
QUERY = 0
|
202
176
|
# Constant for +opCode+ iquery
|
@@ -207,8 +181,8 @@ module Net # :nodoc:
|
|
207
181
|
OPARR = %w[QUERY IQUERY STATUS]
|
208
182
|
|
209
183
|
@@id_arr = []
|
210
|
-
|
211
|
-
# Reader for +id+ attribute
|
184
|
+
|
185
|
+
# Reader for +id+ attribute
|
212
186
|
attr_reader :id
|
213
187
|
# Reader for the operational code
|
214
188
|
attr_reader :opCode
|
@@ -222,10 +196,10 @@ module Net # :nodoc:
|
|
222
196
|
attr_reader :nsCount
|
223
197
|
# Reader for addictional section entries number
|
224
198
|
attr_reader :arCount
|
225
|
-
|
199
|
+
|
226
200
|
# Creates a new Net::DNS::Header object with the desired values,
|
227
201
|
# which can be specified as an Hash argument. When called without
|
228
|
-
# arguments, defaults are used. If a data string is passed, values
|
202
|
+
# arguments, defaults are used. If a data string is passed, values
|
229
203
|
# are taken from parsing the string.
|
230
204
|
#
|
231
205
|
# Examples:
|
@@ -266,7 +240,7 @@ module Net # :nodoc:
|
|
266
240
|
end
|
267
241
|
end
|
268
242
|
|
269
|
-
# Creates a new Net::DNS::Header object from binary data, which is
|
243
|
+
# Creates a new Net::DNS::Header object from binary data, which is
|
270
244
|
# passed as a string object as argument.
|
271
245
|
# The configurations parameters are taken from parsing the string.
|
272
246
|
#
|
@@ -275,8 +249,8 @@ module Net # :nodoc:
|
|
275
249
|
# # Create a new Net::DNS::Header object with binary data
|
276
250
|
# header = Net::DNS::Header.new(data)
|
277
251
|
#
|
278
|
-
# header.auth?
|
279
|
-
# #=> "true" if it comes from authoritative name server
|
252
|
+
# header.auth?
|
253
|
+
# #=> "true" if it comes from authoritative name server
|
280
254
|
#
|
281
255
|
def self.parse(arg)
|
282
256
|
if arg.kind_of? String
|
@@ -287,9 +261,9 @@ module Net # :nodoc:
|
|
287
261
|
raise ArgumentError, "Wrong argument class `#{arg.class}'"
|
288
262
|
end
|
289
263
|
end
|
290
|
-
|
264
|
+
|
291
265
|
# Inspect method, prints out all the options and relative values.
|
292
|
-
#
|
266
|
+
#
|
293
267
|
# p Net::DNS::Header.new
|
294
268
|
# # ;; id = 18123
|
295
269
|
# # ;; qr = 0 opCode: 0 aa = 0 tc = 0 rd = 1
|
@@ -299,7 +273,7 @@ module Net # :nodoc:
|
|
299
273
|
# This method will maybe be changed in the future to a more pretty
|
300
274
|
# way of display output.
|
301
275
|
#
|
302
|
-
def inspect
|
276
|
+
def inspect
|
303
277
|
";; id = #@id\n" +
|
304
278
|
if false # @opCode == "UPDATE"
|
305
279
|
#do stuff
|
@@ -319,11 +293,11 @@ module Net # :nodoc:
|
|
319
293
|
"arCount = #@arCount\n"
|
320
294
|
end
|
321
295
|
end
|
322
|
-
|
296
|
+
|
323
297
|
# The Net::DNS::Header#format method prints out the header
|
324
|
-
# in a special ascii representation of data, in a way
|
325
|
-
# similar to those often found on RFCs.
|
326
|
-
#
|
298
|
+
# in a special ascii representation of data, in a way
|
299
|
+
# similar to those often found on RFCs.
|
300
|
+
#
|
327
301
|
# p Net::DNS::Header.new.format
|
328
302
|
# # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
329
303
|
# # | 18123 |
|
@@ -341,7 +315,7 @@ module Net # :nodoc:
|
|
341
315
|
#
|
342
316
|
# This can be very usefull for didactical purpouses :)
|
343
317
|
#
|
344
|
-
def format
|
318
|
+
def format
|
345
319
|
del = ("+-" * 16) + "+\n"
|
346
320
|
len = del.length
|
347
321
|
str = del + "|" + @id.to_s.center(len-3) + "|\n"
|
@@ -360,8 +334,8 @@ module Net # :nodoc:
|
|
360
334
|
str += del + "|" + @arCount.to_s.center(len-3) + "|\n" + del
|
361
335
|
str
|
362
336
|
end
|
363
|
-
|
364
|
-
# Returns the header data in binary format, appropriate
|
337
|
+
|
338
|
+
# Returns the header data in binary format, appropriate
|
365
339
|
# for use in a DNS query packet.
|
366
340
|
#
|
367
341
|
# hdata = header.data
|
@@ -393,15 +367,15 @@ module Net # :nodoc:
|
|
393
367
|
raise ArgumentError, "ID `#{val}' out of range"
|
394
368
|
end
|
395
369
|
end
|
396
|
-
|
370
|
+
|
397
371
|
# Checks whether the header is a query (+qr+ bit set to 0)
|
398
372
|
#
|
399
373
|
def query?
|
400
374
|
@qr == 0
|
401
375
|
end
|
402
376
|
|
403
|
-
# Set the +qr+ query response flag to be either +true+ or
|
404
|
-
# +false+. You can also use the values 0 and 1. This flag
|
377
|
+
# Set the +qr+ query response flag to be either +true+ or
|
378
|
+
# +false+. You can also use the values 0 and 1. This flag
|
405
379
|
# indicates if the DNS packet contains a query or an answer,
|
406
380
|
# so it should be set to +true+ in DNS answer packets.
|
407
381
|
# If +qr+ is +true+, the packet is a response.
|
@@ -419,7 +393,7 @@ module Net # :nodoc:
|
|
419
393
|
end
|
420
394
|
end
|
421
395
|
|
422
|
-
# Checks whether the header is a response
|
396
|
+
# Checks whether the header is a response
|
423
397
|
# (+qr+ bit set to 1)
|
424
398
|
#
|
425
399
|
def response?
|
@@ -436,15 +410,15 @@ module Net # :nodoc:
|
|
436
410
|
end
|
437
411
|
|
438
412
|
# Set the +opCode+ variable to a new value. This fields indicates
|
439
|
-
# the type of the question present in the DNS packet; +val+ can be
|
440
|
-
# one of the values QUERY, IQUERY or STATUS.
|
413
|
+
# the type of the question present in the DNS packet; +val+ can be
|
414
|
+
# one of the values QUERY, IQUERY or STATUS.
|
441
415
|
#
|
442
416
|
# * QUERY is the standard DNS query
|
443
417
|
# * IQUERY is the inverse query
|
444
418
|
# * STATUS is used to query the nameserver for its status
|
445
419
|
#
|
446
420
|
# Example:
|
447
|
-
#
|
421
|
+
#
|
448
422
|
# include Net::DNS
|
449
423
|
# header = Header.new
|
450
424
|
# header.opCode = Header::STATUS
|
@@ -470,10 +444,10 @@ module Net # :nodoc:
|
|
470
444
|
end
|
471
445
|
|
472
446
|
# Set the +aa+ flag (authoritative answer) to either +true+
|
473
|
-
# or +false+. You can also use 0 or 1.
|
447
|
+
# or +false+. You can also use 0 or 1.
|
474
448
|
#
|
475
449
|
# This flag indicates whether a DNS answer packet contains
|
476
|
-
# authoritative data, meaning that is was generated by a
|
450
|
+
# authoritative data, meaning that is was generated by a
|
477
451
|
# nameserver authoritative for the domain of the question.
|
478
452
|
#
|
479
453
|
# Must only be set to +true+ in DNS answer packets.
|
@@ -490,7 +464,7 @@ module Net # :nodoc:
|
|
490
464
|
raise ArgumentError, ":aa must be true(or 1) or false(or 0)"
|
491
465
|
end
|
492
466
|
end
|
493
|
-
|
467
|
+
|
494
468
|
# Checks whether the packet was truncated
|
495
469
|
#
|
496
470
|
# # Sending packet using UDP
|
@@ -504,14 +478,14 @@ module Net # :nodoc:
|
|
504
478
|
@tc == 1
|
505
479
|
end
|
506
480
|
|
507
|
-
# Set the +tc+ flag (truncated packet) to either +true+
|
481
|
+
# Set the +tc+ flag (truncated packet) to either +true+
|
508
482
|
# ot +false+. You can also use 0 or 1.
|
509
483
|
#
|
510
484
|
# The truncated flag is used in response packets to indicate
|
511
|
-
# that the amount of data to be trasmitted exceedes the
|
512
|
-
# maximum allowed by the protocol in use, tipically UDP, and
|
513
|
-
# that the data present in the packet has been truncated.
|
514
|
-
# A different protocol (such has TCP) need to be used to
|
485
|
+
# that the amount of data to be trasmitted exceedes the
|
486
|
+
# maximum allowed by the protocol in use, tipically UDP, and
|
487
|
+
# that the data present in the packet has been truncated.
|
488
|
+
# A different protocol (such has TCP) need to be used to
|
515
489
|
# retrieve full data.
|
516
490
|
#
|
517
491
|
# Must only be set in DNS answer packets.
|
@@ -528,7 +502,7 @@ module Net # :nodoc:
|
|
528
502
|
raise ArgumentError, ":tc must be true(or 1) or false(or 0)"
|
529
503
|
end
|
530
504
|
end
|
531
|
-
|
505
|
+
|
532
506
|
# Checks whether the packet has a recursion bit
|
533
507
|
# set, meaning that recursion is desired
|
534
508
|
#
|
@@ -567,7 +541,7 @@ module Net # :nodoc:
|
|
567
541
|
def rd=(val)
|
568
542
|
self.recursive = val
|
569
543
|
end
|
570
|
-
|
544
|
+
|
571
545
|
# Checks whether recursion is available.
|
572
546
|
# This flag is usually set by nameservers to indicate
|
573
547
|
# that they support recursive-type queries.
|
@@ -602,7 +576,7 @@ module Net # :nodoc:
|
|
602
576
|
@cd == 0
|
603
577
|
end
|
604
578
|
|
605
|
-
# Set the +cd+ flag (checking disabled) to either +true+
|
579
|
+
# Set the +cd+ flag (checking disabled) to either +true+
|
606
580
|
# ot +false+. You can also use 0 or 1.
|
607
581
|
#
|
608
582
|
def cd=(val)
|
@@ -626,11 +600,11 @@ module Net # :nodoc:
|
|
626
600
|
@ad == 1
|
627
601
|
end
|
628
602
|
|
629
|
-
# Set the +ad+ flag to either +true+
|
603
|
+
# Set the +ad+ flag to either +true+
|
630
604
|
# ot +false+. You can also use 0 or 1.
|
631
605
|
#
|
632
|
-
# The AD bit is only set on answers where signatures have
|
633
|
-
# been cryptographically verified or the server is
|
606
|
+
# The AD bit is only set on answers where signatures have
|
607
|
+
# been cryptographically verified or the server is
|
634
608
|
# authoritative for the data and is allowed to set the bit by policy.
|
635
609
|
#
|
636
610
|
def ad=(val)
|
@@ -645,7 +619,7 @@ module Net # :nodoc:
|
|
645
619
|
raise ArgumentError, ":ad must be true(or 1) or false(or 0)"
|
646
620
|
end
|
647
621
|
end
|
648
|
-
|
622
|
+
|
649
623
|
# Returns an error array for the header response code, or
|
650
624
|
# +nil+ if no error is generated.
|
651
625
|
#
|
@@ -667,14 +641,14 @@ module Net # :nodoc:
|
|
667
641
|
def error?
|
668
642
|
@rCode.code > 0
|
669
643
|
end
|
670
|
-
|
671
|
-
# Set the rCode value. This should only be done in DNS
|
644
|
+
|
645
|
+
# Set the rCode value. This should only be done in DNS
|
672
646
|
# answer packets.
|
673
647
|
#
|
674
648
|
def rCode=(val)
|
675
649
|
@rCode = RCode.new(val)
|
676
650
|
end
|
677
|
-
|
651
|
+
|
678
652
|
# Sets the number of entries in a question section
|
679
653
|
#
|
680
654
|
def qdCount=(val)
|
@@ -716,16 +690,16 @@ module Net # :nodoc:
|
|
716
690
|
end
|
717
691
|
|
718
692
|
private
|
719
|
-
|
693
|
+
|
720
694
|
def new_from_scratch
|
721
695
|
@id = genID # generate ad unique id
|
722
696
|
@qr = @aa = @tc = @ra = @ad = @cd = 0
|
723
|
-
@rCode = RCode.new(0) # no error
|
697
|
+
@rCode = RCode.new(0) # no error
|
724
698
|
@anCount = @nsCount = @arCount = 0
|
725
699
|
@rd = @qdCount = 1
|
726
|
-
@opCode = QUERY # standard query, default message
|
700
|
+
@opCode = QUERY # standard query, default message
|
727
701
|
end
|
728
|
-
|
702
|
+
|
729
703
|
def new_from_binary(str)
|
730
704
|
unless str.size == Net::DNS::HFIXEDSZ
|
731
705
|
raise ArgumentError, "Header binary data has wrong size: `#{str.size}' bytes"
|
@@ -746,14 +720,14 @@ module Net # :nodoc:
|
|
746
720
|
@nsCount = arr[5]
|
747
721
|
@arCount = arr[6]
|
748
722
|
end
|
749
|
-
|
723
|
+
|
750
724
|
def new_from_hash(hash)
|
751
725
|
new_from_scratch
|
752
726
|
hash.each do |key,val|
|
753
727
|
eval "self.#{key.to_s} = val"
|
754
728
|
end
|
755
729
|
end
|
756
|
-
|
730
|
+
|
757
731
|
def genID
|
758
732
|
while (@@id_arr.include?(q = rand(65535)))
|
759
733
|
end
|
@@ -764,4 +738,4 @@ module Net # :nodoc:
|
|
764
738
|
end
|
765
739
|
|
766
740
|
end
|
767
|
-
end
|
741
|
+
end
|