net-dns 0.9.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -16
  3. data/README.md +1 -1
  4. data/lib/net/dns/header.rb +48 -64
  5. data/lib/net/dns/names.rb +8 -10
  6. data/lib/net/dns/packet.rb +46 -53
  7. data/lib/net/dns/question.rb +5 -3
  8. data/lib/net/dns/resolver/socks.rb +5 -7
  9. data/lib/net/dns/resolver/timeouts.rb +3 -5
  10. data/lib/net/dns/resolver.rb +54 -69
  11. data/lib/net/dns/rr/a.rb +3 -4
  12. data/lib/net/dns/rr/aaaa.rb +3 -5
  13. data/lib/net/dns/rr/classes.rb +6 -8
  14. data/lib/net/dns/rr/cname.rb +3 -5
  15. data/lib/net/dns/rr/hinfo.rb +9 -13
  16. data/lib/net/dns/rr/mr.rb +3 -5
  17. data/lib/net/dns/rr/mx.rb +5 -7
  18. data/lib/net/dns/rr/ns.rb +3 -5
  19. data/lib/net/dns/rr/null.rb +3 -5
  20. data/lib/net/dns/rr/ptr.rb +3 -5
  21. data/lib/net/dns/rr/soa.rb +11 -7
  22. data/lib/net/dns/rr/srv.rb +5 -2
  23. data/lib/net/dns/rr/txt.rb +4 -6
  24. data/lib/net/dns/rr/types.rb +90 -79
  25. data/lib/net/dns/rr.rb +2 -2
  26. data/lib/net/dns/version.rb +1 -1
  27. data/lib/net/dns.rb +3 -1
  28. metadata +11 -104
  29. data/.gitignore +0 -8
  30. data/.rubocop.yml +0 -3
  31. data/.rubocop_defaults.yml +0 -364
  32. data/.rubocop_todo.yml +0 -207
  33. data/Gemfile +0 -8
  34. data/Rakefile +0 -38
  35. data/bin/console +0 -14
  36. data/lib/net/dns/core_ext.rb +0 -45
  37. data/net-dns.gemspec +0 -23
  38. data/spec/fixtures/resolv.conf +0 -4
  39. data/spec/spec_helper.rb +0 -14
  40. data/spec/unit/resolver/dns_timeout_spec.rb +0 -36
  41. data/spec/unit/resolver/tcp_timeout_spec.rb +0 -46
  42. data/spec/unit/resolver/udp_timeout_spec.rb +0 -46
  43. data/test/test_helper.rb +0 -13
  44. data/test/unit/header_test.rb +0 -164
  45. data/test/unit/names_test.rb +0 -21
  46. data/test/unit/packet_test.rb +0 -47
  47. data/test/unit/question_test.rb +0 -81
  48. data/test/unit/resolver_test.rb +0 -114
  49. data/test/unit/rr/a_test.rb +0 -106
  50. data/test/unit/rr/aaaa_test.rb +0 -102
  51. data/test/unit/rr/classes_test.rb +0 -83
  52. data/test/unit/rr/cname_test.rb +0 -90
  53. data/test/unit/rr/hinfo_test.rb +0 -111
  54. data/test/unit/rr/mr_test.rb +0 -99
  55. data/test/unit/rr/mx_test.rb +0 -106
  56. data/test/unit/rr/ns_test.rb +0 -80
  57. data/test/unit/rr/types_test.rb +0 -71
  58. data/test/unit/rr_test.rb +0 -127
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dc42ad67563fd2c8dff75111f86d918da967e98b0beb1be2797b5a718081a65
4
- data.tar.gz: 7dcdef18fe96bde06059de4953787a4f80f352dd49f4d75d1358e44c286477b5
3
+ metadata.gz: fec69b4a6e824defa6fb7a25a020a67d0dba5340f2f42b1c489e3b73027b6577
4
+ data.tar.gz: bd9fcd575cb009fa14ce0443ea3b415f0924a04c3a63be620b350c913b93fe39
5
5
  SHA512:
