net-dns2 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ed3f3e2f37539751f0eb14cebde9652653c2774b
4
- data.tar.gz: 83dbbb4ff3215849a7394cefa7eac3a49a55e326
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGJiMWM3NGY5YzgxMmM0OTk4NmQxYmM4NTA1ODg3YjMyN2QyZTYxMA==
5
+ data.tar.gz: !binary |-
6
+ MDRkYjY2YzBhZWRiNzM1OWM0ODY1MzgwNmI1Mjk1ZjZiODE1YWQ2Mw==
5
7
  SHA512:
6
- metadata.gz: ca5ba8110bdd4feb9d12e2228aa1147943c38100e45c0412862b7dbabe547010eb452aceb9ca393f64b00f2e9e1425ab9380e55dbf132e06d402695101fd97f6
7
- data.tar.gz: 4e3be6b483ae98e989072aa04142da0a04199397bd9be6a6eeac7b917bb0e78452dbd5047a199dd3b70381952e684ffc49dfdfe51931ec26bbecaf71f8ef2748
8
+ metadata.gz: !binary |-
9
+ ZGFhZmIxZjQxODMxM2U5Y2MxNWIzM2QzYjYwNzkwOTU1NmVkN2RkYTVjYTNj
10
+ ZmNlNjQ1YzA1YTA3OTliZjMyNzFkOTM1MGM5ZWFiOGRlMTc3Y2IwYzdjNmM5
11
+ YmJkMDkzNTQ3NjZiNDY5NWIyYTljMjEzZGE3OGExNmUwMmU0NGY=
12
+ data.tar.gz: !binary |-
13
+ NDU5NTA1NzBmNTZiZmZhZGYxZjEwOGZkMDJkZTNiNWY1OTEzNDMwZmJlMmI5
14
+ ZWQzYWZlMTBlZWY5YzhkYWZhNmQ1OTgzMjMzN2U1ZjRkN2EyMDk5ZTBmNGZj
15
+ Y2RkNWM5NzJlNGViNDRjNWRiYzBjYzAyN2E0NTEwMTI4OTVmODc=
@@ -1,20 +1,12 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.8.7
5
4
  - 1.9.2
6
5
  - 1.9.3
7
6
  - 2.0.0
8
- # - jruby-18mode
9
- # - jruby-19mode
10
- - rbx-18mode
11
- # - ruby-head
12
- # - jruby-head
7
+ - 2.1.0
8
+ - ruby-head
13
9
 
14
10
  notifications:
15
11
  recipients:
16
12
  - mordocai@mordocai.net
17
-
18
- matrix:
19
- allow_failures:
20
- - rvm: 2.0.0
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## Release 0.8.3
4
+ - FIXED: Packet size cannot be set issue #1
5
+ - FIXED: Now raise exception if raw sockets are requested and we are not
6
+ running as root issue #23
7
+ - FIXED: Rake can build gem, travis file updated to test up to
8
+ ruby-head issue #30
9
+ - FIXED: Merged in pending bluemonk pull requests issue #29, remaining
10
+ fixes are from these
11
+ - FIXED: Cannot get TXT record issue #13
12
+ https://github.com/bluemonk/net-dns/pull/42
13
+ - FIXED: Various fixes by neoraider
14
+ https://github.com/bluemonk/net-dns/pull/36
15
+ - FIXED: query_tcp fix by nbaum
16
+ https://github.com/bluemonk/net-dns/pull/63
17
+ - FIXED: Text fixes by chrislundquist
18
+ https://github.com/bluemonk/net-dns/pull/52
19
+ https://github.com/bluemonk/net-dns/pull/51
20
+ - CHANGED: Support SPF records by winebarrel
21
+ https://github.com/bluemonk/net-dns/pull/57
22
+ - CHANGED: Simplified nameserver settings
23
+ https://github.com/bluemonk/net-dns/pull/60
24
+
3
25
  ## Release 0.8.2
4
26
  - FIXED: Exception when using new raw support issue #2
