net-dns 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +6 -0
  2. data/AUTHORS.rdoc +7 -0
  3. data/CHANGELOG.rdoc +34 -0
  4. data/README.rdoc +26 -14
  5. data/Rakefile +23 -30
  6. data/{THANKS → THANKS.rdoc} +0 -0
  7. data/VERSION.yml +3 -2
  8. data/demo/check_soa.rb +6 -11
  9. data/lib/net/{dns/dns.rb → dns.rb} +5 -12
  10. data/lib/net/dns/core_ext.rb +52 -0
  11. data/lib/net/dns/header.rb +55 -49
  12. data/lib/net/dns/names/names.rb +20 -10
  13. data/lib/net/dns/packet.rb +33 -26
  14. data/lib/net/dns/question.rb +60 -27
  15. data/lib/net/dns/resolver.rb +101 -156
  16. data/lib/net/dns/resolver/timeouts.rb +71 -65
  17. data/lib/net/dns/rr.rb +131 -166
  18. data/lib/net/dns/rr/a.rb +20 -26
  19. data/lib/net/dns/rr/aaaa.rb +15 -20
  20. data/lib/net/dns/rr/classes.rb +1 -1
  21. data/lib/net/dns/rr/cname.rb +8 -14
  22. data/lib/net/dns/rr/hinfo.rb +8 -14
  23. data/lib/net/dns/rr/mr.rb +8 -14
  24. data/lib/net/dns/rr/mx.rb +11 -18
  25. data/lib/net/dns/rr/ns.rb +8 -14
  26. data/lib/net/dns/rr/null.rb +7 -14
  27. data/lib/net/dns/rr/ptr.rb +9 -15
  28. data/lib/net/dns/rr/soa.rb +9 -15
  29. data/lib/net/dns/rr/srv.rb +10 -19
  30. data/lib/net/dns/rr/txt.rb +9 -20
  31. data/lib/net/dns/rr/types.rb +51 -58
  32. data/lib/net/dns/version.rb +22 -0
  33. data/test/{net/dns/test_header.rb → header_test.rb} +20 -20
  34. data/test/{net/dns/test_packet.rb → packet_test.rb} +2 -2
  35. data/test/question_test.rb +84 -0
  36. data/test/resolver/timeouts_test.rb +109 -0
  37. data/test/{net/dns/test_resolver.rb → resolver_test.rb} +6 -6
  38. data/test/rr/a_test.rb +66 -0
  39. data/test/{net/dns/rr/test_classes.rb → rr/classes_test.rb} +5 -5
  40. data/test/rr/ns_test.rb +64 -0
  41. data/test/rr/types_test.rb +69 -0
  42. data/test/{net/dns/test_rr.rb → rr_test.rb} +10 -12
  43. data/test/test_helper.rb +4 -0
  44. metadata +50 -35
  45. data/AUTHORS +0 -10
  46. data/CHANGELOG +0 -7
  47. data/INSTALL +0 -8
  48. data/net-dns.gemspec +0 -92
  49. data/test/net/dns/resolver/test_timeouts.rb +0 -59
  50. data/test/net/dns/rr/test_a.rb +0 -72
  51. data/test/net/dns/rr/test_ns.rb +0 -66
  52. data/test/net/dns/rr/test_types.rb +0 -124
  53. data/test/net/dns/test_question.rb +0 -54
@@ -1,18 +1,11 @@
1
- ##
2
- #
3
- # Net::DNS::RR::A
4
- #
5
- # $id$
6
- #
7
- ##
8
-
9
1
  require 'ipaddr'
10
2
 
3
+
11
4
  module Net # :nodoc:
12
5
  module DNS
13
6
 
14
7
  class RR
15
-
8
+
16
9
  # =Name
17
10
  #
18
11
  # Net::DNS::RR::A DNS A resource record
@@ -39,8 +32,9 @@ module Net # :nodoc:
39
32
  # without any imbedded spaces (e.g.,"10.2.0.52" or "192.0.5.6").
40
33
  #
41
34
  class A < RR
35
+
42
36
  attr_reader :address
43
-
37
+
44
38
  # Assign to the RR::A object a new IPv4 address, which can be in the
45
39
  # form of a string or an IPAddr object
46
40
  #
@@ -50,7 +44,7 @@ module Net # :nodoc:
50
44
  def address=(addr)
51
45
  @address = check_address addr
52
46
  build_pack
53
- end # address=
47
+ end
54
48
 
55
49
  private
56
50
 
@@ -66,12 +60,12 @@ module Net # :nodoc:
66
60
  when IPAddr