6
- metadata.gz: 29ec0713726b0a5b8ff79e3bedc35dbb9ace5f6e98c4b77e5ceaaf814b1220028ef879e426468e5189364ffc028c2d938f2639420f398701656eb2a562f6cf7b
7
- data.tar.gz: a515331bf54ce6c5d2d5971979d333043f02b569d4343f3883b99af92c162669eea0aa1287307573c1455a4f257d970a86bf6c0c717a068b8213879190a63460
6
+ metadata.gz: 3ba5ecc052ddd89bfc5bb264ce0a11edb2aa791b1d6285075f0f96245634b1b73bb69e29e883bd4656a85d6c82e6f331e11cfb66b55a10da27b90221ad61f8d6
7
+ data.tar.gz: 0ff1b210ef56b91a7dc3d914039bedb7e08803c8838a0eefe1233fef4c97a7e817b06387e45bc6b77354a3efe7f9fc885499efff0aabacb07ac24c3eb75aca15
data/CHANGELOG.md CHANGED
@@ -1,33 +1,46 @@
1
1
  # Changelog
2
2
 
3
3
 
4
- ## Release 0.9.0
4
+ ## Release 0.20.0
5
5
 
6
- - FIXED: Fixed CI run (GH-77).
6
+ - CHANGED: Minimum Ruby version is now 2.7
7
+
8
+ - CHANGED: Merged changes from gitlab-net-dns @stanhu
9
+
10
+ - FIXED: Fixed undefined method 'size' errors (GH-46, GH-81) @stanhu
11
+
12
+ - FIXED: uninitialized constant Net::DNS::Resolver::TimeoutError (GH-82, GH-83, GH-84)
13
+
14
+ - ADDED: Added URI/SPF/CAA type code
7
15
 
8
- - FIXED: Fixed deprecated references to Fixnum.
16
+
17
+ ## Release 0.9.0
9
18
 
10
19
  - CHANGED: Major code cleanup.
11
20
 
12
21
  - CHANGED: Minimum Ruby version is now 2.1
13
22
 
23
+ - FIXED: Fixed CI run (GH-77).
24
+
25
+ - FIXED: Fixed deprecated references to Fixnum.
14
26
 
15
- ## Release 0.8.0
16
27
 
17
- - FIXED: undefined local variable or method `source_address_inet6' (GH-40). [Thanks @simsicon]
28
+ ## Release 0.8.0
18
29
 
19
- - FIXED: Fixed bug on parsing multiple nameservers on different lines (GH-45). [Thanks @nicholasren]
30
+ - FIXED: undefined local variable or method `source_address_inet6' (GH-40). @simsicon
20
31
 
21
- - CHANGED: Dropped duplicate query ID filter. Query ID is now randomically generated but it's not guaranteed to be unique (GH-39). [Thanks @ebroder]
32
+ - FIXED: Fixed bug on parsing multiple nameservers on different lines (GH-45). @nicholasren
33
+
34
+ - CHANGED: Dropped duplicate query ID filter. Query ID is now randomically generated but it's not guaranteed to be unique (GH-39). @ebroder
22
35
 
23
- - CHANGED: require 'net/dns' is now the preferred way to load the library (GH-37). [Thanks @johnroa]
36
+ - CHANGED: require 'net/dns' is now the preferred way to load the library (GH-37). @johnroa
24
37
 
25
38
  - CHANGED: Removed setup.rb installation script.
26
39
 
27
40
 
28
41
  ## Release 0.7.1
29
42
 
30
- - FIXED: Invalid file permissions on several files (GH-35) [Thanks @jamespharaoh]
43
+ - FIXED: Invalid file permissions on several files (GH-35) @jamespharaoh
31
44
 
32
45
 
33
46
  ## Release 0.7.0
