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.
- checksums.yaml +6 -14
- data/.rspec +1 -0
- data/.travis.yml +9 -16
- data/CHANGELOG.md +37 -13
- data/LICENSE.txt +56 -0
- data/README.md +94 -77
- data/demo/check_soa.rb +27 -38
- data/demo/threads.rb +3 -7
- data/lib/net/dns/header.rb +86 -110
- data/lib/net/dns/names.rb +31 -31
- data/lib/net/dns/packet.rb +148 -158
- data/lib/net/dns/question.rb +41 -42
- data/lib/net/dns/resolver/socks.rb +47 -55
- data/lib/net/dns/resolver/timeouts.rb +19 -30
- data/lib/net/dns/resolver.rb +151 -176
- data/lib/net/dns/rr/a.rb +45 -55
- data/lib/net/dns/rr/aaaa.rb +39 -50
- data/lib/net/dns/rr/classes.rb +32 -37
- data/lib/net/dns/rr/cname.rb +31 -41
- data/lib/net/dns/rr/hinfo.rb +40 -56
- data/lib/net/dns/rr/mr.rb +31 -42
- data/lib/net/dns/rr/mx.rb +35 -47
- data/lib/net/dns/rr/ns.rb +31 -41
- data/lib/net/dns/rr/null.rb +10 -15
- data/lib/net/dns/rr/ptr.rb +16 -24
- data/lib/net/dns/rr/soa.rb +36 -35
- data/lib/net/dns/rr/srv.rb +18 -19
- data/lib/net/dns/rr/txt.rb +11 -16
- data/lib/net/dns/rr/types.rb +118 -109
- data/lib/net/dns/rr.rb +107 -117
- data/lib/net/dns/version.rb +5 -13
- data/lib/net/dns.rb +6 -11
- metadata +18 -83
- data/.gitignore +0 -8
- data/Gemfile +0 -4
- data/Rakefile +0 -71
- data/fixtures/resolv.conf +0 -4
- data/lib/net/dns/core_ext.rb +0 -52
- data/net-dns.gemspec +0 -35
- data/test/header_test.rb +0 -167
- data/test/names_test.rb +0 -21
- data/test/packet_test.rb +0 -49
- data/test/question_test.rb +0 -83
- data/test/resolver/timeouts_test.rb +0 -109
- data/test/resolver_test.rb +0 -117
- data/test/rr/a_test.rb +0 -113
- data/test/rr/aaaa_test.rb +0 -109
- data/test/rr/classes_test.rb +0 -85
- data/test/rr/cname_test.rb +0 -97
- data/test/rr/hinfo_test.rb +0 -117
- data/test/rr/mr_test.rb +0 -105
- data/test/rr/mx_test.rb +0 -112
- data/test/rr/ns_test.rb +0 -86
- data/test/rr/types_test.rb +0 -69
- data/test/rr_test.rb +0 -131
- data/test/test_helper.rb +0 -4
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,38 +23,34 @@ module Net # :nodoc:
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def subclass_new_from_hash(args)
|
27
|
-
|
28
|
-
|
29
|
-
|
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.
|
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
|
-
|
45
|
+
offset
|
49
46
|
end
|
50
47
|
|
51
48
|
private
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
data/lib/net/dns/rr/types.rb
CHANGED
@@ -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'
|
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'
|
34
|
-
|
35
|
-
'
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
|
42
|
-
'
|
43
|
-
'
|
44
|
-
'
|
45
|
-
'
|
46
|
-
'
|
47
|
-
'
|
48
|
-
'
|
49
|
-
'
|
50
|
-
'
|
51
|
-
'
|
52
|
-
|
53
|
-
'
|
54
|
-
'
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
65
|
-
'
|
66
|
-
'
|
67
|
-
'
|
68
|
-
'
|
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
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
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
|
-
|
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
|