net-dns 0.8.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +6 -14
  2. data/.rspec +1 -0
  3. data/.travis.yml +9 -16
  4. data/CHANGELOG.md +37 -13
  5. data/LICENSE.txt +56 -0
  6. data/README.md +94 -77
  7. data/demo/check_soa.rb +27 -38
  8. data/demo/threads.rb +3 -7
  9. data/lib/net/dns/header.rb +86 -110
  10. data/lib/net/dns/names.rb +31 -31
  11. data/lib/net/dns/packet.rb +148 -158
  12. data/lib/net/dns/question.rb +41 -42
  13. data/lib/net/dns/resolver/socks.rb +47 -55
  14. data/lib/net/dns/resolver/timeouts.rb +19 -30
  15. data/lib/net/dns/resolver.rb +151 -176
  16. data/lib/net/dns/rr/a.rb +45 -55
  17. data/lib/net/dns/rr/aaaa.rb +39 -50
  18. data/lib/net/dns/rr/classes.rb +32 -37
  19. data/lib/net/dns/rr/cname.rb +31 -41
  20. data/lib/net/dns/rr/hinfo.rb +40 -56
  21. data/lib/net/dns/rr/mr.rb +31 -42
  22. data/lib/net/dns/rr/mx.rb +35 -47
  23. data/lib/net/dns/rr/ns.rb +31 -41
  24. data/lib/net/dns/rr/null.rb +10 -15
  25. data/lib/net/dns/rr/ptr.rb +16 -24
  26. data/lib/net/dns/rr/soa.rb +36 -35
  27. data/lib/net/dns/rr/srv.rb +18 -19
  28. data/lib/net/dns/rr/txt.rb +11 -16
  29. data/lib/net/dns/rr/types.rb +118 -109
  30. data/lib/net/dns/rr.rb +107 -117
  31. data/lib/net/dns/version.rb +5 -13
  32. data/lib/net/dns.rb +6 -11
  33. metadata +18 -83
  34. data/.gitignore +0 -8
  35. data/Gemfile +0 -4
  36. data/Rakefile +0 -71
  37. data/fixtures/resolv.conf +0 -4
  38. data/lib/net/dns/core_ext.rb +0 -52
  39. data/net-dns.gemspec +0 -35
  40. data/test/header_test.rb +0 -167
  41. data/test/names_test.rb +0 -21
  42. data/test/packet_test.rb +0 -49
  43. data/test/question_test.rb +0 -83
  44. data/test/resolver/timeouts_test.rb +0 -109
  45. data/test/resolver_test.rb +0 -117
  46. data/test/rr/a_test.rb +0 -113
  47. data/test/rr/aaaa_test.rb +0 -109
  48. data/test/rr/classes_test.rb +0 -85
  49. data/test/rr/cname_test.rb +0 -97
  50. data/test/rr/hinfo_test.rb +0 -117
  51. data/test/rr/mr_test.rb +0 -105
  52. data/test/rr/mx_test.rb +0 -112
  53. data/test/rr/ns_test.rb +0 -86
  54. data/test/rr/types_test.rb +0 -69
  55. data/test/rr_test.rb +0 -131
  56. data/test/test_helper.rb +0 -4
@@ -1,7 +1,6 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
3
  class RR
4
-
5
4
  #------------------------------------------------------------
6
5
  # RR type TXT
7
6
  #------------------------------------------------------------
@@ -13,7 +12,7 @@ module Net # :nodoc:
13
12
  def build_pack
14
13
  str = ""
15
14
  @txt.split(" ").each do |txt|
16
- str += [txt.length,txt].pack("C a*")
15
+ str += [txt.length, txt].pack("C a*")
17
16
  end
18
17
  @txt_pack = str
19
18
  @rdlength = @txt_pack.size
@@ -24,38 +23,34 @@ module Net # :nodoc:
24
23
  end
25
24
 
26
25
  def subclass_new_from_hash(args)