@@ -38,15 +51,15 @@
38
51
 
39
52
  - FIXED: Cleaned up require dependency and recursive require statements.
40
53
 
41
- - FIXED: Use RbConfig instead of obsolete and deprecated Config (GH-28, GH-33) [Thanks @shadowbq, @eik3]
54
+ - FIXED: Use RbConfig instead of obsolete and deprecated Config (GH-28, GH-33) @shadowbq, @eik3
42
55
 
43
- - FIXED: SRV record not required by Net::DNS::RR (GH-27) [Thanks @sebastian]
56
+ - FIXED: SRV record not required by Net::DNS::RR (GH-27) @sebastian
44
57
 
45
- - FIXED: Resolver now supports IPv6 (GH-32) [Thanks @jamesotron]
58
+ - FIXED: Resolver now supports IPv6 (GH-32) @jamesotron
46
59
 
47
- - FIXED: Net::DNS::RR::PTR references an invalid parameter (GH-19) [Thanks @dd23]
60
+ - FIXED: Net::DNS::RR::PTR references an invalid parameter (GH-19) @dd23
48
61
 
49
- - FIXED: Net::DNS::Question changes input arguments (GH-7) [Thanks @gfarfl]
62
+ - FIXED: Net::DNS::Question changes input arguments (GH-7) @gfarfl
50
63
 
51
64
  - CHANGED: Refactoring unit test to follow most used Ruby conventions.
52
65
 
@@ -67,9 +80,9 @@
67
80
 
68
81
  - ADDED: Net::DNS::Packet#to_s method (alias of #inspect)
69
82
 
70
- - FIXED: typo in lib/net/dns/rr/ptr.rb [Thanks Chris Lundquist]
83
+ - FIXED: typo in lib/net/dns/rr/ptr.rb. Thanks Chris Lundquist.
71
84
 
72
- - FIXED: warning: method redefined; discarding old inspect (GH-3) [Thanks Kevin Baker]
85
+ - FIXED: warning: method redefined; discarding old inspect (GH-3). Thanks Kevin Baker.
73
86
 
74
87
  - FIXED: issue with rescue ArgumentError (GH-5) and with IPAddr handling (GH-6)
75
88
 
data/README.md CHANGED
@@ -12,7 +12,7 @@ Net::DNS is a DNS library written in pure Ruby. It started as a port of Perl Net
12
12
 
13
13
  ## Requirements
14
14
 
15
- Ruby >= 2.1
15
+ Ruby >= 2.6
16
16
 
17
17
 
18
18
  ## Installation
@@ -128,16 +128,16 @@ module Net
128
128
  "",
129
129
  "",].freeze
130
130
 
131
- attr_reader :code, :type, :explanation
131
+ attr_reader :code
132
+ attr_reader :type
133
+ attr_reader :explanation
132
134
 
133
135
  def initialize(code)
134
- if (0..10).cover? code
135
- @code = code
136
- @type = RCodeType[code]
137
- @explanation = RCodeErrorString[code]
138
- else
139
- raise ArgumentError, "RCode `#{code}' out of range"
140
- end
136
+ raise ArgumentError, "RCode `#{code}' out of range" unless (0..10).cover? code
137
+
138
+ @code = code
139
+ @type = RCodeType[code]
140
+ @explanation = RCodeErrorString[code]
141
141
  end
142
142
 
143
143
  def to_s
@@ -205,11 +205,9 @@ module Net
205
205
  # See also each option for a detailed explanation of usage.
206
206
  #
207
207
  def initialize(arg = {})
208
- if arg.is_a? Hash
209
- new_from_hash(arg)
210
- else
211
- raise ArgumentError, "Wrong argument class `#{arg.class}'"
212
- end
208
+ raise ArgumentError, "Wrong argument class `#{arg.class}'" unless arg.is_a? Hash
209
+
210
+ new_from_hash(arg)
213
211
  end