67
61
  address = addr
68
62
  else
69
- raise RRArgumentError, "Unknown address type: #{addr}"
63
+ raise ArgumentError, "Unknown address type `#{addr}'"
70
64
  end
71
- raise RRArgumentError, "Must specify an IPv4 address" unless address.ipv4?
65
+ raise ArgumentError, "Must specify an IPv4 address" unless address.ipv4?
72
66
  address
73
- rescue ArgumentError
74
- raise RRArgumentError, "Invalid address #{addr}"
67
+ rescue ::ArgumentError
68
+ raise ArgumentError, "Invalid address `#{addr}'"
75
69
  end
76
70
 
77
71
  def build_pack
@@ -79,10 +73,6 @@ module Net # :nodoc:
79
73
  @rdlength = @address_pack.size
80
74
  end
81
75
 
82
- def set_type
83
- @type = Net::DNS::RR::Types.new("A")
84
- end
85
-
86
76
  def get_data
87
77
  @address_pack
88
78
  end
@@ -98,7 +88,7 @@ module Net # :nodoc:
98
88
  @address = check_address args[:rdata]
99
89
  else
100
90
  # Address field is mandatory
101
- raise RRArgumentError, ":address field is mandatory but missing"
91
+ raise ArgumentError, ":address field is mandatory but missing"
102
92
  end
103
93
  end
104
94
 
@@ -112,10 +102,14 @@ module Net # :nodoc:
112
102
  return offset + 4
113
103
  end
114
104
 
115
- end # class A
105
+ private
106
+
107
+ def set_type
108
+ @type = Net::DNS::RR::Types.new("A")
109
+ end
110
+
111
+ end
116
112
 
117
- end # class RR
118
- end # module DNS
119
- end # module Net
120
-
121
-
113
+ end
114
+ end
115
+ end
@@ -1,13 +1,6 @@
1
- ##
2
- #
3
- # Net::DNS::RR::AAAA
4
- #
5
- # $id$
6
- #
7
- ##
8
-
9
1
  require 'ipaddr'
10
2
 
3
+
11
4
  module Net
12
5
  module DNS
13
6
 
@@ -40,12 +33,12 @@ module Net
40
33
  when IPAddr
41
34
  address = addr
42
35
  else
43
- raise RRArgumentError, "Unknown address type: #{addr.inspect}"
36
+ raise ArgumentError, "Unknown address type: #{addr.inspect}"
44
37
  end
45
- raise RRArgumentError, "Must specify an IPv6 address" unless address.ipv6?
38
+ raise ArgumentError, "Must specify an IPv6 address" unless address.ipv6?
46
39
  address
47
40
  rescue ArgumentError
48
- raise RRArgumentError, "Invalid address #{addr.inspect}"
41
+ raise ArgumentError, "Invalid address #{addr.inspect}"
49
42
  end
50
43
 
51
44
  def build_pack
@@ -53,10 +46,6 @@ module Net
53
46
  @rdlength = @address_pack.size
54
47
  end
55
48
 
56
- def set_type
57
- @type = Net::DNS::RR::Types.new("AAAA")
58
- end
59
-
60
49
  def get_data
61
50
  @address_pack
62
51
  end
@@ -69,7 +58,7 @@ module Net
69
58
  if args.has_key? :address
70
59
  @address = check_address args[:address]
71
60
  else
72
- raise RRArgumentError, ":address field is mandatory but missing"
61
+ raise ArgumentError, ":address field is mandatory but missing"
73
62
  end
74
63
  end
75
64
 
@@ -83,10 +72,16 @@ module Net
83
72
  return offset + 16
84
73
  end
85
74
 
86
- end # class AAAA
75
+ private
76
+
77
+ def set_type
78
+ @type = Net::DNS::RR::Types.new("AAAA")
79
+ end
80
+
81
+ end
87
82
 
88
- end # class RR
89
- end # module DNS
90
- end # module Net
83
+ end
84
+ end
85
+ end
91
86
 
92
87
 
@@ -61,7 +61,7 @@ module Net # :nodoc:
61
61
  # Gives in output the keys from the +Classes+ hash
62
62
  # in a format suited for regexps
63
63
  def self.regexp
64
- Classes.keys.join("|")
64
+ Classes.keys.sort.join("|")
65
65
  end
66
66
 
67
67
  # Creates a new object representing an RR class. Performs some
@@ -1,11 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::CNAME
4
- #
5
- # $Id: CNAME.rb,v 1.7 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
1
  module Net
10
2
  module DNS
11
3
 
@@ -21,7 +13,7 @@ module Net
21
13
 