27
- if args.has_key? :txt
28
- @txt = args[:txt].strip
29
- else
30
- raise ArgumentError, ":txt field is mandatory but missing"
31
- end
26
+ raise ArgumentError, ":txt field is mandatory but missing" unless args.key? :txt
27
+
28
+ @txt = args[:txt].strip
32
29
  end
33
30
 
34
31
  def subclass_new_from_string(str)
35
32
  @txt = str.strip
36
33
  end
37
34
 
38
- def subclass_new_from_binary(data,offset)
35
+ def subclass_new_from_binary(data, offset)
39
36
  off_end = offset + @rdlength
40
37
  @txt = ""
41
38
  while offset < off_end
42
- len = data.unpack("@#{offset} C")[0]
39
+ len = data.unpack1("@#{offset} C")
43
40
  offset += 1
44
- str = data[offset..offset+len-1]
41
+ str = data[offset..offset + len - 1]
45
42
  offset += len
46
43
  @txt << str << " "
47
44
  end
48
- return offset
45
+ offset
49
46
  end
50
47
 
51
48
  private
52
49
 
53
- def set_type
54
- @type = Net::DNS::RR::Types.new("TXT")
55
- end
56
-
50
+ def set_type
51
+ @type = Net::DNS::RR::Types.new("TXT")
52
+ end
57
53
  end
58
-
59
54
  end
60
55
  end
61
56
  end
@@ -1,95 +1,111 @@
1
1
  module Net # :nodoc:
2
2
  module DNS
3
-
4
3
  class RR
5
-
6
4
  # This is an auxiliary class to handle RR type field in a DNS packet.
7
5
  class Types