214
212
 
215
213
  # Creates a new Net::DNS::Header object from binary data, which is
@@ -225,13 +223,11 @@ module Net
225
223
  # #=> "true" if it comes from authoritative name server
226
224
  #
227
225
  def self.parse(arg)
228
- if arg.is_a? String
229
- o = allocate
230
- o.send(:new_from_binary, arg)
231
- o
232
- else
233
- raise ArgumentError, "Wrong argument class `#{arg.class}'"
234
- end
226
+ raise ArgumentError, "Wrong argument class `#{arg.class}'" unless arg.is_a? String
227
+
228
+ o = allocate
229
+ o.send(:new_from_binary, arg)
230
+ o
235
231
  end
236
232
 
237
233
  # Inspect method, prints out all the options and relative values.
@@ -251,18 +247,18 @@ module Net
251
247
  # do stuff
252
248
  else
253
249
  ";; qr = #{@qr}\t" \
254
- "opCode: #{opCode_str}\t" \
255
- "aa = #{@aa}\t" \
256
- "tc = #{@tc}\t" \
257
- "rd = #{@rd}\n" \
258
- ";; ra = #{@ra}\t" \
259
- "ad = #{@ad}\t" \
260
- "cd = #{@cd}\t" \
261
- "rcode = #{@rCode.type}\n" \
262
- ";; qdCount = #{@qdCount}\t" \
263
- "anCount = #{@anCount}\t" \
264
- "nsCount = #{@nsCount}\t" \
265
- "arCount = #{@arCount}\n"
250
+ "opCode: #{opCode_str}\t" \
251
+ "aa = #{@aa}\t" \
252
+ "tc = #{@tc}\t" \
253
+ "rd = #{@rd}\n" \
254
+ ";; ra = #{@ra}\t" \
255
+ "ad = #{@ad}\t" \
256
+ "cd = #{@cd}\t" \
257
+ "rcode = #{@rCode.type}\n" \
258
+ ";; qdCount = #{@qdCount}\t" \
259
+ "anCount = #{@anCount}\t" \
260
+ "nsCount = #{@nsCount}\t" \
261
+ "arCount = #{@arCount}\n"
266
262
  end
267
263
  end
268
264
 
@@ -329,11 +325,9 @@ module Net
329
325
  # performing security tests.
330
326
  #
331
327
  def id=(val)
332
- if (0..65_535).cover? val
333
- @id = val
334
- else
335
- raise ArgumentError, "ID `#{val}' out of range"
336
- end
328
+ raise ArgumentError, "ID `#{val}' out of range" unless (0..65_535).cover? val
329
+
330
+ @id = val
337
331
  end
338
332
 
339
333
  # Checks whether the header is a query (+qr+ bit set to 0)
@@ -392,11 +386,9 @@ module Net
392
386
  # header.opCode = Header::STATUS
393
387
  #
394
388
  def opCode=(val)
395
- if (0..2).cover? val
396
- @opCode = val
397
- else
398
- raise WrongOpcodeError, "Wrong opCode value (#{val}), must be QUERY, IQUERY or STATUS"
399
- end
389
+ raise WrongOpcodeError, "Wrong opCode value (#{val}), must be QUERY, IQUERY or STATUS" unless (0..2).cover? val
390
+
391
+ @opCode = val
400
392
  end
401
393
 
402
394
  # Checks whether the response is authoritative
@@ -620,41 +612,33 @@ module Net
620
612
  # Sets the number of entries in a question section
621
613
  #
622
614
  def qdCount=(val)
623
- if (0..65_535).cover? val
624
- @qdCount = val
625
- else
626
- raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535"
627
- end
615
+ raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535" unless (0..65_535).cover? val
616
+
617
+ @qdCount = val
628
618
  end
629
619
 
630
620
  # Sets the number of RRs in an answer section
631
621
  #
632
622
  def anCount=(val)
