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/hinfo.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
4
|
#
|
6
5
|
# = System Information Record (HINFO)
|
7
6
|
#
|
@@ -13,30 +12,24 @@ module Net # :nodoc:
|
|
13
12
|
# Single space between CPU and OS parameters.
|
14
13
|
#
|
15
14
|
class HINFO < RR
|
16
|
-
|
17
15
|
# Gets the CPU value.
|
18
16
|
#
|
19
17
|
# Returns a String.
|
20
|
-
|
21
|
-
@cpu
|
22
|
-
end
|
18
|
+
attr_reader :cpu
|
23
19
|
|
24
20
|
# Gets the OS value.
|
25
21
|
#
|
26
22
|
# Returns a String.
|
27
|
-
|
28
|
-
@os
|
29
|
-
end
|
23
|
+
attr_reader :os
|
30
24
|
|
31
25
|
# Gets the standardized value for this record,
|
32
26
|
# represented by the value of <tt>cpu</tt> and <tt>os</tt>.
|
33
27
|
#
|
34
28
|
# Returns a String.
|
35
29
|
def value
|
36
|
-
%Q
|
30
|
+
%Q("#{cpu}" "#{os}")
|
37
31
|
end
|
38
32
|
|
39
|
-
|
40
33
|
# Gets a list of all the attributes for this record.
|
41
34
|
#
|
42
35
|
# Returns an Array of values.
|
@@ -44,65 +37,60 @@ module Net # :nodoc:
|
|
44
37
|
[nil, nil, cls.to_s, type.to_s, value]
|
45
38
|
end
|
46
39
|
|
47
|
-
|
48
40
|
private
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def subclass_new_from_string(str)
|
60
|
-
@cpu, @os = check_hinfo(str)
|
42
|
+
def subclass_new_from_hash(options)
|
43
|
+
if options.key?(:cpu) && options.key?(:os)
|
44
|
+
@cpu = options[:cpu]
|
45
|
+
@os = options[:os]
|
46
|
+
else
|
47
|
+
raise ArgumentError, ":cpu and :os fields are mandatory"
|
61
48
|
end
|
49
|
+
end
|
62
50
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
@cpu = data[offset..(offset + len)]
|
67
|
-
offset += len
|
68
|
-
|
69
|
-
len = data.unpack("@#{offset} C").first
|
70
|
-
offset += 1
|
71
|
-
@os = data[offset..(offset + len)]
|
72
|
-
offset += len
|
73
|
-
end
|
51
|
+
def subclass_new_from_string(str)
|
52
|
+
@cpu, @os = check_hinfo(str)
|
53
|
+
end
|
74
54
|
|
55
|
+
def subclass_new_from_binary(data, offset)
|
56
|
+
len = data.unpack("@#{offset} C").first
|
57
|
+
offset += 1
|
58
|
+
@cpu = data[offset..(offset + len)]
|
59
|
+
offset += len
|
75
60
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
value
|
82
|
-
end
|
61
|
+
len = data.unpack("@#{offset} C").first
|
62
|
+
offset += 1
|
63
|
+
@os = data[offset..(offset + len)]
|
64
|
+
offset += len
|
65
|
+
end
|
83
66
|
|
67
|
+
def set_type
|
68
|
+
@type = Net::DNS::RR::Types.new("HINFO")
|
69
|
+
end
|
84
70
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
else
|
89
|
-
raise ArgumentError, "Invalid HINFO Section `#{input}'"
|
90
|
-
end
|
91
|
-
end
|
71
|
+
def get_inspect
|
72
|
+
value
|
73
|
+
end
|
92
74
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
75
|
+
def check_hinfo(input)
|
76
|
+
if input.to_s.strip =~ /^(?:["']?(.*?)["']?)\s+(?:["']?(.*?)["']?)$/
|
77
|
+
[Regexp.last_match(1), Regexp.last_match(2)]
|
78
|
+
else
|
79
|
+
raise ArgumentError, "Invalid HINFO Section `#{input}'"
|
98
80
|
end
|
81
|
+
end
|
99
82
|
|
100
|
-
|
101
|
-
|
102
|
-
|
83
|
+
def build_pack
|
84
|
+
@hinfo_pack = ""
|
85
|
+
@hinfo_pack += [cpu.size].pack("C") + cpu
|
86
|
+
@hinfo_pack += [os.size].pack("C") + os
|
87
|
+
@rdlength = @hinfo_pack.size
|
88
|
+
end
|
103
89
|
|
90
|
+
def get_data
|
91
|
+
@hinfo_pack
|
92
|
+
end
|
104
93
|
end
|
105
|
-
|
106
94
|
end
|
107
95
|
end
|
108
96
|
end
|
data/lib/net/dns/rr/mr.rb
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
module Net # :nodoc:
|
2
2
|
module DNS
|
3
|
-
|
4
3
|
class RR
|
5
|
-
|
6
4
|
#
|
7
5
|
# = Mail Rename Record (MR)
|
8
6
|
#
|
9
7
|
# Class for DNS MR resource records.
|
10
8
|
#
|
11
9
|
class MR < RR
|
12
|
-
|
13
10
|
# Gets the newname value.
|
14
11
|
#
|
15
12
|
# Returns a String.
|
16
|
-
|
17
|
-
@newname
|
18
|
-
end
|
13
|
+
attr_reader :newname
|
19
14
|
|
20
15
|
# Gets the standardized value for this record,
|
21
16
|
# represented by the value of <tt>newname</tt>.
|
@@ -25,55 +20,51 @@ module Net # :nodoc:
|
|
25
20
|
newname.to_s
|
26
21
|
end
|
27
22
|
|
28
|
-
|
29
23
|
private
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def subclass_new_from_string(str)
|
40
|
-
@newname = check_name(str)
|
41
|
-
end
|
42
|
-
|
43
|
-
def subclass_new_from_binary(data, offset)
|
44
|
-
@newname = dn_expand(data,offset)
|
45
|
-
offset
|
25
|
+
def subclass_new_from_hash(options)
|
26
|
+
if options.key?(:newname)
|
27
|
+
@newname = check_name(options[:newname])
|
28
|
+
else
|
29
|
+
raise ArgumentError, ":newname field is mandatory"
|
46
30
|
end
|
31
|
+
end
|
47
32
|
|
33
|
+
def subclass_new_from_string(str)
|
34
|
+
@newname = check_name(str)
|
35
|
+
end
|
48
36
|
|
49
|
-
|
50
|
-
|
51
|
-
|
37
|
+
def subclass_new_from_binary(data, offset)
|
38
|
+
@newname = dn_expand(data, offset)
|
39
|
+
offset
|
40
|
+
end
|
52
41
|
|
53
|
-
|
54
|
-
|
55
|
-
|
42
|
+
def set_type
|
43
|
+
@type = Net::DNS::RR::Types.new("MR")
|
44
|
+
end
|
56
45
|
|
46
|
+
def get_inspect
|
47
|
+
value
|
48
|
+
end
|
57
49
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
name
|
50
|
+
def check_name(input)
|
51
|
+
name = input.to_s
|
52
|
+
unless name =~ /(\w\.?)+\s*$/
|
53
|
+
raise ArgumentError, "Invalid Domain Name `#{name}'"
|
64
54
|
end
|
65
55
|
|
66
|
-
|
67
|
-
|
68
|
-
@rdlength = @newname_pack.size
|
69
|
-
end
|
56
|
+
name
|
57
|
+
end
|
70
58
|
|
71
|
-
|
72
|
-
|
73
|
-
|
59
|
+
def build_pack
|
60
|
+
@newname_pack = pack_name(@newname)
|
61
|
+
@rdlength = @newname_pack.size
|
62
|
+
end
|
74
63
|
|
64
|
+
def get_data
|
65
|
+
@newname_pack
|
66
|
+
end
|
75
67
|
end
|
76
|
-
|
77
68
|
end
|
78
69
|
end
|
79
70
|
end
|
data/lib/net/dns/rr/mx.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
4
|
#
|
6
5
|
# = Mail Exchange Record (MX)
|
7
6
|
#
|
@@ -12,20 +11,15 @@ module Net # :nodoc:
|
|
12
11
|
# The MX RR is used by SMTP (Mail) Agents to route mail for the domain.
|
13
12
|
#
|
14
13
|
class MX < RR
|
15
|
-
|
16
14
|
# Gets the preference value.
|
17
15
|
#
|
18
16
|
# Returns an Integer.
|
19
|
-
|
20
|
-
@preference
|
21
|
-
end
|
17
|
+
attr_reader :preference
|
22
18
|
|
23
19
|
# Gets the exchange value.
|
24
20
|
#
|
25
21
|
# Returns a String.
|
26
|
-
|
27
|
-
@exchange
|
28
|
-
end
|
22
|
+
attr_reader :exchange
|
29
23
|
|
30
24
|
# Gets the standardized value for this record,
|
31
25
|
# represented by the value of <tt>preference</tt> and <tt>exchange</tt>.
|
@@ -35,58 +29,54 @@ module Net # :nodoc:
|
|
35
29
|
"#{preference} #{exchange}"
|
36
30
|
end
|
37
31
|
|
38
|
-
|
39
32
|
private
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def subclass_new_from_string(str)
|
51
|
-
@preference, @exchange = check_mx(str)
|
52
|
-
end
|
53
|
-
|
54
|
-
def subclass_new_from_binary(data, offset)
|
55
|
-
@preference = data.unpack("@#{offset} n")[0]
|
56
|
-
offset += 2
|
57
|
-
@exchange, offset = dn_expand(data, offset)
|
58
|
-
offset
|
34
|
+
def subclass_new_from_hash(options)
|
35
|
+
if options.key?(:preference) && options.key?(:exchange)
|
36
|
+
@preference = options[:preference].to_i
|
37
|
+
@exchange = options[:exchange]
|
38
|
+
else
|
39
|
+
raise ArgumentError, ":preference and :exchange fields are mandatory"
|
59
40
|
end
|
41
|
+
end
|
60
42
|
|
43
|
+
def subclass_new_from_string(str)
|
44
|
+
@preference, @exchange = check_mx(str)
|
45
|
+
end
|
61
46
|
|
62
|
-
|
63
|
-
|
64
|
-
|
47
|
+
def subclass_new_from_binary(data, offset)
|
48
|
+
@preference = data.unpack("@#{offset} n")[0]
|
49
|
+
offset += 2
|
50
|
+
@exchange, offset = dn_expand(data, offset)
|
51
|
+
offset
|
52
|
+
end
|
65
53
|
|
66
|
-
|
67
|
-
|
68
|
-
|
54
|
+
def set_type
|
55
|
+
@type = Net::DNS::RR::Types.new("MX")
|
56
|
+
end
|
69
57
|
|
58
|
+
def get_inspect
|
59
|
+
value
|
60
|
+
end
|
70
61
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
[$1.to_i, $2]
|
62
|
+
def check_mx(input)
|
63
|
+
str = input.to_s
|
64
|
+
unless str.strip =~ /^(\d+)\s+(\S+)$/
|
65
|
+
raise ArgumentError, "Invalid MX section `#{str}'"
|
77
66
|
end
|
78
67
|
|
79
|
-
|
80
|
-
|
81
|
-
@rdlength = @mx_pack.size
|
82
|
-
end
|
68
|
+
[Regexp.last_match(1).to_i, Regexp.last_match(2)]
|
69
|
+
end
|
83
70
|
|
84
|
-
|
85
|
-
|
86
|
-
|
71
|
+
def build_pack
|
72
|
+
@mx_pack = [@preference].pack("n") + pack_name(@exchange)
|
73
|
+
@rdlength = @mx_pack.size
|
74
|
+
end
|
87
75
|
|
76
|
+
def get_data
|
77
|
+
@mx_pack
|
78
|
+
end
|
88
79
|
end
|
89
|
-
|
90
80
|
end
|
91
81
|
end
|
92
82
|
end
|
data/lib/net/dns/rr/ns.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
4
|
#
|
6
5
|
# = Name Server Record (NS)
|
7
6
|
#
|
8
7
|
# Class for DNS NS resource records.
|
9
8
|
#
|
10
9
|
class NS < RR
|
11
|
-
|
12
10
|
# Gets the name server value.
|
13
11
|
#
|
14
12
|
# Returns a String.
|
15
|
-
|
16
|
-
@nsdname
|
17
|
-
end
|
13
|
+
attr_reader :nsdname
|
18
14
|
|
19
15
|
# Gets the standardized value for this record,
|
20
16
|
# represented by the value of <tt>nsdname</tt>.
|
@@ -24,55 +20,51 @@ module Net # :nodoc:
|
|
24
20
|
nsdname.to_s
|
25
21
|
end
|
26
22
|
|
27
|
-
|
28
23
|
private
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def subclass_new_from_string(str)
|
39
|
-
@nsdname = check_name(str)
|
40
|
-
end
|
41
|
-
|
42
|
-
def subclass_new_from_binary(data, offset)
|
43
|
-
@nsdname, offset = dn_expand(data, offset)
|
44
|
-
offset
|
25
|
+
def subclass_new_from_hash(options)
|
26
|
+
if options.key?(:nsdname)
|
27
|
+
@nsdname = check_name(options[:nsdname])
|
28
|
+
else
|
29
|
+
raise ArgumentError, ":nsdname field is mandatory"
|
45
30
|
end
|
31
|
+
end
|
46
32
|
|
33
|
+
def subclass_new_from_string(str)
|
34
|
+
@nsdname = check_name(str)
|
35
|
+
end
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
|
37
|
+
def subclass_new_from_binary(data, offset)
|
38
|
+
@nsdname, offset = dn_expand(data, offset)
|
39
|
+
offset
|
40
|
+
end
|
51
41
|
|
52
|
-
|
53
|
-
|
54
|
-
|
42
|
+
def set_type
|
43
|
+
@type = Net::DNS::RR::Types.new("NS")
|
44
|
+
end
|
55
45
|
|
46
|
+
def get_inspect
|
47
|
+
value
|
48
|
+
end
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
name
|
50
|
+
def check_name(input)
|
51
|
+
name = input.to_s
|
52
|
+
unless name =~ /(\w\.?)+\s*$/ && name =~ /[a-zA-Z]/
|
53
|
+
raise ArgumentError, "Invalid Name Server `#{name}'"
|
63
54
|
end
|
64
55
|
|
65
|
-
|
66
|
-
|
67
|
-
@rdlength = @nsdname_pack.size
|
68
|
-
end
|
56
|
+
name
|
57
|
+
end
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
def build_pack
|
60
|
+
@nsdname_pack = pack_name(@nsdname)
|
61
|
+
@rdlength = @nsdname_pack.size
|
62
|
+
end
|
73
63
|
|
64
|
+
def get_data
|
65
|
+
@nsdname_pack
|
66
|
+
end
|
74
67
|
end
|
75
|
-
|
76
68
|
end
|
77
69
|
end
|
78
70
|
end
|