5
27
  - FIXED: Gemspec file has wrong emails
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Net::DNS
2
2
  [![Build Status](https://travis-ci.org/mordocai/net-dns.svg?branch=master)](https://travis-ci.org/mordocai/net-dns)
3
3
 
4
- Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net::DNS module, but it evolved in time into a full Ruby library.
4
+ https://rubygems.org/gems/net-dns2
5
+
6
+ Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net::DNS module, but it evolved in time into a full Ruby library.
5
7
 
6
8
 
7
9
  ## Features
@@ -9,6 +11,7 @@ Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net
9
11
  - Complete OO interface
10
12
  - Clean and intuitive API
11
13
  - Modular and flexible
14
+ - Source address spoofing (via source_address= on Net::DNS::Resolver)
12
15
 
13
16
 
14
17
  ## Requirements
@@ -20,21 +23,21 @@ Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net
20
23
 
21
24
  The best way to install this library is via [RubyGems](https://rubygems.org/).
22
25
 
23
- $ gem install net-dns
26
+ $ gem install net-dns2
24
27
 
25
28
  You might need administrator privileges on your system to install the gem.
26
29
 
27
30
 
28
31
  ## API Documentation
29
32
 
30
- Visit the page http://rdoc.info/gems/net-dns
33
+ Visit the page http://rdoc.info/gems/net-dns2
31
34
 
32
35
 
33
36
  ## Trivial resolver
34
37
 
35
38
  The simplest way to use the library is to invoke the Resolver() method:
36
39
 
37
- require 'rubygems'
40
+ require 'rubygems'
38
41
  require 'net/dns'
39
42
  p Resolver("www.google.com")
40
43
 
@@ -47,21 +50,21 @@ The output is compatible with BIND zone files and it's the same you would get wi
47
50
  ;; qr = 1 opCode: QUERY aa = 0 tc = 0 rd = 1
48
51
  ;; ra = 1 ad = 0 cd = 0 rcode = NoError
49
52
  ;; qdCount = 1 anCount = 3 nsCount = 4 arCount = 4
50
-
53
+
51
54
  ;; QUESTION SECTION (1 record):
52
55
  ;; google.com. IN A
53
-
56
+
54
57
  ;; ANSWER SECTION (3 records):
55
58
  google.com. 212 IN A 74.125.45.100
56
59
  google.com. 212 IN A 74.125.67.100
57
60
  google.com. 212 IN A 209.85.171.100
58
-
61
+
59
62
  ;; AUTHORITY SECTION (4 records):
60
63
  google.com. 345512 IN NS ns1.google.com.
61
64
  google.com. 345512 IN NS ns4.google.com.
62
65
  google.com. 345512 IN NS ns2.google.com.
63
66
  google.com. 345512 IN NS ns3.google.com.
64
-
67
+
65
68
  ;; ADDITIONAL SECTION (4 records):
66
69
  ns1.google.com. 170275 IN A 216.239.32.10
67
70
  ns2.google.com. 170275 IN A 216.239.34.10
@@ -81,7 +84,7 @@ Same for Net::DNS::Resolver.start():
81
84
  As optional parameters, +TYPE+ and +CLASS+ can be specified.
82
85
 
83
86
  p Net::DNS::Resolver.start("google.com", Net::DNS::MX)
84
-
87
+
85
88
  ;; Answer received from localhost:53 (316 bytes)
86
89
  ;;
87
90
  ;; HEADER SECTION
@@ -89,10 +92,10 @@ As optional parameters, +TYPE+ and +CLASS+ can be specified.
89
92
  ;; qr = 1 opCode: QUERY aa = 0 tc = 0 rd = 1
90
93
  ;; ra = 1 ad = 0 cd = 0 rcode = NoError
91
94
  ;; qdCount = 1 anCount = 4 nsCount = 4 arCount = 8
92
-
95
+
93
96
  ;; QUESTION SECTION (1 record):
94
97
  ;; google.com. IN MX
95
-
98
+
96
99
  ;; ANSWER SECTION (4 records):
97
100
  google.com. 10800 IN MX 10 smtp2.google.com.
98
101
  google.com. 10800 IN MX 10 smtp3.google.com.
@@ -115,16 +118,16 @@ A DNS packet is divided into 5 sections:
115
118
  You can access each section by calling the attribute with the same name on a Packet object:
116
119
 
117
120
  packet = Net::DNS::Resolver.start("google.com")
118
-
121
+
119
122
  header = packet.header
120
123
  answer = packet.answer
121
-
124
+
122
125
  puts "The packet is #{packet.data.size} bytes"
123
126
  puts "It contains #{header.anCount} answer entries"
124
-
127
+
125
128
  answer.any? {|ans| p ans}
126
-
127
- The output is
129
+
130
+ The output is
128
131
 
129
132
  The packet is 378 bytes
130
133
  It contains 3 answer entries
data/Rakefile CHANGED
@@ -1,80 +1,25 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require 'rspec'
3
4
 
4
5
  $:.unshift(File.dirname(__FILE__) + '/lib')
5
6
  require 'net/dns'
6
7
 
7
8
 
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, :spec]
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"
31
- s.add_development_dependency "rspec"
32
- s.add_development_dependency "yard"
33
-
34
- s.files = `git ls-files`.split("\n")
35
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
- s.require_paths = %w( lib )
37
- end
38
-
39
-
40
- require 'rubygems/package_task'
41
-
42
- Gem::PackageTask.new(spec) do |pkg|
43
- pkg.gem_spec = spec
44
- end
45
-
46
- desc "Build the gemspec file #{spec.name}.gemspec"
47
- task :gemspec do
48
- file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
49
- File.open(file, "w") {|f| f << spec.to_ruby }
50
- end
51
-
52
-
53
- require 'rake/testtask'
54
-
55
- # Run all the tests in the /test folder
56
- Rake::TestTask.new do |t|
57
- t.libs << "test"
58
- t.test_files = FileList["test/**/*_test.rb"]
59
- t.verbose = true
60
- end
61
-
9
+ task :default => [:spec, :gem]
62
10
 
11
+ require 'rake'
63
12
  require 'rspec/core/rake_task'
64
- begin
65
- require 'fuubar'
66
- rescue LoadError
67
- end
68
13
 
69
- RSpec::Core::RakeTask.new do |t|
70
- t.verbose = !!ENV["VERBOSE"]
71
- t.rspec_opts = []
72
- t.rspec_opts << ['--format', 'Fuubar'] if defined?(Fuubar)
14
+ RSpec::Core::RakeTask.new(:spec) do |t|
15
+ t.pattern = FileList['spec/**/*_spec.rb']
16
+ t.rspec_opts = ["-r ./spec/spec_helper.rb"]
73
17
  end
74
18
 
19
+ require 'rubygems/package_task'
20
+ Gem::PackageTask.new(Gem::Specification.load("net-dns.gemspec")).define
75
21
 
76
22
  require 'yard'
77
-
78
23
  YARD::Rake::YardocTask.new(:yardoc) do |y|
79
24
  y.options = ["--output-dir", "yardoc"]
80
25
  end
@@ -71,6 +71,7 @@ module Net
71
71
  RRSIG = 46
72
72
  NSEC = 47
73
73
  DNSKEY = 48
74
+ SPF = 99
74
75
  UINFO = 100
75
76
  UID = 101
76
77
  GID = 102
@@ -152,14 +152,17 @@ module Net
152
152
  end
153
153
 
154
154
 
155
+ # Listing: http://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-5
155
156
  # Constant for +opCode+ query
156
157
  QUERY = 0
157
158
  # Constant for +opCode+ iquery
158
159
  IQUERY = 1
159
160
  # Constant for +opCode+ status
160
161
  STATUS = 2
162
+ # Constant for +opCode+ notify
163
+ NOTIFY = 4
161
164
  # Array with given strings
162
- OPARR = %w[QUERY IQUERY STATUS]
165
+ OPARR = %w[QUERY IQUERY STATUS UNASSIGNED NOTIFY]
163
166
 
164
167
  # Reader for +id+ attribute
165
168
  attr_reader :id
@@ -391,6 +394,7 @@ module Net
391
394
  # * QUERY is the standard DNS query
392
395
  # * IQUERY is the inverse query
393
396
  # * STATUS is used to query the nameserver for its status
397
+ # * NOTIFY is to notify a slave that it should check for an updated SOA on the master
394
398
  #
395
399
  # Example:
396
400
  #
@@ -399,10 +403,10 @@ module Net
399
403
  # header.opCode = Header::STATUS
400
404
  #
401
405
  def opCode=(val)
402
- if (0..2).include? val
406
+ if [0, 1, 2, 4].include? val
403
407
  @opCode = val
404
408
  else
405
- raise WrongOpcodeError, "Wrong opCode value (#{val}), must be QUERY, IQUERY or STATUS"
409
+ raise WrongOpcodeError, "Wrong opCode value (#{val}), must be QUERY, IQUERY, STATUS, or NOTIFY"
406
410
  end
407
411
  end
408
412
 
@@ -15,7 +15,7 @@ module Net # :nodoc:
15
15
  INT16SZ = 2
16
16
 
17
17
  # Expand a compressed name in a DNS Packet object. Please
18
- # see RFC1025 for an explanation of how the compression
18
+ # see RFC1035 for an explanation of how the compression
19
19
  # in DNS packets works, how may it be useful and how should
20
20
  # be handled.
21
21
  #
@@ -27,7 +27,7 @@ module Net # :nodoc:
27
27
  name = ""
28
28
  packetlen = packet.size
29
29
  while true
30
- raise ExpandError, "Offset is greater than packet lenght!" if packetlen < (offset+1)
30
+ raise ExpandError, "Offset is greater than packet length!" if packetlen < (offset+1)
31
31
  len = packet.unpack("@#{offset} C")[0]
32
32
 
33
33
  if len == 0
@@ -54,7 +54,7 @@ module Net # :nodoc:
54
54
  end
55
55
 
56
56
  def pack_name(name)
57
- if name.size > 255
57
+ if name.size > 255
58
58
  raise ArgumentError, "Name may not exceed 255 chars"
59
59
  end
60
60
  arr = name.split(".")
@@ -106,13 +106,21 @@ module Net # :nodoc:
106
106
  end
107
107
 
108
108
  def valid?(name)
109
- if name =~ /^([a-z0-9]([-a-z0-9]*[a-z0-9])?\.)+((a[cdefgilmnoqrstuwxz]|aero|arpa)|(b[abdefghijmnorstvwyz]|biz)|(c[acdfghiklmnorsuvxyz]|cat|com|coop)|d[ejkmoz]|(e[ceghrstu]|edu)|f[ijkmor]|(g[abdefghilmnpqrstuwy]|gov)|h[kmnrtu]|(i[delmnoqrst]|info|int)|(j[emop]|jobs)|k[eghimnprwyz]|l[abcikrstuvy]|(m[acdghklmnopqrstuvwxyz]|mil|mobi|museum)|(n[acefgilopruz]|name|net)|(om|org)|(p[aefghklmnrstwy]|pro)|qa|r[eouw]|s[abcdeghijklmnortvyz]|(t[cdfghjklmnoprtvwz]|travel)|u[agkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw])$/i
110
- return name
111
- else
112
- raise ArgumentError, "Invalid FQDN: #{name}"
109
+ return false if name.length < 1 or name.length > 255
110
+
111
+ return true if name == '.' # the root domain is the only valid domain that begins with a dot
112
+
113
+ parts = name.split('.', -1)
114
+ parts.delete_at(parts.length-1) if parts.last.empty? # the domain may end with a dot
115
+
116
+ parts.each do |part|
117
+ if not part =~ /^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/i or part.length < 1 or part.length > 63
118
+ return false
119
+ end
113
120
  end
114
- end
115
121
 
122
+ return true
123
+ end
116
124
  end
117
125
  end
118
126
  end
@@ -97,18 +97,26 @@ module Net
97
97
 
98
98
  # Creates a new instance of <tt>Net::DNS::Packet</tt> class. Arguments are the
99
99
  # canonical name of the resource, an optional type field and an optional
100
- # class field. The record type and class can be omitted; they default
101
- # to +A+ and +IN+.
100
+ # class field. If the arguments are omitted, no question is added to the new packet;
101
+ # type and class default to +A+ and +IN+ if a name is given.
102
102
  #
103
+ # packet = Net::DNS::Packet.new
103
104
  # packet = Net::DNS::Packet.new("www.example.com")
104
105
  # packet = Net::DNS::Packet.new("example.com", Net::DNS::MX)
105
106
  # packet = Net::DNS::Packet.new("example.com", Net::DNS::TXT, Net::DNS::CH)
106
107
  #
107
108
  # This class no longer instantiate object from binary data coming from
108
109
  # network streams. Please use <tt>Net::DNS::Packet.parse</tt> instead.
109
- def initialize(name, type = Net::DNS::A, cls = Net::DNS::IN)
110
- @header = Net::DNS::Header.new(:qdCount => 1)
111
- @question = [Net::DNS::Question.new(name, type, cls)]
110
+ def initialize(name = nil, type = Net::DNS::A, cls = Net::DNS::IN)
111
+ default_qdcount = 0
112
+ @question = []
113
+
114
+ if not name.nil?
115
+ default_qdcount = 1
116
+ @question = [Net::DNS::Question.new(name, type, cls)]
117
+ end
118
+
119
+ @header = Net::DNS::Header.new(:qdCount => default_qdcount)
112
120
  @answer = []
113
121
  @authority = []
114
122
  @additional = []
@@ -119,7 +127,7 @@ module Net
119
127
 
120
128
  # Checks if the packet is a QUERY packet
121
129
  def query?
122
- @header.opCode == Net::DNS::Header::QUERY
130
+ @header.query?
123
131
  end
124
132
 
125
133
  # Returns the packet object in binary data, suitable
@@ -542,7 +550,7 @@ module Net
542
550
  @additional << rrobj
543
551
  @logger.debug rrobj.inspect
544
552
  rescue NameError => e
545
- warn "Net::DNS supported record type: #{e.message}"
553
+ warn "Net::DNS unsupported record type: #{e.message}"
546
554
  end
547
555
  end
548
556
 
@@ -345,38 +345,8 @@ module Net
345
345
  # The default is 127.0.0.1 (localhost)
346
346
  #
347
347
  def nameservers=(arg)
348
- case arg
349
- when String
350
- begin
351
- @config[:nameservers] = [IPAddr.new(arg)]
352
- @logger.info "Nameservers list changed to value #{@config[:nameservers].inspect}"
353
- rescue ArgumentError # arg is in the name form, not IP
354
- nameservers_from_name(arg)
355
- end
356
- when IPAddr
357
- @config[:nameservers] = [arg]
358
- @logger.info "Nameservers list changed to value #{@config[:nameservers].inspect}"
359
- when Array
360
- @config[:nameservers] = []
361
- arg.each do |x|
362
- @config[:nameservers] << case x
363
- when String
364
- begin
365
- IPAddr.new(x)
366
- rescue ArgumentError
367
- nameservers_from_name(arg)
368
- return
369
- end
370
- when IPAddr
371
- x
372
- else
373
- raise ArgumentError, "Wrong argument format"
374
- end
375
- end
376
- @logger.info "Nameservers list changed to value #{@config[:nameservers].inspect}"
377
- else
378
- raise ArgumentError, "Wrong argument format, neither String, Array nor IPAddr"
379
- end
348
+ @config[:nameservers] = convert_nameservers_arg_to_ips(arg)
349
+ @logger.info "Nameservers list changed to value #{@config[:nameservers].inspect}"
380
350
  end
381
351
  alias_method("nameserver=","nameservers=")
382
352
 
@@ -395,6 +365,15 @@ module Net
395
365
  @config[:packet_size]
396
366
  end
397
367
 
368
+ def packet_size=(arg)
369
+ if arg.respond_to? :to_i
370
+ @config[:packet_size] = arg.to_i
371
+ @logger.info "Packet size changed to value #{@config[:packet_size].inspect}"
372
+ else
373
+ @logger.error "Packet size not set, #{arg.class} does not respond to to_i"
374
+ end
375
+ end
376
+
398
377
  # Get the port number to which the resolver sends queries.
399
378
  #
400
379
  # puts "Sending queries to port #{res.port}"
@@ -508,8 +487,12 @@ module Net
508
487
  @logger.warn "Port already in use"
509
488
  retry
510
489
  when 99 # Address is not valid: raw socket
511
- @raw = true
512
- @logger.warn "Using raw sockets"
490
+ if Process.uid == 0
491
+ @raw = true
492
+ @logger.warn "Using raw sockets"
493
+ else
494
+ raise RuntimeError, "Raw sockets requested but not running as root."
495
+ end
513
496
  else
514
497
  raise SystemCallError, e
515
498
  end
@@ -1080,7 +1063,7 @@ module Net
1080
1063
  if self.class.platform_windows?
1081
1064
  require 'win32/resolv'
1082
1065
  arr = Win32::Resolv.get_resolv_info
1083
- self.domain = arr[0].to_s
1066
+ self.domain = arr[0].first.to_s
1084
1067
  self.nameservers = arr[1]
1085
1068
  else
1086
1069
  nameservers = []
@@ -1123,6 +1106,24 @@ module Net
1123
1106
  end
1124
1107
  end
1125
1108
 
1109
+ def convert_nameservers_arg_to_ips(arg)
1110
+ if arg.kind_of? IPAddr
1111
+ [arg]
1112
+ elsif arg.respond_to? :map
1113
+ arg.map{|x| convert_nameservers_arg_to_ips(x) }.flatten
1114
+ elsif arg.respond_to? :to_a
1115
+ arg.to_a.map{|x| convert_nameservers_arg_to_ips(x) }.flatten
1116
+ elsif arg.respond_to? :to_s
1117
+ begin
1118
+ [IPAddr.new(arg.to_s)]
1119
+ rescue ArgumentError # arg is in the name form, not IP
1120
+ nameservers_from_name(arg)
1121
+ end
1122
+ else
1123
+ raise ArgumentError, "Wrong nameservers argument format, cannot convert to array of IPAddrs"
1124
+ end
1125
+ end
1126
+
1126
1127
  def nameservers_from_name(arg)
1127
1128
  arr = []
1128
1129
  arg.split(" ").each do |name|
@@ -1130,26 +1131,21 @@ module Net
1130
1131
  arr << ip
1131
1132
  end
1132
1133
  end
1133
- @config[:nameservers] << arr
1134
+ arr
1134
1135
  end
1135
1136
 
1136
1137
  def make_query_packet(string, type, cls)
1137
- case string
1138
- when IPAddr
1139
- name = string.reverse
1138
+ begin
1139
+ name = IPAddr.new(string.chomp(".")).reverse
1140
1140
  type = Net::DNS::PTR
1141
- @logger.warn "PTR query required for address #{string}, changing type to PTR"
1142
- when /\d/ # Contains a number, try to see if it's an IP or IPv6 address
1143
- begin
1144
- name = IPAddr.new(string.chomp(".")).reverse
1145
- type = Net::DNS::PTR
1146
- rescue ArgumentError
1147
- name = string if valid? string
1148
- end
1149
- else
1141
+ rescue ArgumentError
1150
1142
  name = string if valid? string
1151
1143
  end
1152
1144
 
1145
+ if name.nil?
1146
+ raise ArgumentError, "Bad query string"
1147
+ end
1148
+
1153
1149
  # Create the packet
1154
1150
  packet = Net::DNS::Packet.new(name, type, cls)
1155
1151
 
@@ -1208,13 +1204,16 @@ module Net
1208
1204
  socket.close
1209
1205
  end
1210
1206
  end
1207
+ ans
1211
1208
  end
1212
1209
 
1213
1210
  def query_udp(packet, packet_data)
1214
1211
  socket4 = UDPSocket.new
1215
1212
  socket4.bind(@config[:source_address].to_s,@config[:source_port])
1216
- socket6 = UDPSocket.new(Socket::AF_INET6)
1217
- socket6.bind(@config[:source_address_inet6].to_s,@config[:source_port])
1213
+ if @config[:nameservers].any? { |ns| ns.ipv6? }
1214
+ socket6 = UDPSocket.new(Socket::AF_INET6)
1215
+ socket6.bind(@config[:source_address_inet6].to_s,@config[:source_port])
1216
+ end
1218
1217
 
1219
1218
  ans = nil
1220
1219
  response = ""