633
- if (0..65_535).cover? val
634
- @anCount = val
635
- else
636
- raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535"
637
- end
623
+ raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535" unless (0..65_535).cover? val
624
+
625
+ @anCount = val
638
626
  end
639
627
 
640
628
  # Sets the number of RRs in an authority section
641
629
  #
642
630
  def nsCount=(val)
643
- if (0..65_535).cover? val
644
- @nsCount = val
645
- else
646
- raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535"
647
- end
631
+ raise WrongCountError, "Wrong number of count (#{val}), must be 0-65535" unless (0..65_535).cover? val
632
+
633
+ @nsCount = val
648
634
  end
649
635
 
650
636
  # Sets the number of RRs in an addictional section
651
637
  #
652
638
  def arCount=(val)
653
- if (0..65_535).cover? val
654
- @arCount = val
655
- else
656
- raise WrongCountError, "Wrong number of count: `#{val}' must be 0-65535"
657
- end
639
+ raise WrongCountError, "Wrong number of count: `#{val}' must be 0-65535" unless (0..65_535).cover? val
640
+
641
+ @arCount = val
658
642
  end
659
643
 
660
644
  private
@@ -674,12 +658,12 @@ module Net
674
658
  end
675
659
 
676
660
  arr = str.unpack("n C2 n4")
677
- @id = arr[0]
661
+ @id = arr[0]
678
662
  @qr = (arr[1] >> 7) & 0x01
679
663
  @opCode = (arr[1] >> 3) & 0x0F
680
664
  @aa = (arr[1] >> 2) & 0x01
681
665
  @tc = (arr[1] >> 1) & 0x01
682
- @rd = arr[1] & 0x1
666
+ @rd = arr[1] & 0x1
683
667
  @ra = (arr[2] >> 7) & 0x01
684
668
  @ad = (arr[2] >> 5) & 0x01
685
669
  @cd = (arr[2] >> 4) & 0x01
data/lib/net/dns/names.rb CHANGED
@@ -12,7 +12,7 @@ module Net # :nodoc:
12
12
  INT16SZ = 2
13
13
 
14
14
  # Expand a compressed name in a DNS Packet object. Please
15
- # see RFC1025 for an explanation of how the compression
15
+ # see RFC1035 for an explanation of how the compression
16
16
  # in DNS packets works, how may it be useful and how should
17
17
  # be handled.
18
18
  #
@@ -24,9 +24,9 @@ module Net # :nodoc:
24
24
  name = ""
25
25
  packetlen = packet.size
26
26
  loop do
27
- raise ExpandError, "Offset is greater than packet lenght!" if packetlen < (offset + 1)
27
+ raise ExpandError, "Offset is greater than packet length!" if packetlen < (offset + 1)
28
28
 
29
- len = packet.unpack("@#{offset} C")[0]
29
+ len = packet.unpack1("@#{offset} C")
30
30
 
31
31
  if len == 0
32
32
  offset += 1
@@ -34,7 +34,7 @@ module Net # :nodoc:
34
34
  elsif (len & 0xC0) == 0xC0
35
35
  raise ExpandError, "Packet ended before offset expand" if packetlen < (offset + INT16SZ)
36
36
 
37
- ptr = packet.unpack("@#{offset} n")[0]
37
+ ptr = packet.unpack1("@#{offset} n")
38
38
  ptr &= 0x3FFF
39
39
  name2 = dn_expand(packet, ptr)[0]
40
40
  raise ExpandError, "Packet is malformed!" if name2.nil?
@@ -98,7 +98,7 @@ module Net # :nodoc:
98
98
  offset += INT16SZ
99
99
  break
100
100
  else
101
- len = entry.unpack("C")[0]
101
+ len = entry.unpack1("C")
102
102
  elem = entry[1..len]
103
103
  str += [len, elem].pack("Ca*")
104
104
  names.update(entry.to_s => offset)
