net-dns 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +1 -1
- data/.rspec +1 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_defaults.yml +364 -0
- data/.rubocop_todo.yml +207 -0
- data/.travis.yml +9 -16
- data/CHANGELOG.md +12 -1
- data/Gemfile +6 -2
- data/LICENSE.txt +56 -0
- data/README.md +94 -77
- data/Rakefile +23 -56
- data/bin/console +14 -0
- data/demo/check_soa.rb +27 -38
- data/demo/threads.rb +3 -7
- data/lib/net/dns.rb +4 -11
- data/lib/net/dns/core_ext.rb +8 -15
- data/lib/net/dns/header.rb +58 -66
- data/lib/net/dns/names.rb +25 -23
- data/lib/net/dns/packet.rb +136 -139
- data/lib/net/dns/question.rb +36 -39
- data/lib/net/dns/resolver.rb +103 -113
- data/lib/net/dns/resolver/socks.rb +45 -51
- data/lib/net/dns/resolver/timeouts.rb +17 -26
- data/lib/net/dns/rr.rb +107 -117
- data/lib/net/dns/rr/a.rb +46 -55
- data/lib/net/dns/rr/aaaa.rb +40 -49
- data/lib/net/dns/rr/classes.rb +26 -29
- data/lib/net/dns/rr/cname.rb +33 -41
- data/lib/net/dns/rr/hinfo.rb +44 -56
- data/lib/net/dns/rr/mr.rb +33 -42
- data/lib/net/dns/rr/mx.rb +37 -47
- data/lib/net/dns/rr/ns.rb +33 -41
- data/lib/net/dns/rr/null.rb +8 -11
- data/lib/net/dns/rr/ptr.rb +14 -20
- data/lib/net/dns/rr/soa.rb +27 -30
- data/lib/net/dns/rr/srv.rb +13 -17
- data/lib/net/dns/rr/txt.rb +8 -11
- data/lib/net/dns/rr/types.rb +97 -99
- data/lib/net/dns/version.rb +5 -13
- data/net-dns.gemspec +17 -29
- data/{fixtures → spec/fixtures}/resolv.conf +0 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/unit/resolver/dns_timeout_spec.rb +36 -0
- data/spec/unit/resolver/tcp_timeout_spec.rb +46 -0
- data/spec/unit/resolver/udp_timeout_spec.rb +46 -0
- data/test/test_helper.rb +12 -3
- data/test/{header_test.rb → unit/header_test.rb} +43 -46
- data/test/{names_test.rb → unit/names_test.rb} +1 -1
- data/test/{packet_test.rb → unit/packet_test.rb} +3 -5
- data/test/{question_test.rb → unit/question_test.rb} +3 -5
- data/test/{resolver_test.rb → unit/resolver_test.rb} +10 -13
- data/test/{rr → unit/rr}/a_test.rb +10 -17
- data/test/{rr → unit/rr}/aaaa_test.rb +7 -14
- data/test/{rr → unit/rr}/classes_test.rb +14 -16
- data/test/{rr → unit/rr}/cname_test.rb +7 -14
- data/test/{rr → unit/rr}/hinfo_test.rb +16 -22
- data/test/{rr → unit/rr}/mr_test.rb +12 -18
- data/test/{rr → unit/rr}/mx_test.rb +18 -24
- data/test/{rr → unit/rr}/ns_test.rb +10 -16
- data/test/{rr → unit/rr}/types_test.rb +10 -8
- data/test/{rr_test.rb → unit/rr_test.rb} +33 -37
- metadata +77 -49
- data/test/resolver/timeouts_test.rb +0 -109
data/lib/net/dns/rr/null.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
4
|
#------------------------------------------------------------
|
6
5
|
# RR type NULL
|
7
6
|
#------------------------------------------------------------
|
@@ -20,11 +19,11 @@ module Net # :nodoc:
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def get_inspect
|
23
|
-
|
22
|
+
@null.to_s
|
24
23
|
end
|
25
24
|
|
26
25
|
def subclass_new_from_hash(args)
|
27
|
-
if args.
|
26
|
+
if args.key? :null
|
28
27
|
@null = args[:null]
|
29
28
|
else
|
30
29
|
raise ArgumentError, ":null field is mandatory but missing"
|
@@ -35,19 +34,17 @@ module Net # :nodoc:
|
|
35
34
|
@null = str.strip
|
36
35
|
end
|
37
36
|
|
38
|
-
def subclass_new_from_binary(data,offset)
|
39
|
-
@null = data[offset..offset
|
40
|
-
|
37
|
+
def subclass_new_from_binary(data, offset)
|
38
|
+
@null = data[offset..offset + @rdlength]
|
39
|
+
offset + @rdlength
|
41
40
|
end
|
42
41
|
|
43
42
|
private
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
def set_type
|
45
|
+
@type = Net::DNS::RR::Types.new("NULL")
|
46
|
+
end
|
49
47
|
end
|
50
|
-
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
data/lib/net/dns/rr/ptr.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
1
|
module Net
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
4
|
#
|
6
5
|
# = Pointer Record (PTR)
|
7
6
|
#
|
8
7
|
# Class for DNS Pointer (PTR) resource records.
|
9
8
|
#
|
10
|
-
# Pointer records are the opposite of A and AAAA RRs
|
9
|
+
# Pointer records are the opposite of A and AAAA RRs
|
11
10
|
# and are used in Reverse Map zone files to map
|
12
11
|
# an IP address (IPv4 or IPv6) to a host name.
|
13
12
|
#
|
14
13
|
class PTR < RR
|
15
|
-
|
16
14
|
# Gets the PTR value.
|
17
15
|
#
|
18
16
|
# Returns a String.
|
@@ -20,7 +18,7 @@ module Net
|
|
20
18
|
@ptrdname.to_s
|
21
19
|
end
|
22
20
|
|
23
|
-
|
21
|
+
alias ptr ptrdname
|
24
22
|
|
25
23
|
# Gets the standardized value for this record,
|
26
24
|
# represented by the value of <tt>ptrdname</tt>.
|
@@ -30,7 +28,6 @@ module Net
|
|
30
28
|
ptrdname.to_s
|
31
29
|
end
|
32
30
|
|
33
|
-
|
34
31
|
private
|
35
32
|
|
36
33
|
def build_pack
|
@@ -43,7 +40,7 @@ module Net
|
|
43
40
|
end
|
44
41
|
|
45
42
|
def subclass_new_from_hash(args)
|
46
|
-
if args.
|
43
|
+
if args.key?(:ptrdname) || args.key?(:ptr)
|
47
44
|
@ptrdname = args[:ptrdname]
|
48
45
|
else
|
49
46
|
raise ArgumentError, ":ptrdname or :ptr field is mandatory"
|
@@ -61,23 +58,20 @@ module Net
|
|
61
58
|
|
62
59
|
private
|
63
60
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
def get_inspect
|
69
|
-
value
|
70
|
-
end
|
71
|
-
|
61
|
+
def set_type
|
62
|
+
@type = Net::DNS::RR::Types.new("PTR")
|
63
|
+
end
|
72
64
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
raise ArgumentError, "Invalid PTR Section `#{input}'"
|
77
|
-
end
|
65
|
+
def get_inspect
|
66
|
+
value
|
67
|
+
end
|
78
68
|
|
69
|
+
def check_name(input)
|
70
|
+
IPAddr.new(str)
|
71
|
+
rescue StandardError
|
72
|
+
raise ArgumentError, "Invalid PTR Section `#{input}'"
|
73
|
+
end
|
79
74
|
end
|
80
|
-
|
81
75
|
end
|
82
76
|
end
|
83
77
|
end
|
data/lib/net/dns/rr/soa.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
4
|
#------------------------------------------------------------
|
6
5
|
# RR type SOA
|
7
6
|
#------------------------------------------------------------
|
8
7
|
class SOA < RR
|
9
8
|
attr_reader :mname, :rname, :serial, :refresh, :retry, :expire, :minimum
|
10
|
-
|
9
|
+
|
11
10
|
private
|
12
|
-
|
11
|
+
|
13
12
|
def build_pack
|
14
13
|
@soa_pack = pack_name(@mname)
|
15
14
|
@soa_pack += pack_name(@rname)
|
16
|
-
@soa_pack += [@serial
|
15
|
+
@soa_pack += [@serial, @refresh, @retry, @expire, @minimum].pack("N5")
|
17
16
|
end
|
18
17
|
|
19
18
|
def get_data
|
@@ -21,28 +20,28 @@ module Net # :nodoc:
|
|
21
20
|
end
|
22
21
|
|
23
22
|
def get_inspect
|
24
|
-
"
|
23
|
+
"#{@mname} #{@rname} #{@serial} #{@refresh} #{@retry} #{@expire} #{@minimum}"
|
25
24
|
end
|
26
25
|
|
27
26
|
def subclass_new_from_hash(args)
|
28
|
-
if args.
|
27
|
+
if args.key? :rdata
|
29
28
|
subclass_new_from_string(args[:rdata])
|
30
29
|
else
|
31
|
-
[
|
32
|
-
raise ArgumentError, "Missing field :#{key}" unless args.
|
30
|
+
%i[mname rname serial refresh retry expire minimum].each do |key|
|
31
|
+
raise ArgumentError, "Missing field :#{key}" unless args.key? key
|
33
32
|
end
|
34
|
-
@mname = args[:mname] if valid? args[:mname]
|
33
|
+
@mname = args[:mname] if valid? args[:mname]
|
35
34
|
@rname = args[:rname] if valid? args[:rname]
|
36
|
-
@serial = args[:serial] if number? args[:serial]
|
37
|
-
@refresh = args[:refresh] if number? args[:refresh]
|
38
|
-
@retry = args[:retry] if number? args[:retry]
|
39
|
-
@expire = args[:expire] if number? args[:expire]
|
40
|
-
@minimum = args[:minimum] if number? args[:minimum]
|
35
|
+
@serial = args[:serial] if number? args[:serial]
|
36
|
+
@refresh = args[:refresh] if number? args[:refresh]
|
37
|
+
@retry = args[:retry] if number? args[:retry]
|
38
|
+
@expire = args[:expire] if number? args[:expire]
|
39
|
+
@minimum = args[:minimum] if number? args[:minimum]
|
41
40
|
end
|
42
41
|
end
|
43
|
-
|
42
|
+
|
44
43
|
def number?(num)
|
45
|
-
if num.
|
44
|
+
if num.is_a?(Integer) && (num > 0)
|
46
45
|
true
|
47
46
|
else
|
48
47
|
raise ArgumentError, "Wrong format field: #{num} not a number or less than zero"
|
@@ -50,29 +49,27 @@ module Net # :nodoc:
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def subclass_new_from_string(str)
|
53
|
-
mname,rname,serial,refresh,ret,expire,minimum = str.strip.split(" ")
|
52
|
+
mname, rname, serial, refresh, ret, expire, minimum = str.strip.split(" ")
|
54
53
|
@mname = mname if valid? mname
|
55
54
|
@rname = rname if valid? rname
|
56
|
-
@serial
|
55
|
+
@serial, @refresh, @retry, @expire, @minimum = [serial, refresh, ret, expire, minimum].collect do |i|
|
57
56
|
i.to_i if valid? i.to_i
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
def subclass_new_from_binary(data,offset)
|
62
|
-
@mname,offset = dn_expand(data,offset)
|
63
|
-
@rname,offset = dn_expand(data,offset)
|
64
|
-
@serial
|
65
|
-
|
60
|
+
def subclass_new_from_binary(data, offset)
|
61
|
+
@mname, offset = dn_expand(data, offset)
|
62
|
+
@rname, offset = dn_expand(data, offset)
|
63
|
+
@serial, @refresh, @retry, @expire, @minimum = data.unpack("@#{offset} N5")
|
64
|
+
offset + 5 * Net::DNS::INT32SZ
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
private
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
|
69
|
+
def set_type
|
70
|
+
@type = Net::DNS::RR::Types.new("SOA")
|
71
|
+
end
|
74
72
|
end
|
75
|
-
|
76
73
|
end
|
77
74
|
end
|
78
75
|
end
|
data/lib/net/dns/rr/srv.rb
CHANGED
@@ -1,45 +1,41 @@
|
|
1
1
|
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
4
|
#------------------------------------------------------------
|
6
5
|
# RR type SRV
|
7
6
|
#------------------------------------------------------------
|
8
7
|
class SRV < RR
|
9
|
-
|
10
8
|
attr_reader :priority, :weight, :port, :host
|
11
|
-
|
9
|
+
|
12
10
|
private
|
13
|
-
|
11
|
+
|
14
12
|
def build_pack
|
15
13
|
str = ""
|
16
14
|
end
|
17
|
-
|
18
|
-
def subclass_new_from_binary(data,offset)
|
15
|
+
|
16
|
+
def subclass_new_from_binary(data, offset)
|
19
17
|
off_end = offset + @rdlength
|
20
18
|
@priority, @weight, @port = data.unpack("@#{offset} n n n")
|
21
|
-
offset+=6
|
19
|
+
offset += 6
|
22
20
|
|
23
|
-
@host=[]
|
21
|
+
@host = []
|
24
22
|
while offset < off_end
|
25
23
|
len = data.unpack("@#{offset} C")[0]
|
26
24
|
offset += 1
|
27
|
-
str = data[offset..offset+len-1]
|
25
|
+
str = data[offset..offset + len - 1]
|
28
26
|
offset += len
|
29
27
|
@host << str
|
30
28
|
end
|
31
|
-
@host
|
29
|
+
@host = @host.join(".")
|
32
30
|
offset
|
33
31
|
end
|
34
|
-
|
32
|
+
|
35
33
|
private
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
|
35
|
+
def set_type
|
36
|
+
@type = Net::DNS::RR::Types.new("SRV")
|
37
|
+
end
|
41
38
|
end
|
42
39
|
end
|
43
|
-
|
44
40
|
end
|
45
41
|
end
|
data/lib/net/dns/rr/txt.rb
CHANGED
@@ -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,7 +23,7 @@ module Net # :nodoc:
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def subclass_new_from_hash(args)
|
27
|
-
if args.
|
26
|
+
if args.key? :txt
|
28
27
|
@txt = args[:txt].strip
|
29
28
|
else
|
30
29
|
raise ArgumentError, ":txt field is mandatory but missing"
|
@@ -35,27 +34,25 @@ module Net # :nodoc:
|
|
35
34
|
@txt = str.strip
|
36
35
|
end
|
37
36
|
|
38
|
-
def subclass_new_from_binary(data,offset)
|
37
|
+
def subclass_new_from_binary(data, offset)
|
39
38
|
off_end = offset + @rdlength
|
40
39
|
@txt = ""
|
41
40
|
while offset < off_end
|
42
41
|
len = data.unpack("@#{offset} C")[0]
|
43
42
|
offset += 1
|
44
|
-
str = data[offset..offset+len-1]
|
43
|
+
str = data[offset..offset + len - 1]
|
45
44
|
offset += len
|
46
45
|
@txt << str << " "
|
47
46
|
end
|
48
|
-
|
47
|
+
offset
|
49
48
|
end
|
50
49
|
|
51
50
|
private
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def set_type
|
53
|
+
@type = Net::DNS::RR::Types.new("TXT")
|
54
|
+
end
|
57
55
|
end
|
58
|
-
|
59
56
|
end
|
60
57
|
end
|
61
58
|
end
|
data/lib/net/dns/rr/types.rb
CHANGED
@@ -1,80 +1,81 @@
|
|
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'
|
11
|
-
'A'
|
12
|
-
'NS'
|
13
|
-
'MD'
|
14
|
-
'MF'
|
15
|
-
'CNAME'
|
16
|
-
'SOA'
|
17
|
-
'MB'
|
18
|
-
'MG'
|
19
|
-
'MR'
|
20
|
-
'NULL'
|
21
|
-
'WKS'
|
22
|
-
'PTR'
|
23
|
-
'HINFO'
|
24
|
-
'MINFO'
|
25
|
-
'MX'
|
26
|
-
'TXT'
|
27
|
-
'RP'
|
28
|
-
'AFSDB'
|
29
|
-
'X25'
|
30
|
-
'ISDN'
|
31
|
-
'RT'
|
32
|
-
'NSAP'
|
33
|
-
'NSAP_PTR'
|
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
|
15
|
+
'MG' => 8, # RFC 1035, Section 3.3.6
|
16
|
+
'MR' => 9, # RFC 1035, Section 3.3.8
|
17
|
+
'NULL' => 10, # RFC 1035, Section 3.3.10
|
18
|
+
'WKS' => 11, # RFC 1035, Section 3.4.2 (deprecated)
|
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
|
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
|
25
|
+
'AFSDB' => 18, # RFC 1183, Section 1
|
26
|
+
'X25' => 19, # RFC 1183, Section 3.1
|
27
|
+
'ISDN' => 20, # RFC 1183, Section 3.2
|
28
|
+
'RT' => 21, # RFC 1183, Section 3.3
|
29
|
+
'NSAP' => 22, # RFC 1706, Section 5
|
30
|
+
'NSAP_PTR' => 23, # RFC 1348 (obsolete)
|
34
31
|
# The following 2 RRs are impemented in Net::DNS::SEC, TODO
|
35
|
-
'SIG'
|
36
|
-
'KEY'
|
37
|
-
'PX'
|
38
|
-
'GPOS'
|
39
|
-
'AAAA'
|
40
|
-
'LOC'
|
32
|
+
'SIG' => 24, # RFC 2535, Section 4.1
|
33
|
+
'KEY' => 25, # RFC 2535, Section 3.1
|
34
|
+
'PX' => 26, # RFC 2163,
|
35
|
+
'GPOS' => 27, # RFC 1712 (obsolete)
|
36
|
+
'AAAA' => 28, # RFC 1886, Section 2.1
|
37
|
+
'LOC' => 29, # RFC 1876
|
41
38
|
# The following RR is implemented in Net::DNS::SEC, TODO
|
42
|
-
'NXT'
|
43
|
-
'EID'
|
44
|
-
'NIMLOC'
|
45
|
-
'SRV'
|
46
|
-
'ATMA'
|
47
|
-
'NAPTR'
|
48
|
-
'KX'
|
49
|
-
'CERT'
|
50
|
-
'DNAME'
|
51
|
-
'OPT'
|
39
|
+
'NXT' => 30, # RFC 2535, Section 5.2
|
40
|
+
'EID' => 31, # draft-ietf-nimrod-dns-xx.txt
|
41
|
+
'NIMLOC' => 32, # draft-ietf-nimrod-dns-xx.txt
|
42
|
+
'SRV' => 33, # RFC 2052
|
43
|
+
'ATMA' => 34, # ???
|
44
|
+
'NAPTR' => 35, # RFC 2168
|
45
|
+
'KX' => 36, # RFC 2230
|
46
|
+
'CERT' => 37, # RFC 2538
|
47
|
+
'DNAME' => 39, # RFC 2672
|
48
|
+
'OPT' => 41, # RFC 2671
|
52
49
|
# The following 4 RRs are implemented in Net::DNS::SEC TODO
|
53
|
-
'DS'
|
54
|
-
'SSHFP'
|
55
|
-
'RRSIG'
|
56
|
-
'NSEC'
|
57
|
-
'DNSKEY'
|
58
|
-
'UINFO'
|
59
|
-
'UID'
|
60
|
-
'GID'
|
61
|
-
'UNSPEC'
|
62
|
-
'TKEY'
|
63
|
-
'TSIG'
|
64
|
-
'IXFR'
|
65
|
-
'AXFR'
|
66
|
-
'MAILB'
|
67
|
-
'MAILA'
|
68
|
-
'ANY'
|
69
|
-
}
|
50
|
+
'DS' => 43, # draft-ietf-dnsext-delegation-signer
|
51
|
+
'SSHFP' => 44, # draft-ietf-secsh-dns (No RFC # yet at time of coding)
|
52
|
+
'RRSIG' => 46, # draft-ietf-dnsext-dnssec-2535typecode-change
|
53
|
+
'NSEC' => 47, # draft-ietf-dnsext-dnssec-2535typecode-change
|
54
|
+
'DNSKEY' => 48, # draft-ietf-dnsext-dnssec-2535typecode-change
|
55
|
+
'UINFO' => 100, # non-standard
|
56
|
+
'UID' => 101, # non-standard
|
57
|
+
'GID' => 102, # non-standard
|
58
|
+
'UNSPEC' => 103, # non-standard
|
59
|
+
'TKEY' => 249, # RFC 2930
|
60
|
+
'TSIG' => 250, # RFC 2931
|
61
|
+
'IXFR' => 251, # RFC 1995
|
62
|
+
'AXFR' => 252, # RFC 1035
|
63
|
+
'MAILB' => 253, # RFC 1035 (MB, MG, MR)
|
64
|
+
'MAILA' => 254, # RFC 1035 (obsolete - see MX)
|
65
|
+
'ANY' => 255, # RFC 1035
|
66
|
+
}.freeze
|
70
67
|
|
71
68
|
# The default value when type is nil in Resource Records
|
72
69
|
@@default = TYPES["A"]
|
73
70
|
|
71
|
+
def self.default
|
72
|
+
@@default
|
73
|
+
end
|
74
|
+
|
74
75
|
# Be able to control the default type to assign when
|
75
76
|
# type is +nil+. Default to +A+
|
76
77
|
def self.default=(str)
|
77
|
-
if TYPES.
|
78
|
+
if TYPES.key? str
|
78
79
|
@@default = TYPES[str]
|
79
80
|
else
|
80
81
|
raise ArgumentError, "Unknown type #{str}"
|
@@ -84,12 +85,12 @@ module Net # :nodoc:
|
|
84
85
|
# Checks whether +type+ is a valid RR type.
|
85
86
|
def self.valid?(type)
|
86
87
|
case type
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
when String
|
89
|
+
TYPES.key?(type)
|
90
|
+
when Integer
|
91
|
+
TYPES.invert.key?(type)
|
92
|
+
else
|
93
|
+
raise ArgumentError, "Wrong type class: #{type.class}"
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
@@ -97,14 +98,14 @@ module Net # :nodoc:
|
|
97
98
|
# given the numeric value
|
98
99
|
def self.to_str(type)
|
99
100
|
case type
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
else
|
104
|
-
raise ArgumentError, "Unknown type number #{type}"
|
105
|
-
end
|
101
|
+
when Integer
|
102
|
+
if TYPES.invert.key? type
|
103
|
+
TYPES.invert[type]
|
106
104
|
else
|
107
|
-
raise ArgumentError, "
|
105
|
+
raise ArgumentError, "Unknown type number #{type}"
|
106
|
+
end
|
107
|
+
else
|
108
|
+
raise ArgumentError, "Wrong type class: #{type.class}"
|
108
109
|
end
|
109
110
|
end
|
110
111
|
|
@@ -112,7 +113,7 @@ module Net # :nodoc:
|
|
112
113
|
# in a format suited for regexps
|
113
114
|
def self.regexp
|
114
115
|
# Longest ones go first, so the regex engine will match AAAA before A.
|
115
|
-
TYPES.keys.sort { |a,b| b.length <=> a.length }.join("|")
|
116
|
+
TYPES.keys.sort { |a, b| b.length <=> a.length }.join("|")
|
116
117
|
end
|
117
118
|
|
118
119
|
# Creates a new object representing an RR type. Performs some
|
@@ -123,7 +124,7 @@ module Net # :nodoc:
|
|
123
124
|
when String
|
124
125
|
# type in the form "A" or "NS"
|
125
126
|
new_from_string(type.upcase)
|
126
|
-
when
|
127
|
+
when Integer
|
127
128
|
# type in numeric form
|
128
129
|
new_from_num(type)
|
129
130
|
when nil
|
@@ -157,37 +158,34 @@ module Net # :nodoc:
|
|
157
158
|
@num.to_s
|
158
159
|
end
|
159
160
|
|
160
|
-
|
161
161
|
private
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
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.key? type
|
171
|
+
@str = type
|
172
|
+
@num = TYPES[type]
|
168
173
|
else
|
169
|
-
|
170
|
-
if TYPES.has_key? type
|
171
|
-
@str = type
|
172
|
-
@num = TYPES[type]
|
173
|
-
else
|
174
|
-
raise ArgumentError, "Unknown type #{type}"
|
175
|
-
end
|
174
|
+
raise ArgumentError, "Unknown type #{type}"
|
176
175
|
end
|
177
176
|
end
|
177
|
+
end
|
178
178
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
end
|
179
|
+
# Contructor for numeric data type.
|
180
|
+
def new_from_num(type)
|
181
|
+
if TYPES.invert.key? type
|
182
|
+
@num = type
|
183
|
+
@str = TYPES.invert[type]
|
184
|
+
else
|
185
|
+
raise ArgumentError, "Unkown type number #{type}"
|
187
186
|
end
|
188
|
-
|
187
|
+
end
|
189
188
|
end
|
190
|
-
|
191
189
|
end
|
192
190
|
end
|
193
191
|
end
|