8
-
9
6
  TYPES = {
10
- 'SIGZERO' => 0, # RFC2931 consider this a pseudo type
11
- 'A' => 1, # RFC 1035, Section 3.4.1
12
- 'NS' => 2, # RFC 1035, Section 3.3.11
13
- 'MD' => 3, # RFC 1035, Section 3.3.4 (obsolete)
14
- 'MF' => 4, # RFC 1035, Section 3.3.5 (obsolete)
15
- 'CNAME' => 5, # RFC 1035, Section 3.3.1
16
- 'SOA' => 6, # RFC 1035, Section 3.3.13
17
- 'MB' => 7, # RFC 1035, Section 3.3.3
18
- 'MG' => 8, # RFC 1035, Section 3.3.6
19
- 'MR' => 9, # RFC 1035, Section 3.3.8
20
- 'NULL' => 10, # RFC 1035, Section 3.3.10
21
- 'WKS' => 11, # RFC 1035, Section 3.4.2 (deprecated)
22
- 'PTR' => 12, # RFC 1035, Section 3.3.12
23
- 'HINFO' => 13, # RFC 1035, Section 3.3.2
24
- 'MINFO' => 14, # RFC 1035, Section 3.3.7
25
- 'MX' => 15, # RFC 1035, Section 3.3.9
26
- 'TXT' => 16, # RFC 1035, Section 3.3.14
27
- 'RP' => 17, # RFC 1183, Section 2.2
28
- 'AFSDB' => 18, # RFC 1183, Section 1
29
- 'X25' => 19, # RFC 1183, Section 3.1
30
- 'ISDN' => 20, # RFC 1183, Section 3.2
31
- 'RT' => 21, # RFC 1183, Section 3.3
32
- 'NSAP' => 22, # RFC 1706, Section 5
33
- 'NSAP_PTR' => 23, # RFC 1348 (obsolete)
34
- # The following 2 RRs are impemented in Net::DNS::SEC, TODO
35
- 'SIG' => 24, # RFC 2535, Section 4.1
36
- 'KEY' => 25, # RFC 2535, Section 3.1
37
- 'PX' => 26, # RFC 2163,
38
- 'GPOS' => 27, # RFC 1712 (obsolete)
39
- 'AAAA' => 28, # RFC 1886, Section 2.1
40
- 'LOC' => 29, # RFC 1876
41
- # The following RR is implemented in Net::DNS::SEC, TODO
42
- 'NXT' => 30, # RFC 2535, Section 5.2
43
- 'EID' => 31, # draft-ietf-nimrod-dns-xx.txt
44
- 'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt
45
- 'SRV' => 33, # RFC 2052
46
- 'ATMA' => 34, # ???
47
- 'NAPTR' => 35, # RFC 2168
48
- 'KX' => 36, # RFC 2230
49
- 'CERT' => 37, # RFC 2538
50
- 'DNAME' => 39, # RFC 2672
51
- 'OPT' => 41, # RFC 2671
52
- # The following 4 RRs are implemented in Net::DNS::SEC TODO
53
- 'DS' => 43, # draft-ietf-dnsext-delegation-signer
54
- 'SSHFP' => 44, # draft-ietf-secsh-dns (No RFC # yet at time of coding)
55
- 'RRSIG' => 46, # draft-ietf-dnsext-dnssec-2535typecode-change
56
- 'NSEC' => 47, # draft-ietf-dnsext-dnssec-2535typecode-change
57
- 'DNSKEY' => 48, # draft-ietf-dnsext-dnssec-2535typecode-change
58
- 'UINFO' => 100, # non-standard
59
- 'UID' => 101, # non-standard
60
- 'GID' => 102, # non-standard
61
- 'UNSPEC' => 103, # non-standard
62
- 'TKEY' => 249, # RFC 2930
63
- 'TSIG' => 250, # RFC 2931
64
- 'IXFR' => 251, # RFC 1995
65
- 'AXFR' => 252, # RFC 1035
66
- 'MAILB' => 253, # RFC 1035 (MB, MG, MR)
67
- 'MAILA' => 254, # RFC 1035 (obsolete - see MX)
68
- 'ANY' => 255, # RFC 1035
69
- }
7
+ 'SIGZERO' => 0, # RFC2931 consider this a pseudo type
8
+ 'A' => 1, # RFC 1035, Section 3.4.1
9
+ 'NS' => 2, # RFC 1035, Section 3.3.11
10
+ 'MD' => 3, # RFC 1035, Section 3.3.4 (obsolete)
11
+ 'MF' => 4, # RFC 1035, Section 3.3.5 (obsolete)
12
+ 'CNAME' => 5, # RFC 1035, Section 3.3.1
13
+ 'SOA' => 6, # RFC 1035, Section 3.3.13
14
+ 'MB' => 7, # RFC 1035, Section 3.3.3 (obsolete)
15
+ 'MG' => 8, # RFC 1035, Section 3.3.6 (obsolete)
16
+ 'MR' => 9, # RFC 1035, Section 3.3.8 (obsolete)
17
+ 'NULL' => 10, # RFC 1035, Section 3.3.10 (obsolete)
18
+ 'WKS' => 11, # RFC 1035, Section 3.4.2 (obsolete)
19
+ 'PTR' => 12, # RFC 1035, Section 3.3.12
20
+ 'HINFO' => 13, # RFC 1035, Section 3.3.2
21
+ 'MINFO' => 14, # RFC 1035, Section 3.3.7 (obsolete)
22
+ 'MX' => 15, # RFC 1035, Section 3.3.9
23
+ 'TXT' => 16, # RFC 1035, Section 3.3.14
24
+ 'RP' => 17, # RFC 1183, Section 2.2 (obsolete)
25
+ 'AFSDB' => 18, # RFC 1183, Section 1
26
+ 'X25' => 19, # RFC 1183, Section 3.1 (obsolete)
27
+ 'ISDN' => 20, # RFC 1183, Section 3.2 (obsolete)
28
+ 'RT' => 21, # RFC 1183, Section 3.3 (obsolete)
29
+ 'NSAP' => 22, # RFC 1706, Section 5 (obsolete)
30
+ 'NSAP_PTR' => 23, # RFC 1348 (obsolete) (obsolete)
31
+ 'SIG' => 24, # RFC 2535, Section 4.1 (obsolete)
32
+ 'KEY' => 25, # RFC 2535, Section 3.1 (obsolete)
33
+ 'PX' => 26, # RFC 2163, (obsolete)
34
+ 'GPOS' => 27, # RFC 1712 (obsolete)
35
+ 'AAAA' => 28, # RFC 1886, Section 2.1
36
+ 'LOC' => 29, # RFC 1876
37
+ 'NXT' => 30, # RFC 2535, Section 5.2 (obsolete)
38
+ 'EID' => 31, # draft-ietf-nimrod-dns-xx.txt (obsolete)
39
+ 'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt (obsolete)
40
+ 'SRV' => 33, # RFC 2052
41
+ 'ATMA' => 34, # ??? (obsolete)
42
+ 'NAPTR' => 35, # RFC 2168
43
+ 'KX' => 36, # RFC 2230
44
+ 'CERT' => 37, # RFC 2538
45
+ 'DNAME' => 39, # RFC 2672
46
+ 'OPT' => 41, # RFC 2671
47
+ 'APL' => 42, # RFC 3123 (obsolete)
48
+ 'DS' => 43, # RFC 4034
49
+ 'SSHFP' => 44, # RFC 4255
50
+ 'IPSECKEY' => 45, # RFC 4025
51
+ 'RRSIG' => 46, # RFC 4034
52
+ 'NSEC' => 47, # RFC 4034
53
+ 'DNSKEY' => 48, # RFC 4034
54
+ 'DHCID' => 49, # RFC 4701
55
+ 'NSEC3' => 50, # RFC 5155
56
+ 'NSEC3PARAM' => 51, # RFC 5155
57
+ 'TLSA' => 52, # RFC 6698
58
+ 'SMIMEA' => 53, # RFC 8162
59
+ 'HIP' => 55, # RFC 8005
60
+ 'CDS' => 59, # RFC 7344
61
+ 'CDNSKEY' => 60, # RFC 7344
62
+ 'OPENPGPKEY' => 61, # RFC 7929
63
+ 'CSYNC' => 62, # RFC 7477
64
+ 'ZONEMD' => 63, # RFC 8976
65
+ 'SVCB' => 64, # RFC 9460
66
+ 'HTTPS' => 65, # RFC 9460
67
+ 'SPF' => 99, # RFC 4408 (obsolete)
68
+ 'UINFO' => 100, # non-standard (obsolete)
69
+ 'UID' => 101, # non-standard (obsolete)
70
+ 'GID' => 102, # non-standard (obsolete)
71
+ 'UNSPEC' => 103, # non-standard (obsolete)
72
+ 'EUI48' => 108, # RFC 7043
73
+ 'EUI64' => 109, # RFC 7043
74
+ 'TKEY' => 249, # RFC 2930
75
+ 'TSIG' => 250, # RFC 2931
76
+ 'IXFR' => 251, # RFC 1995
77
+ 'AXFR' => 252, # RFC 1035
78
+ 'MAILB' => 253, # RFC 1035 (MB, MG, MR) (obsolete)
79
+ 'MAILA' => 254, # RFC 1035 (obsolete - see MX)
80
+ 'ANY' => 255, # RFC 1035
81
+ 'URI' => 256, # RFC 7553
82
+ 'CAA' => 257, # RFC 6844
83
+ }.freeze
70
84
 