@@ -109,11 +109,9 @@ module Net # :nodoc:
109
109
  end
110
110
 
111
111
  def valid?(name)
112
- 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
113
- name
114
- else
115
- raise ArgumentError, "Invalid FQDN: #{name}"
116
- end
112
+ raise ArgumentError, "Invalid FQDN: #{name}" unless 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
113
+
114
+ name
117
115
  end
118
116
  end
119
117
  end
@@ -90,8 +90,13 @@ module Net
90
90
  class PacketError < Error
91
91
  end
92
92
 
93
- attr_reader :header, :question, :answer, :authority, :additional
94
- attr_reader :answerfrom, :answersize
93
+ attr_reader :header
94
+ attr_reader :question
95
+ attr_reader :answer
96
+ attr_reader :authority
97
+ attr_reader :additional
98
+ attr_reader :answerfrom
99
+ attr_reader :answersize
95
100
 
96
101
  # Creates a new instance of <tt>Net::DNS::Packet</tt> class. Arguments are the
97
102
  # canonical name of the resource, an optional type field and an optional
@@ -261,11 +266,9 @@ module Net
261
266
  # Assigns a <tt>Net::DNS::Header</tt> <tt>object</tt>
262
267
  # to this <tt>Net::DNS::Packet</tt> instance.
263
268
  def header=(object)
264
- if object.is_a? Net::DNS::Header
265
- @header = object
266
- else
267
- raise ArgumentError, "Argument must be a Net::DNS::Header object"
268
- end
269
+ raise ArgumentError, "Argument must be a Net::DNS::Header object" unless object.is_a? Net::DNS::Header
270
+
271
+ @header = object
269
272
  end
270
273
 
271
274
  # Assigns a <tt>Net::DNS::Question</tt> <tt>object</tt>
@@ -273,11 +276,10 @@ module Net
273
276
  def question=(object)
274
277
  case object
275
278
  when Array
276
- if object.all? { |x| x.is_a? Net::DNS::Question }
277
- @question = object
278
- else
279
- raise ArgumentError, "Some of the elements is not an Net::DNS::Question object"
280
- end
279
+ raise ArgumentError, "Some of the elements is not an Net::DNS::Question object" unless object.all? { |x| x.is_a? Net::DNS::Question }
280
+
281
+ @question = object
282
+
281
283
  when Net::DNS::Question
282
284
  @question = [object]
283
285
  else
@@ -290,11 +292,10 @@ module Net
290
292
  def answer=(object)
291
293
  case object
292
294
  when Array
293
- if object.all? { |x| x.is_a? Net::DNS::RR }
294
- @answer = object
295
- else
296
- raise ArgumentError, "Some of the elements is not an Net::DNS::RR object"
297
- end
295
+ raise ArgumentError, "Some of the elements is not an Net::DNS::RR object" unless object.all? { |x| x.is_a? Net::DNS::RR }
296
+
297
+ @answer = object
298
+
298
299
  when Net::DNS::RR
299
300
  @answer = [object]
300
301
  else
@@ -307,11 +308,10 @@ module Net
307
308
  def additional=(object)
308
309
  case object
309
310
  when Array
310
- if object.all? { |x| x.is_a? Net::DNS::RR }
311
- @additional = object
312
- else
313
- raise ArgumentError, "Some of the elements is not an Net::DNS::RR object"
314
- end
311
+ raise ArgumentError, "Some of the elements is not an Net::DNS::RR object" unless object.all? { |x| x.is_a? Net::DNS::RR }
312
+
313
+ @additional = object
314
+
315
315
  when Net::DNS::RR
316
316
  @additional = [object]
317
317
  else
@@ -324,11 +324,10 @@ module Net
324
324
  def authority=(object)
325
325
  case object
326
326
  when Array