22
14
  def check_name(name)
23
15
  unless name =~ /(\w\.?)+\s*$/ and name =~ /[a-zA-Z]/
24
- raise RRArgumentError, "Canonical Name not valid: #{name}"
16
+ raise ArgumentError, "Canonical Name not valid: #{name}"
25
17
  end
26
18
  name
27
19
  end
@@ -31,10 +23,6 @@ module Net
31
23
  @rdlength = @cname_pack.size
32
24
  end
33
25
 
34
- def set_type
35
- @type = Net::DNS::RR::Types.new("CNAME")
36
- end
37
-
38
26
  def get_data
39
27
  @cname_pack
40
28
  end
@@ -47,7 +35,7 @@ module Net
47
35
  if args.has_key? :cname
48
36
  @cname = check_name args[:cname]
49
37
  else
50
- raise RRArgumentError, ":cname field is mandatory but missing"
38
+ raise ArgumentError, ":cname field is mandatory but missing"
51
39
  end
52
40
  end
53
41
 
@@ -60,6 +48,12 @@ module Net
60
48
  return offset
61
49
  end
62
50
 
51
+ private
52
+
53
+ def set_type
54
+ @type = Net::DNS::RR::Types.new("CNAME")
55
+ end
56
+
63
57
  end # class CNAME
64
58
 
65
59
  end # class RR
@@ -1,11 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::HINFO
4
- #
5
- # $Id: HINFO.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
1
  module Net
10
2
  module DNS
11
3
  class RR