71
85
  # The default value when type is nil in Resource Records
72
86
  @@default = TYPES["A"]
73
87
 
88
+ def self.default
89
+ @@default
90
+ end
91
+
74
92
  # Be able to control the default type to assign when
75
93
  # type is +nil+. Default to +A+
76
94
  def self.default=(str)
77
- if TYPES.has_key? str
78
- @@default = TYPES[str]
79
- else
80
- raise ArgumentError, "Unknown type #{str}"
81
- end
95
+ raise ArgumentError, "Unknown type #{str}" unless TYPES.key? str
96
+
97
+ @@default = TYPES[str]
82
98
  end
83
99
 
84
100
  # Checks whether +type+ is a valid RR type.
85
101
  def self.valid?(type)
86
102
  case type
87
- when String
88
- TYPES.has_key?(type)
89
- when Fixnum
90
- TYPES.invert.has_key?(type)
91
- else
92
- raise ArgumentError, "Wrong type class: #{type.class}"
103
+ when String
104
+ TYPES.key?(type)
105
+ when Integer
106
+ TYPES.invert.key?(type)
107
+ else
108
+ raise ArgumentError, "Wrong type class: #{type.class}"
93
109
  end
94
110
  end
95
111
 
@@ -97,14 +113,13 @@ module Net # :nodoc:
97
113
  # given the numeric value