327
- if object.all? { |x| x.is_a? Net::DNS::RR }
328
- @authority = object
329
- else
330
- raise ArgumentError, "Some of the elements is not an Net::DNS::RR object"
331
- end
327
+ raise ArgumentError, "Some of the elements is not an Net::DNS::RR object" unless object.all? { |x| x.is_a? Net::DNS::RR }
328
+
329
+ @authority = object
330
+
332
331
  when Net::DNS::RR
333
332
  @authority = [object]
334
333
  else
@@ -345,7 +344,7 @@ module Net
345
344
  #
346
345
  # As you can see in the documentation for the <tt>Net::DNS::RR::A</tt> class,
347
346
  # the address returned is an instance of <tt>IPAddr</tt> class.
348
- def each_address(&block)
347
+ def each_address
349
348
  @answer.each do |elem|
350
349
  next unless elem.class == Net::DNS::RR::A
351
350
 
@@ -360,7 +359,7 @@ module Net
360
359
  # puts "Nameserver found: #{ns}"
361
360
  # end
362
361
  #
363
- def each_nameserver(&block)
362
+ def each_nameserver
364
363
  @answer.each do |elem|
365
364
  next unless elem.class == Net::DNS::RR::NS
366
365
 
@@ -375,7 +374,7 @@ module Net
375
374
  # puts "Mail exchange #{name} has preference #{pref}"
376
375
  # end
377
376
  #
378
- def each_mx(&block)
377
+ def each_mx
379
378
  @answer.each do |elem|
380
379
  next unless elem.class == Net::DNS::RR::MX
381
380
 
@@ -390,7 +389,7 @@ module Net
390
389
  # puts "Canonical name: #{cname}"
391
390
  # end
392
391
  #
393
- def each_cname(&block)
392
+ def each_cname
394
393
  @answer.each do |elem|
395
394
  next unless elem.class == Net::DNS::RR::CNAME
396
395
 
@@ -405,7 +404,7 @@ module Net
405
404
  # puts "Pointer for resource: #{ptr}"
406
405
  # end
407
406
  #
408
- def each_ptr(&block)
407
+ def each_ptr
409
408
  @answer.each do |elem|
410
409
  next unless elem.class == Net::DNS::RR::PTR
411
410
 
@@ -505,13 +504,11 @@ module Net
505
504
 
506
505
  @answer = []
507
506
  @header.anCount.times do
508
- begin
509
- rrobj, offset = Net::DNS::RR.parse_packet(data, offset)
510
- @answer << rrobj
511
- @logger.debug rrobj.inspect
512
- rescue NameError => e
513
- warn "Net::DNS unsupported record type: #{e.message}"
514
- end
507
+ rrobj, offset = Net::DNS::RR.parse_packet(data, offset)
508
+ @answer << rrobj
509
+ @logger.debug rrobj.inspect
510
+ rescue NameError => e
511
+ warn "Net::DNS unsupported record type: #{e.message}"
515
512
  end
516
513
 
517
514
  #------------------------------------------------------------
@@ -522,13 +519,11 @@ module Net
522
519
 
523
520
  @authority = []
524
521
  @header.nsCount.times do
525
- begin
526
- rrobj, offset = Net::DNS::RR.parse_packet(data, offset)
527
- @authority << rrobj
528
- @logger.debug rrobj.inspect
529
- rescue NameError => e
530
- warn "Net::DNS unsupported record type: #{e.message}"
531
- end
522
+ rrobj, offset = Net::DNS::RR.parse_packet(data, offset)
523
+ @authority << rrobj
524
+ @logger.debug rrobj.inspect
525
+ rescue NameError => e
526
+ warn "Net::DNS unsupported record type: #{e.message}"
532
527
  end
533
528
 
534
529
  #------------------------------------------------------------
@@ -538,13 +533,11 @@ module Net
538
533
 
539
534
  @additional = []
540
535
  @header.arCount.times do