@@ -22,7 +14,7 @@ module Net
22
14
  if str.strip =~ /^["'](.*?)["']\s+["'](.*?)["']$/
23
15
  return $1,$2
24
16
  else
25
- raise RRArgumentError, "HINFO section not valid: #{str.inspect}"
17
+ raise ArgumentError, "HINFO section not valid: #{str.inspect}"
26
18
  end
27
19
  end
28
20
 
@@ -32,10 +24,6 @@ module Net
32
24
  @rdlength = @hinfo_pack.size
33
25
  end
34
26
 
35
- def set_type
36
- @type = Net::DNS::RR::Types.new("HINFO")
37
- end
38
-
39
27
  def get_data
40
28
  @hinfo_pack
41
29
  end
@@ -49,7 +37,7 @@ module Net
49
37
  @cpu = args[:cpu]
50
38
  @os = args[:os]
51
39
  else
52
- raise RRArgumentError, ":cpu and :os fields are mandatory but missing"
40
+ raise ArgumentError, ":cpu and :os fields are mandatory but missing"
53
41
  end
54
42
  end
55
43
 
@@ -66,6 +54,12 @@ module Net
66
54
  return offset += len+1
67
55
  end
68
56
 
57
+ private
58
+
59
+ def set_type
60
+ @type = Net::DNS::RR::Types.new("HINFO")
61
+ end
62
+
69
63
  end # class HINFO
70
64
 
71
65
  end # class RR
@@ -1,11 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::MR
4
- #
5
- # $Id: MR.rb,v 1.4 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
1
  module Net
10
2
  module DNS
11
3
 
@@ -21,7 +13,7 @@ module Net
21
13
 
22
14
  def check_name(name)
23
15
  unless name =~ /(\w\.?)+\s*$/
24
- raise RRArgumentError, "Name not valid: #{name.inspect}"
16
+ raise ArgumentError, "Name not valid: #{name.inspect}"
25
17
  end
26
18
  name
27
19
  end
@@ -31,10 +23,6 @@ module Net
31
23
  @rdlength = @newname_pack.size
32
24
  end
33
25
 
34
- def set_type
35
- @type = Net::DNS::RR::Types.new("MR")
36
- end
37
-
38
26
  def get_data
39
27
  @newname_pack
40
28
  end
@@ -47,7 +35,7 @@ module Net
47
35
  if args.has_key? :newname
48
36
  @newname = check_name args[:newname]
49
37
  else
50
- raise RRArgumentError, ":newname field is mandatory but missing"
38
+ raise ArgumentError, ":newname field is mandatory but missing"
51
39
  end
52
40
  end
53
41
 
@@ -60,6 +48,12 @@ module Net
60
48
  return offset
61
49
  end
62
50
 
51
+ private
52
+
53
+ def set_type
54
+ @type = Net::DNS::RR::Types.new("MR")
55
+ end
56
+
63
57
  end # class MR
64
58
 
65
59
  end # class RR
@@ -1,12 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::MX
4
- #
5
- # $Id: MX.rb,v 1.8 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
-
10
1
  module Net
11
2
  module DNS
12
3
  class RR
@@ -23,7 +14,7 @@ module Net
23
14
  if str.strip =~ /^(\d+)\s+(\S+)$/
24
15
  return $1.to_i,$2
25
16
  else
26
- raise RRArgumentError, "MX section not valid"
17
+ raise ArgumentError, "MX section not valid"
27
18
  end
28
19
  end
29
20
 
@@ -32,10 +23,6 @@ module Net
32
23
  @rdlength = @mx_pack.size
33
24
  end
34
25
 
35
- def set_type
36
- @type = Net::DNS::RR::Types.new("MX")
37
- end
38
-
39
26
  def get_data
40
27
  @mx_pack
41
28
  end
@@ -46,10 +33,10 @@ module Net
46
33
 
47
34
  def subclass_new_from_hash(args)
48
35
  if args.has_key? :preference and args.has_key? :exchange
49
- @preference = args[0][:preference].to_i
50
- @exchange = args[0][:exchange]
36
+ @preference = args[:preference].to_i
37
+ @exchange = args[:exchange]
51
38
  else
52
- raise RRArgumentError, ":preference and :exchange fields are mandatory but missing"
39
+ raise ArgumentError, ":preference and :exchange fields are mandatory but missing"
53
40
  end
54
41
  end
55
42
 
@@ -63,7 +50,13 @@ module Net
63
50
  @exchange,offset = dn_expand(data,offset)
64
51
  return offset
65
52
  end
66
-
53
+
54
+ private
55
+
56
+ def set_type
57
+ @type = Net::DNS::RR::Types.new("MX")
58
+ end
59
+
67
60
  end # class MX
68
61
 
69
62
  end # class RR
@@ -1,11 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::NS
4
- #
5
- # $Id: NS.rb,v 1.8 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
1
  module Net
10
2
  module DNS
11
3
 
@@ -21,7 +13,7 @@ module Net
21
13
 
22
14
  def check_name(name)
23
15
  unless name =~ /(\w\.?)+\s*$/ and name =~ /[a-zA-Z]/
24
- raise RRArgumentError, "NS Domain Name not valid: #{name}"
16
+ raise ArgumentError, "NS Domain Name not valid: #{name}"
25
17
  end
26
18
  name
27
19
  end
@@ -31,10 +23,6 @@ module Net
31
23
  @rdlength = @nsdname_pack.size
32
24
  end
33
25
 
34
- def set_type
35
- @type = Net::DNS::RR::Types.new("NS")
36
- end
37
-
38
26
  def get_data
39
27
  @nsdname_pack
40
28
  end
@@ -47,7 +35,7 @@ module Net
47
35
  if args.has_key? :nsdname
48
36
  @nsdname = check_name args[:nsdname]
49
37
  else
50
- raise RRArgumentError, ":nsdname field is mandatory but missing"
38
+ raise ArgumentError, ":nsdname field is mandatory but missing"
51
39
  end
52
40
  end
53
41
 
@@ -60,6 +48,12 @@ module Net
60
48
  return offset
61
49
  end
62
50
 
51
+ private
52
+
53
+ def set_type
54
+ @type = Net::DNS::RR::Types.new("NS")
55
+ end
56
+
63
57
  end # class NS
64
58
 
65
59
  end # class RR
@@ -1,12 +1,3 @@
1
- ##
2
- #
3
- # Net::DNS::RR::NULL
4
- #
5
- # $Id: NULL.rb,v 1.5 2006/07/28 07:33:36 bluemonk Exp $
6
- #
7
- ##
8
-
9
-
10
1
  module Net
11
2
  module DNS
12
3
  class RR
@@ -24,10 +15,6 @@ module Net
24
15
  @rdlength = @null_pack.size
25
16
  end
26
17
 
27
- def set_type
28
- @type = Net::DNS::RR::RRTypes.new("NULL")
29
- end
30
-
31
18
  def get_data
32
19
  @null_pack
33
20
  end
@@ -40,7 +27,7 @@ module Net
40
27
  if args.has_key? :null
41
28
  @null = args[:null]
42
29
  else
43
- raise RRArgumentError, ":null field is mandatory but missing"
30
+ raise ArgumentError, ":null field is mandatory but missing"
44
31
  end
45
32
  end
46
33
 
@@ -53,6 +40,12 @@ module Net
53
40
  return offset + @rdlength
54
41
  end
55
42
 
43
+ private
44
+
45
+ def set_type
46
+ @type = Net::DNS::RR::Types.new("NULL")
47
+ end
48
+
56
49
  end # class NULL
57
50
 
58
51
  end # class RR