98
114
  def self.to_str(type)
99
115
  case type
100
- when Fixnum
101
- if TYPES.invert.has_key? type
102
- TYPES.invert[type]
103
- else
104
- raise ArgumentError, "Unknown type number #{type}"
105
- end
106
- else
107
- raise ArgumentError, "Wrong type class: #{type.class}"
116
+ when Integer
117
+ raise ArgumentError, "Unknown type number #{type}" unless TYPES.invert.key? type
118
+
119
+ TYPES.invert[type]
120
+
121
+ else
122
+ raise ArgumentError, "Wrong type class: #{type.class}"
108
123
  end
109
124
  end
110
125
 
@@ -112,7 +127,7 @@ module Net # :nodoc:
112
127
  # in a format suited for regexps
113
128
  def self.regexp
114
129
  # Longest ones go first, so the regex engine will match AAAA before A.
115
- TYPES.keys.sort { |a,b| b.length <=> a.length }.join("|")
130
+ TYPES.keys.sort { |a, b| b.length <=> a.length }.join("|")
116
131
  end
117
132
 
118
133
  # Creates a new object representing an RR type. Performs some
@@ -123,7 +138,7 @@ module Net # :nodoc:
123
138
  when String
124
139
  # type in the form "A" or "NS"
125
140
  new_from_string(type.upcase)
126
- when Fixnum
141
+ when Integer
127
142
  # type in numeric form
128
143
  new_from_num(type)
129
144
  when nil
@@ -157,37 +172,31 @@ module Net # :nodoc:
157
172
  @num.to_s
158
173
  end
159
174
 
160
-
161
175
  private
162
176
 
163
- # Constructor for string data type.
164
- def new_from_string(type)
165
- case type
166
- when /^TYPE\\d+/
167
- # TODO!!!
168
- else
169
- # String with name of type
170
- if TYPES.has_key? type
171
- @str = type
172
- @num = TYPES[type]
173
- else
174
- raise ArgumentError, "Unknown type #{type}"
175
- end
176
- end
177
- end
177
+ # Constructor for string data type.
178
+ def new_from_string(type)
179
+ case type
180
+ when /^TYPE\\d+/
181
+ # TODO!!!
182
+ else
183
+ # String with name of type
184
+ raise ArgumentError, "Unknown type #{type}" unless TYPES.key? type
185
+
186
+ @str = type
187
+ @num = TYPES[type]
178
188
 
179
- # Contructor for numeric data type.
180
- def new_from_num(type)
181
- if TYPES.invert.has_key? type
182
- @num = type
183
- @str = TYPES.invert[type]
184
- else
185
- raise ArgumentError, "Unkown type number #{type}"
186
- end
187
189
  end
190
+ end
188
191
 
189
- end
192
+ # Contructor for numeric data type.
193
+ def new_from_num(type)
194
+ raise ArgumentError, "Unkown type number #{type}" unless TYPES.invert.key? type
190
195
 
196
+ @num = type
197
+ @str = TYPES.invert[type]
198
+ end
199
+ end
191
200
  end
192
201
  end
193
202
  end