541
- begin
542
- rrobj, offset = Net::DNS::RR.parse_packet(data, offset)
543
- @additional << rrobj
544
- @logger.debug rrobj.inspect
545
- rescue NameError => e
546
- warn "Net::DNS unsupported record type: #{e.message}"
547
- end
536
+ rrobj, offset = Net::DNS::RR.parse_packet(data, offset)
537
+ @additional << rrobj
538
+ @logger.debug rrobj.inspect
539
+ rescue NameError => e
540
+ warn "Net::DNS unsupported record type: #{e.message}"
548
541
  end
549
542
  end
550
543
 
@@ -152,7 +152,7 @@ module Net
152
152
  result = ""
153
153
  offset = 0
154
154
  loop do
155
- len = str.unpack("@#{offset} C")[0]
155
+ len = str.unpack1("@#{offset} C")
156
156
  break if len == 0
157
157
 
158
158
  offset += 1
@@ -165,7 +165,7 @@ module Net
165
165
 
166
166
  def check_name(input)
167
167
  name = input.to_s.strip
168
- if name =~ /[^\w\.\-_]/
168
+ if name =~ /[^\w\.\-_\*]/
169
169
  raise NameInvalid, "Invalid Question Name `#{name}'"
170
170
  end
171
171
 
@@ -173,11 +173,13 @@ module Net
173
173
  end
174
174
 
175
175
  def new_from_binary(data)
176
+ raise NameInvalid if data.size <= 4
177
+
176
178
  str, type, cls = data.unpack("a#{data.size - 4}nn")
177
179
  @qName = build_qName(str)
178
180
  @qType = Net::DNS::RR::Types.new type
179
181
  @qClass = Net::DNS::RR::Classes.new cls
180
- rescue StandardError => e
182
+ rescue StandardError
181
183
  raise ArgumentError, "Invalid data: #{data.inspect}"
182
184
  end
183
185
  end
@@ -50,7 +50,7 @@ class RawSocket # :nodoc:
50
50
  [@protocol, 'C'], # protocol
51
51
  [0, 'n'], # checksum
52
52
  [@src_addr.to_i, 'N'], # source
53
- [@dest_addr.to_i, 'N'], # destination
53
+ [@dest_addr.to_i, 'N'], # destination
54
54
  ])
55
55
  packet << make_transport_header(payload.size)
56
56
  packet << [payload].pack("a*")
@@ -71,11 +71,9 @@ class RawSocket # :nodoc:
71
71
  end
72
72
 
73
73
  def check_port(port)
74
- if (1..65_535).cover?(port) && port.is_a?(Integer)
75
- port
76
- else
77
- raise ArgumentError, "Port #{port} not valid"
78
- end
74
+ raise ArgumentError, "Port #{port} not valid" unless (1..65_535).cover?(port) && port.is_a?(Integer)
75
+
76
+ port
79
77
  end
80
78
 
81
79
  def genID
@@ -142,7 +140,7 @@ class UdpRawSocket < RawSocket # :nodoc:
142
140
  [@src_port, 'n'], # source port
143
141
  [@dest_port, 'n'], # destination port
144
142
  [8 + pay_size, 'n'], # len
145
- [0, 'n'] # checksum (mandatory)
143
+ [0, 'n'], # checksum (mandatory)
146
144
  ])
147
145
  end
148
146
  end
@@ -7,11 +7,9 @@ module Net # :nodoc:
7
7
  attr_reader :seconds
8
8
 
9
9
  def initialize(seconds)
10
- if seconds.is_a?(Numeric) && seconds >= 0
11
- @seconds = seconds
12
- else
13
- raise ArgumentError, "Invalid value for tcp timeout"
14
- end
10
+ raise ArgumentError, "Invalid value for tcp timeout" unless seconds.is_a?(Numeric) && seconds >= 0
11
+
12
+ @seconds = seconds
15
13
  end
16
14
 
17
15
  # Returns a string representation of the timeout corresponding