dnsruby 1.55 → 1.56.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +96 -0
- data/Rakefile +30 -29
- data/demo/axfr.rb +93 -93
- data/demo/check_soa.rb +99 -99
- data/demo/check_zone.rb +59 -59
- data/demo/digdlv.rb +43 -43
- data/demo/digroot.rb +34 -34
- data/demo/example_recurse.rb +14 -14
- data/demo/mresolv.rb +30 -30
- data/demo/mx.rb +31 -31
- data/demo/rubydig.rb +37 -37
- data/demo/to_resolve.txt +3088 -3088
- data/demo/trace_dns.rb +46 -46
- data/lib/dnsruby.rb +161 -526
- data/lib/dnsruby/DNS.rb +305 -0
- data/lib/{Dnsruby/Cache.rb → dnsruby/cache.rb} +152 -152
- data/lib/{Dnsruby → dnsruby}/code_mapper.rb +48 -52
- data/lib/dnsruby/code_mappers.rb +295 -0
- data/lib/{Dnsruby/Config.rb → dnsruby/config.rb} +454 -454
- data/lib/{Dnsruby → dnsruby}/dnssec.rb +91 -91
- data/lib/{Dnsruby/Hosts.rb → dnsruby/hosts.rb} +125 -125
- data/lib/{Dnsruby → dnsruby}/ipv4.rb +26 -26
- data/lib/{Dnsruby → dnsruby}/ipv6.rb +42 -42
- data/lib/{Dnsruby → dnsruby}/key_cache.rb +29 -29
- data/lib/dnsruby/message/decoder.rb +164 -0
- data/lib/dnsruby/message/encoder.rb +75 -0
- data/lib/dnsruby/message/header.rb +249 -0
- data/lib/dnsruby/message/message.rb +629 -0
- data/lib/dnsruby/message/question.rb +86 -0
- data/lib/dnsruby/message/section.rb +96 -0
- data/lib/{Dnsruby → dnsruby}/name.rb +141 -141
- data/lib/dnsruby/packet_sender.rb +661 -0
- data/lib/{Dnsruby/Recursor.rb → dnsruby/recursor.rb} +235 -233
- data/lib/dnsruby/resolv.rb +113 -0
- data/lib/dnsruby/resolver.rb +1192 -0
- data/lib/dnsruby/resource/A.rb +56 -0
- data/lib/dnsruby/resource/AAAA.rb +54 -0
- data/lib/{Dnsruby → dnsruby}/resource/AFSDB.rb +68 -68
- data/lib/{Dnsruby → dnsruby}/resource/CERT.rb +105 -105
- data/lib/{Dnsruby → dnsruby}/resource/DHCID.rb +54 -54
- data/lib/dnsruby/resource/DLV.rb +27 -0
- data/lib/{Dnsruby → dnsruby}/resource/DNSKEY.rb +372 -372
- data/lib/{Dnsruby → dnsruby}/resource/DS.rb +255 -255
- data/lib/{Dnsruby → dnsruby}/resource/HINFO.rb +71 -71
- data/lib/{Dnsruby → dnsruby}/resource/HIP.rb +29 -29
- data/lib/{Dnsruby → dnsruby}/resource/IN.rb +30 -30
- data/lib/{Dnsruby → dnsruby}/resource/IPSECKEY.rb +31 -31
- data/lib/{Dnsruby → dnsruby}/resource/ISDN.rb +62 -62
- data/lib/{Dnsruby → dnsruby}/resource/KX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/LOC.rb +263 -263
- data/lib/{Dnsruby → dnsruby}/resource/MINFO.rb +69 -69
- data/lib/{Dnsruby → dnsruby}/resource/MX.rb +65 -65
- data/lib/{Dnsruby → dnsruby}/resource/NAPTR.rb +98 -98
- data/lib/{Dnsruby → dnsruby}/resource/NSAP.rb +171 -171
- data/lib/dnsruby/resource/NSEC.rb +275 -0
- data/lib/dnsruby/resource/NSEC3.rb +332 -0
- data/lib/dnsruby/resource/NSEC3PARAM.rb +135 -0
- data/lib/dnsruby/resource/OPT.rb +272 -0
- data/lib/{Dnsruby → dnsruby}/resource/PX.rb +70 -70
- data/lib/{Dnsruby → dnsruby}/resource/RP.rb +75 -75
- data/lib/dnsruby/resource/RR.rb +421 -0
- data/lib/dnsruby/resource/RRSIG.rb +275 -0
- data/lib/dnsruby/resource/RRSet.rb +190 -0
- data/lib/{Dnsruby → dnsruby}/resource/RT.rb +67 -67
- data/lib/{Dnsruby → dnsruby}/resource/SOA.rb +94 -94
- data/lib/dnsruby/resource/SPF.rb +29 -0
- data/lib/dnsruby/resource/SRV.rb +112 -0
- data/lib/{Dnsruby → dnsruby}/resource/SSHFP.rb +14 -14
- data/lib/dnsruby/resource/TKEY.rb +163 -0
- data/lib/dnsruby/resource/TSIG.rb +593 -0
- data/lib/{Dnsruby → dnsruby}/resource/TXT.rb +191 -191
- data/lib/dnsruby/resource/X25.rb +55 -0
- data/lib/{Dnsruby → dnsruby}/resource/domain_name.rb +25 -25
- data/lib/{Dnsruby → dnsruby}/resource/generic.rb +80 -80
- data/lib/dnsruby/resource/resource.rb +25 -0
- data/lib/{Dnsruby → dnsruby}/select_thread.rb +148 -148
- data/lib/{Dnsruby/SingleResolver.rb → dnsruby/single_resolver.rb} +60 -60
- data/lib/{Dnsruby → dnsruby}/single_verifier.rb +344 -344
- data/lib/dnsruby/the_log.rb +44 -0
- data/lib/dnsruby/update.rb +278 -0
- data/lib/dnsruby/validator_thread.rb +124 -0
- data/lib/dnsruby/version.rb +3 -0
- data/lib/{Dnsruby → dnsruby}/zone_reader.rb +93 -93
- data/lib/{Dnsruby → dnsruby}/zone_transfer.rb +377 -377
- data/test/spec_helper.rb +16 -0
- data/test/tc_axfr.rb +31 -34
- data/test/tc_cache.rb +32 -32
- data/test/tc_dlv.rb +28 -28
- data/test/tc_dns.rb +73 -76
- data/test/tc_dnskey.rb +31 -32
- data/test/tc_dnsruby.rb +50 -44
- data/test/tc_ds.rb +36 -36
- data/test/tc_escapedchars.rb +252 -255
- data/test/tc_hash.rb +17 -21
- data/test/tc_header.rb +48 -57
- data/test/tc_hip.rb +19 -22
- data/test/tc_ipseckey.rb +18 -21
- data/test/tc_keith.rb +300 -0
- data/test/tc_message.rb +87 -0
- data/test/tc_misc.rb +83 -87
- data/test/tc_name.rb +81 -84
- data/test/tc_naptr.rb +18 -21
- data/test/tc_nsec.rb +55 -55
- data/test/tc_nsec3.rb +23 -24
- data/test/tc_nsec3param.rb +20 -21
- data/test/tc_packet.rb +90 -93
- data/test/tc_packet_unique_push.rb +48 -51
- data/test/tc_question.rb +30 -33
- data/test/tc_queue.rb +16 -17
- data/test/tc_recur.rb +16 -17
- data/test/tc_res_config.rb +38 -41
- data/test/tc_res_env.rb +29 -32
- data/test/tc_res_file.rb +26 -29
- data/test/tc_res_opt.rb +62 -65
- data/test/tc_resolver.rb +287 -242
- data/test/tc_rr-opt.rb +70 -63
- data/test/tc_rr-txt.rb +68 -71
- data/test/tc_rr-unknown.rb +45 -48
- data/test/tc_rr.rb +76 -70
- data/test/tc_rrset.rb +21 -22
- data/test/tc_rrsig.rb +19 -20
- data/test/tc_single_resolver.rb +294 -297
- data/test/tc_soak.rb +199 -202
- data/test/tc_soak_base.rb +29 -34
- data/test/tc_sshfp.rb +20 -23
- data/test/tc_tcp.rb +32 -35
- data/test/tc_tkey.rb +41 -44
- data/test/tc_tsig.rb +81 -84
- data/test/tc_update.rb +108 -111
- data/test/tc_validator.rb +29 -29
- data/test/tc_verifier.rb +81 -82
- data/test/ts_dnsruby.rb +16 -15
- data/test/ts_offline.rb +62 -63
- data/test/ts_online.rb +115 -115
- metadata +155 -90
- data/README +0 -59
- data/lib/Dnsruby/DNS.rb +0 -305
- data/lib/Dnsruby/PacketSender.rb +0 -656
- data/lib/Dnsruby/Resolver.rb +0 -1189
- data/lib/Dnsruby/TheLog.rb +0 -44
- data/lib/Dnsruby/message.rb +0 -1230
- data/lib/Dnsruby/resource/A.rb +0 -56
- data/lib/Dnsruby/resource/AAAA.rb +0 -54
- data/lib/Dnsruby/resource/DLV.rb +0 -27
- data/lib/Dnsruby/resource/NSEC.rb +0 -298
- data/lib/Dnsruby/resource/NSEC3.rb +0 -340
- data/lib/Dnsruby/resource/NSEC3PARAM.rb +0 -135
- data/lib/Dnsruby/resource/OPT.rb +0 -213
- data/lib/Dnsruby/resource/RRSIG.rb +0 -275
- data/lib/Dnsruby/resource/SPF.rb +0 -29
- data/lib/Dnsruby/resource/SRV.rb +0 -112
- data/lib/Dnsruby/resource/TKEY.rb +0 -163
- data/lib/Dnsruby/resource/TSIG.rb +0 -593
- data/lib/Dnsruby/resource/X25.rb +0 -55
- data/lib/Dnsruby/resource/resource.rb +0 -678
- data/lib/Dnsruby/update.rb +0 -278
- data/lib/Dnsruby/validator_thread.rb +0 -124
@@ -1,66 +1,66 @@
|
|
1
|
-
|
2
|
-
#Copyright 2007 Nominet UK
|
3
|
-
#
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
#you may not use this file except in compliance with the License.
|
6
|
-
#You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
#See the License for the specific language governing permissions and
|
14
|
-
#limitations under the License.
|
15
|
-
|
16
|
-
module Dnsruby
|
17
|
-
class RR
|
18
|
-
#Class for DNS Key Exchange (KX) resource records.
|
19
|
-
#RFC 2230
|
20
|
-
class KX < RR
|
21
|
-
ClassValue = nil #:nodoc: all
|
22
|
-
TypeValue= Types::KX #:nodoc: all
|
23
|
-
|
24
|
-
#The preference for this mail exchange.
|
25
|
-
attr_accessor :preference
|
26
|
-
#The name of this mail exchange.
|
27
|
-
attr_accessor :exchange
|
28
|
-
|
29
|
-
def from_hash(hash) #:nodoc: all
|
30
|
-
@preference = hash[:preference]
|
31
|
-
@exchange = Name.create(hash[:exchange])
|
32
|
-
end
|
33
|
-
|
34
|
-
def from_data(data) #:nodoc: all
|
35
|
-
@preference, @exchange = data
|
36
|
-
end
|
37
|
-
|
38
|
-
def from_string(input) #:nodoc: all
|
39
|
-
if (input.length > 0)
|
40
|
-
names = input.split(" ")
|
41
|
-
@preference = names[0].to_i
|
42
|
-
@exchange = Name.create(names[1])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def rdata_to_string #:nodoc: all
|
47
|
-
if (@preference!=nil)
|
48
|
-
return "#{@preference} #{@exchange.to_s(true)}"
|
49
|
-
else
|
50
|
-
return ""
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def encode_rdata(msg, canonical=false) #:nodoc: all
|
55
|
-
msg.put_pack('n', @preference)
|
56
|
-
msg.put_name(@exchange, true)
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.decode_rdata(msg) #:nodoc: all
|
60
|
-
preference, = msg.get_unpack('n')
|
61
|
-
exchange = msg.get_name
|
62
|
-
return self.new([preference, exchange])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
# --
|
2
|
+
# Copyright 2007 Nominet UK
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
module Dnsruby
|
17
|
+
class RR
|
18
|
+
# Class for DNS Key Exchange (KX) resource records.
|
19
|
+
# RFC 2230
|
20
|
+
class KX < RR
|
21
|
+
ClassValue = nil #:nodoc: all
|
22
|
+
TypeValue= Types::KX #:nodoc: all
|
23
|
+
|
24
|
+
# The preference for this mail exchange.
|
25
|
+
attr_accessor :preference
|
26
|
+
# The name of this mail exchange.
|
27
|
+
attr_accessor :exchange
|
28
|
+
|
29
|
+
def from_hash(hash) #:nodoc: all
|
30
|
+
@preference = hash[:preference]
|
31
|
+
@exchange = Name.create(hash[:exchange])
|
32
|
+
end
|
33
|
+
|
34
|
+
def from_data(data) #:nodoc: all
|
35
|
+
@preference, @exchange = data
|
36
|
+
end
|
37
|
+
|
38
|
+
def from_string(input) #:nodoc: all
|
39
|
+
if (input.length > 0)
|
40
|
+
names = input.split(" ")
|
41
|
+
@preference = names[0].to_i
|
42
|
+
@exchange = Name.create(names[1])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def rdata_to_string #:nodoc: all
|
47
|
+
if (@preference!=nil)
|
48
|
+
return "#{@preference} #{@exchange.to_s(true)}"
|
49
|
+
else
|
50
|
+
return ""
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def encode_rdata(msg, canonical=false) #:nodoc: all
|
55
|
+
msg.put_pack('n', @preference)
|
56
|
+
msg.put_name(@exchange, true)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.decode_rdata(msg) #:nodoc: all
|
60
|
+
preference, = msg.get_unpack('n')
|
61
|
+
exchange = msg.get_name
|
62
|
+
return self.new([preference, exchange])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
@@ -1,264 +1,264 @@
|
|
1
|
-
|
2
|
-
#Copyright 2007 Nominet UK
|
3
|
-
#
|
4
|
-
#Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
#you may not use this file except in compliance with the License.
|
6
|
-
#You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
#Unless required by applicable law or agreed to in writing, software
|
11
|
-
#distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
#See the License for the specific language governing permissions and
|
14
|
-
#limitations under the License.
|
15
|
-
|
16
|
-
module Dnsruby
|
17
|
-
class RR
|
18
|
-
#Class for DNS Location (LOC) resource records. See RFC 1876 for
|
19
|
-
#details.
|
20
|
-
class LOC < RR
|
21
|
-
ClassValue = nil #:nodoc: all
|
22
|
-
TypeValue = Types::LOC #:nodoc: all
|
23
|
-
|
24
|
-
#The version number of the representation; programs should
|
25
|
-
#always check this. Dnsruby currently supports only version 0.
|
26
|
-
attr_accessor :version
|
27
|
-
@version = 0
|
28
|
-
|
29
|
-
#The diameter of a sphere enclosing the described entity,
|
30
|
-
#in centimeters.
|
31
|
-
attr_accessor :size
|
32
|
-
#The horizontal precision of the data, in centimeters.
|
33
|
-
attr_accessor :horiz_pre
|
34
|
-
#The vertical precision of the data, in centimeters.
|
35
|
-
attr_accessor :vert_pre
|
36
|
-
#The latitude of the center of the sphere described by
|
37
|
-
#the size method, in thousandths of a second of arc. 2**31
|
38
|
-
#represents the equator; numbers above that are north latitude.
|
39
|
-
attr_accessor :latitude
|
40
|
-
#The longitude of the center of the sphere described by
|
41
|
-
#the size method, in thousandths of a second of arc. 2**31
|
42
|
-
#represents the prime meridian; numbers above that are east
|
43
|
-
#longitude.
|
44
|
-
attr_accessor :longitude
|
45
|
-
#The altitude of the center of the sphere described by
|
46
|
-
#the size method, in centimeters, from a base of 100,000m
|
47
|
-
#below the WGS 84 reference spheroid used by GPS.
|
48
|
-
attr_accessor :altitude
|
49
|
-
#
|
50
|
-
POWEROFTEN = [1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000]
|
51
|
-
|
52
|
-
#
|
53
|
-
REFERENCE_ALT = 100_000 * 100;
|
54
|
-
|
55
|
-
#
|
56
|
-
REFERENCE_LATLON = 2**31;
|
57
|
-
|
58
|
-
#
|
59
|
-
CONV_SEC = 1000;
|
60
|
-
CONV_MIN = 60 * CONV_SEC;
|
61
|
-
CONV_DEG = 60 * CONV_MIN;
|
62
|
-
|
63
|
-
#
|
64
|
-
DEFAULT_MIN = 0;
|
65
|
-
DEFAULT_SEC = 0;
|
66
|
-
DEFAULT_SIZE = 1;
|
67
|
-
DEFAULT_HORIZ_PRE = 10_000;
|
68
|
-
DEFAULT_VERT_PRE = 10;
|
69
|
-
|
70
|
-
|
71
|
-
def latlon2dms(rawmsec, hems)
|
72
|
-
#
|
73
|
-
#
|
74
|
-
|
75
|
-
abs = (rawmsec - REFERENCE_LATLON).abs;
|
76
|
-
deg = (abs / CONV_DEG).round;
|
77
|
-
abs -= deg * CONV_DEG;
|
78
|
-
min = (abs / CONV_MIN).round;
|
79
|
-
abs -= min * CONV_MIN;
|
80
|
-
sec = (abs / CONV_SEC).round; # $conv_sec
|
81
|
-
abs -= sec * CONV_SEC;
|
82
|
-
msec = abs;
|
83
|
-
|
84
|
-
hem = hems[(rawmsec >= REFERENCE_LATLON ? 0 : 1), 1]
|
85
|
-
|
86
|
-
return sprintf("%d %02d %02d.%03d %s", deg, min, sec, msec, hem);
|
87
|
-
end
|
88
|
-
|
89
|
-
def dms2latlon(deg, min, sec, hem)
|
90
|
-
retval=0
|
91
|
-
|
92
|
-
retval = (deg * CONV_DEG) + (min * CONV_MIN) + (sec * CONV_SEC).round;
|
93
|
-
retval = -retval if ((hem != nil) && ((hem == "S") || (hem == "W")));
|
94
|
-
retval += REFERENCE_LATLON;
|
95
|
-
return retval;
|
96
|
-
end
|
97
|
-
|
98
|
-
#Returns the latitude and longitude as floating-point degrees.
|
99
|
-
#Positive numbers represent north latitude or east longitude;
|
100
|
-
#negative numbers represent south latitude or west longitude.
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
def latlon
|
106
|
-
retlat, retlon = nil
|
107
|
-
|
108
|
-
if (@version == 0)
|
109
|
-
retlat = latlon2deg(@latitude);
|
110
|
-
retlon = latlon2deg(@longitude);
|
111
|
-
end
|
112
|
-
|
113
|
-
return retlat, retlon
|
114
|
-
end
|
115
|
-
|
116
|
-
def latlon2deg(rawmsec)
|
117
|
-
deg=0;
|
118
|
-
|
119
|
-
deg = (rawmsec - reference_latlon) / CONV_DEG;
|
120
|
-
return deg;
|
121
|
-
end
|
122
|
-
|
123
|
-
def from_data(data) #:nodoc: all
|
124
|
-
@version, @size, @horiz_pre, @vert_pre, @latitude, @longitude, @altitude = data
|
125
|
-
end
|
126
|
-
|
127
|
-
def from_string(string) #:nodoc: all
|
128
|
-
if (string &&
|
129
|
-
string =~ /^ (\d+) \s+ # deg lat
|
130
|
-
((\d+) \s+)? # min lat
|
131
|
-
(([\d.]+) \s+)? # sec lat
|
132
|
-
(N|S) \s+ # hem lat
|
133
|
-
(\d+) \s+ # deg lon
|
134
|
-
((\d+) \s+)? # min lon
|
135
|
-
(([\d.]+) \s+)? # sec lon
|
136
|
-
(E|W) \s+ # hem lon
|
137
|
-
(-?[\d.]+) m? # altitude
|
138
|
-
(\s+ ([\d.]+) m?)? # size
|
139
|
-
(\s+ ([\d.]+) m?)? # horiz precision
|
140
|
-
(\s+ ([\d.]+) m?)? # vert precision
|
141
|
-
/ix) #
|
142
|
-
|
143
|
-
size = DEFAULT_SIZE
|
144
|
-
|
145
|
-
#
|
146
|
-
version = 0;
|
147
|
-
|
148
|
-
horiz_pre = DEFAULT_HORIZ_PRE
|
149
|
-
vert_pre = DEFAULT_VERT_PRE
|
150
|
-
latdeg, latmin, latsec, lathem = $1.to_i, $3.to_i, $5.to_f, $6;
|
151
|
-
londeg, lonmin, lonsec, lonhem = $7.to_i, $9.to_i, $11.to_f, $12
|
152
|
-
alt = $13.to_i
|
153
|
-
if ($15)
|
154
|
-
size = $15.to_f
|
155
|
-
end
|
156
|
-
if ($17)
|
157
|
-
horiz_pre = $17.to_f
|
158
|
-
end
|
159
|
-
if ($19)
|
160
|
-
vert_pre = $19.to_f
|
161
|
-
end
|
162
|
-
|
163
|
-
latmin = DEFAULT_MIN unless latmin;
|
164
|
-
latsec = DEFAULT_SEC unless latsec;
|
165
|
-
lathem = lathem.upcase;
|
166
|
-
|
167
|
-
lonmin = DEFAULT_MIN unless lonmin;
|
168
|
-
lonsec = DEFAULT_SEC unless lonsec;
|
169
|
-
lonhem = lonhem.upcase
|
170
|
-
|
171
|
-
@version = version;
|
172
|
-
@size = size * 100;
|
173
|
-
@horiz_pre = horiz_pre * 100;
|
174
|
-
@vert_pre = vert_pre * 100;
|
175
|
-
@latitude = dms2latlon(latdeg, latmin, latsec, lathem);
|
176
|
-
@longitude = dms2latlon(londeg, lonmin, lonsec, lonhem);
|
177
|
-
@altitude = alt * 100 + REFERENCE_ALT;
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def from_hash(hash) #:nodoc: all
|
182
|
-
super(hash)
|
183
|
-
if (@size == nil)
|
184
|
-
@size = DEFAULT_SIZE * 100
|
185
|
-
end
|
186
|
-
if @horiz_pre == nil
|
187
|
-
@horiz_pre = DEFAULT_HORIZ_PRE * 100
|
188
|
-
end
|
189
|
-
if @vert_pre == nil
|
190
|
-
@vert_pre = DEFAULT_VERT_PRE * 100
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def rdata_to_string #:nodoc: all
|
195
|
-
rdatastr=""
|
196
|
-
|
197
|
-
if (defined?@version)
|
198
|
-
if (@version == 0)
|
199
|
-
lat = @latitude;
|
200
|
-
lon = @longitude;
|
201
|
-
altitude = @altitude;
|
202
|
-
size = @size;
|
203
|
-
horiz_pre = @horiz_pre;
|
204
|
-
vert_pre = @vert_pre;
|
205
|
-
|
206
|
-
altitude = (altitude - REFERENCE_ALT) / 100;
|
207
|
-
size /= 100;
|
208
|
-
horiz_pre /= 100;
|
209
|
-
vert_pre /= 100;
|
210
|
-
|
211
|
-
rdatastr = latlon2dms(lat, "NS") + " " +
|
212
|
-
latlon2dms(lon, "EW") + " " +
|
213
|
-
sprintf("%.2fm", altitude) + " " +
|
214
|
-
sprintf("%.2fm", size) + " " +
|
215
|
-
sprintf("%.2fm", horiz_pre) + " " +
|
216
|
-
sprintf("%.2fm", vert_pre);
|
217
|
-
else
|
218
|
-
rdatastr = "; version " + @version + " not supported";
|
219
|
-
end
|
220
|
-
else
|
221
|
-
rdatastr = '';
|
222
|
-
end
|
223
|
-
|
224
|
-
return rdatastr;
|
225
|
-
end
|
226
|
-
|
227
|
-
def self.decode_rdata(msg) #:nodoc: all
|
228
|
-
version, = msg.get_unpack("C")
|
229
|
-
if (version == 0)
|
230
|
-
size, horiz_pre, vert_pre, latitude, longitude, altitude = msg.get_unpack('CCCNNN')
|
231
|
-
size = precsize_ntoval(size)
|
232
|
-
horiz_pre = precsize_ntoval(horiz_pre)
|
233
|
-
vert_pre = precsize_ntoval(vert_pre)
|
234
|
-
return self.new([version, size, horiz_pre, vert_pre, latitude, longitude, altitude])
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
def encode_rdata(msg, canonical=false) #:nodoc: all
|
239
|
-
msg.put_pack('C', @version)
|
240
|
-
if (@version == 0)
|
241
|
-
msg.put_pack('CCCNNN', precsize_valton(@size),
|
242
|
-
precsize_valton(@horiz_pre), precsize_valton(@vert_pre),
|
243
|
-
@latitude, @longitude, @altitude)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
def self.precsize_ntoval(prec)
|
248
|
-
mantissa = ((prec >> 4) & 0x0f) % 10;
|
249
|
-
exponent = (prec & 0x0f) % 10;
|
250
|
-
return mantissa * POWEROFTEN[exponent];
|
251
|
-
end
|
252
|
-
|
253
|
-
def precsize_valton(val)
|
254
|
-
exponent = 0;
|
255
|
-
while (val >= 10)
|
256
|
-
val /= 10;
|
257
|
-
exponent+=1
|
258
|
-
end
|
259
|
-
return (val.round << 4) | (exponent & 0x0f);
|
260
|
-
end
|
261
|
-
|
262
|
-
end
|
263
|
-
end
|
1
|
+
# --
|
2
|
+
# Copyright 2007 Nominet UK
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
module Dnsruby
|
17
|
+
class RR
|
18
|
+
# Class for DNS Location (LOC) resource records. See RFC 1876 for
|
19
|
+
# details.
|
20
|
+
class LOC < RR
|
21
|
+
ClassValue = nil #:nodoc: all
|
22
|
+
TypeValue = Types::LOC #:nodoc: all
|
23
|
+
|
24
|
+
# The version number of the representation; programs should
|
25
|
+
# always check this. Dnsruby currently supports only version 0.
|
26
|
+
attr_accessor :version
|
27
|
+
@version = 0
|
28
|
+
|
29
|
+
# The diameter of a sphere enclosing the described entity,
|
30
|
+
# in centimeters.
|
31
|
+
attr_accessor :size
|
32
|
+
# The horizontal precision of the data, in centimeters.
|
33
|
+
attr_accessor :horiz_pre
|
34
|
+
# The vertical precision of the data, in centimeters.
|
35
|
+
attr_accessor :vert_pre
|
36
|
+
# The latitude of the center of the sphere described by
|
37
|
+
# the size method, in thousandths of a second of arc. 2**31
|
38
|
+
# represents the equator; numbers above that are north latitude.
|
39
|
+
attr_accessor :latitude
|
40
|
+
# The longitude of the center of the sphere described by
|
41
|
+
# the size method, in thousandths of a second of arc. 2**31
|
42
|
+
# represents the prime meridian; numbers above that are east
|
43
|
+
# longitude.
|
44
|
+
attr_accessor :longitude
|
45
|
+
# The altitude of the center of the sphere described by
|
46
|
+
# the size method, in centimeters, from a base of 100,000m
|
47
|
+
# below the WGS 84 reference spheroid used by GPS.
|
48
|
+
attr_accessor :altitude
|
49
|
+
# Powers of 10 from 0 to 9 (used to speed up calculations).
|
50
|
+
POWEROFTEN = [1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000]
|
51
|
+
|
52
|
+
# Reference altitude in centimeters (see RFC 1876).
|
53
|
+
REFERENCE_ALT = 100_000 * 100;
|
54
|
+
|
55
|
+
# Reference lat/lon (see RFC 1876).
|
56
|
+
REFERENCE_LATLON = 2**31;
|
57
|
+
|
58
|
+
# Conversions to/from thousandths of a degree.
|
59
|
+
CONV_SEC = 1000;
|
60
|
+
CONV_MIN = 60 * CONV_SEC;
|
61
|
+
CONV_DEG = 60 * CONV_MIN;
|
62
|
+
|
63
|
+
# Defaults (from RFC 1876, Section 3).
|
64
|
+
DEFAULT_MIN = 0;
|
65
|
+
DEFAULT_SEC = 0;
|
66
|
+
DEFAULT_SIZE = 1;
|
67
|
+
DEFAULT_HORIZ_PRE = 10_000;
|
68
|
+
DEFAULT_VERT_PRE = 10;
|
69
|
+
|
70
|
+
|
71
|
+
def latlon2dms(rawmsec, hems)
|
72
|
+
# Tried to use modulus here, but Perl dumped core if
|
73
|
+
# the value was >= 2**31.
|
74
|
+
|
75
|
+
abs = (rawmsec - REFERENCE_LATLON).abs;
|
76
|
+
deg = (abs / CONV_DEG).round;
|
77
|
+
abs -= deg * CONV_DEG;
|
78
|
+
min = (abs / CONV_MIN).round;
|
79
|
+
abs -= min * CONV_MIN;
|
80
|
+
sec = (abs / CONV_SEC).round; # $conv_sec
|
81
|
+
abs -= sec * CONV_SEC;
|
82
|
+
msec = abs;
|
83
|
+
|
84
|
+
hem = hems[(rawmsec >= REFERENCE_LATLON ? 0 : 1), 1]
|
85
|
+
|
86
|
+
return sprintf("%d %02d %02d.%03d %s", deg, min, sec, msec, hem);
|
87
|
+
end
|
88
|
+
|
89
|
+
def dms2latlon(deg, min, sec, hem)
|
90
|
+
retval=0
|
91
|
+
|
92
|
+
retval = (deg * CONV_DEG) + (min * CONV_MIN) + (sec * CONV_SEC).round;
|
93
|
+
retval = -retval if ((hem != nil) && ((hem == "S") || (hem == "W")));
|
94
|
+
retval += REFERENCE_LATLON;
|
95
|
+
return retval;
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the latitude and longitude as floating-point degrees.
|
99
|
+
# Positive numbers represent north latitude or east longitude;
|
100
|
+
# negative numbers represent south latitude or west longitude.
|
101
|
+
#
|
102
|
+
# lat, lon = rr.latlon
|
103
|
+
# system("xearth", "-pos", "fixed #{lat} #{lon}")
|
104
|
+
#
|
105
|
+
def latlon
|
106
|
+
retlat, retlon = nil
|
107
|
+
|
108
|
+
if (@version == 0)
|
109
|
+
retlat = latlon2deg(@latitude);
|
110
|
+
retlon = latlon2deg(@longitude);
|
111
|
+
end
|
112
|
+
|
113
|
+
return retlat, retlon
|
114
|
+
end
|
115
|
+
|
116
|
+
def latlon2deg(rawmsec)
|
117
|
+
deg=0;
|
118
|
+
|
119
|
+
deg = (rawmsec - reference_latlon) / CONV_DEG;
|
120
|
+
return deg;
|
121
|
+
end
|
122
|
+
|
123
|
+
def from_data(data) #:nodoc: all
|
124
|
+
@version, @size, @horiz_pre, @vert_pre, @latitude, @longitude, @altitude = data
|
125
|
+
end
|
126
|
+
|
127
|
+
def from_string(string) #:nodoc: all
|
128
|
+
if (string &&
|
129
|
+
string =~ /^ (\d+) \s+ # deg lat
|
130
|
+
((\d+) \s+)? # min lat
|
131
|
+
(([\d.]+) \s+)? # sec lat
|
132
|
+
(N|S) \s+ # hem lat
|
133
|
+
(\d+) \s+ # deg lon
|
134
|
+
((\d+) \s+)? # min lon
|
135
|
+
(([\d.]+) \s+)? # sec lon
|
136
|
+
(E|W) \s+ # hem lon
|
137
|
+
(-?[\d.]+) m? # altitude
|
138
|
+
(\s+ ([\d.]+) m?)? # size
|
139
|
+
(\s+ ([\d.]+) m?)? # horiz precision
|
140
|
+
(\s+ ([\d.]+) m?)? # vert precision
|
141
|
+
/ix) #
|
142
|
+
|
143
|
+
size = DEFAULT_SIZE
|
144
|
+
|
145
|
+
# What to do for other versions?
|
146
|
+
version = 0;
|
147
|
+
|
148
|
+
horiz_pre = DEFAULT_HORIZ_PRE
|
149
|
+
vert_pre = DEFAULT_VERT_PRE
|
150
|
+
latdeg, latmin, latsec, lathem = $1.to_i, $3.to_i, $5.to_f, $6;
|
151
|
+
londeg, lonmin, lonsec, lonhem = $7.to_i, $9.to_i, $11.to_f, $12
|
152
|
+
alt = $13.to_i
|
153
|
+
if ($15)
|
154
|
+
size = $15.to_f
|
155
|
+
end
|
156
|
+
if ($17)
|
157
|
+
horiz_pre = $17.to_f
|
158
|
+
end
|
159
|
+
if ($19)
|
160
|
+
vert_pre = $19.to_f
|
161
|
+
end
|
162
|
+
|
163
|
+
latmin = DEFAULT_MIN unless latmin;
|
164
|
+
latsec = DEFAULT_SEC unless latsec;
|
165
|
+
lathem = lathem.upcase;
|
166
|
+
|
167
|
+
lonmin = DEFAULT_MIN unless lonmin;
|
168
|
+
lonsec = DEFAULT_SEC unless lonsec;
|
169
|
+
lonhem = lonhem.upcase
|
170
|
+
|
171
|
+
@version = version;
|
172
|
+
@size = size * 100;
|
173
|
+
@horiz_pre = horiz_pre * 100;
|
174
|
+
@vert_pre = vert_pre * 100;
|
175
|
+
@latitude = dms2latlon(latdeg, latmin, latsec, lathem);
|
176
|
+
@longitude = dms2latlon(londeg, lonmin, lonsec, lonhem);
|
177
|
+
@altitude = alt * 100 + REFERENCE_ALT;
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def from_hash(hash) #:nodoc: all
|
182
|
+
super(hash)
|
183
|
+
if (@size == nil)
|
184
|
+
@size = DEFAULT_SIZE * 100
|
185
|
+
end
|
186
|
+
if @horiz_pre == nil
|
187
|
+
@horiz_pre = DEFAULT_HORIZ_PRE * 100
|
188
|
+
end
|
189
|
+
if @vert_pre == nil
|
190
|
+
@vert_pre = DEFAULT_VERT_PRE * 100
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def rdata_to_string #:nodoc: all
|
195
|
+
rdatastr=""
|
196
|
+
|
197
|
+
if (defined?@version)
|
198
|
+
if (@version == 0)
|
199
|
+
lat = @latitude;
|
200
|
+
lon = @longitude;
|
201
|
+
altitude = @altitude;
|
202
|
+
size = @size;
|
203
|
+
horiz_pre = @horiz_pre;
|
204
|
+
vert_pre = @vert_pre;
|
205
|
+
|
206
|
+
altitude = (altitude - REFERENCE_ALT) / 100;
|
207
|
+
size /= 100;
|
208
|
+
horiz_pre /= 100;
|
209
|
+
vert_pre /= 100;
|
210
|
+
|
211
|
+
rdatastr = latlon2dms(lat, "NS") + " " +
|
212
|
+
latlon2dms(lon, "EW") + " " +
|
213
|
+
sprintf("%.2fm", altitude) + " " +
|
214
|
+
sprintf("%.2fm", size) + " " +
|
215
|
+
sprintf("%.2fm", horiz_pre) + " " +
|
216
|
+
sprintf("%.2fm", vert_pre);
|
217
|
+
else
|
218
|
+
rdatastr = "; version " + @version + " not supported";
|
219
|
+
end
|
220
|
+
else
|
221
|
+
rdatastr = '';
|
222
|
+
end
|
223
|
+
|
224
|
+
return rdatastr;
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.decode_rdata(msg) #:nodoc: all
|
228
|
+
version, = msg.get_unpack("C")
|
229
|
+
if (version == 0)
|
230
|
+
size, horiz_pre, vert_pre, latitude, longitude, altitude = msg.get_unpack('CCCNNN')
|
231
|
+
size = precsize_ntoval(size)
|
232
|
+
horiz_pre = precsize_ntoval(horiz_pre)
|
233
|
+
vert_pre = precsize_ntoval(vert_pre)
|
234
|
+
return self.new([version, size, horiz_pre, vert_pre, latitude, longitude, altitude])
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
def encode_rdata(msg, canonical=false) #:nodoc: all
|
239
|
+
msg.put_pack('C', @version)
|
240
|
+
if (@version == 0)
|
241
|
+
msg.put_pack('CCCNNN', precsize_valton(@size),
|
242
|
+
precsize_valton(@horiz_pre), precsize_valton(@vert_pre),
|
243
|
+
@latitude, @longitude, @altitude)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.precsize_ntoval(prec)
|
248
|
+
mantissa = ((prec >> 4) & 0x0f) % 10;
|
249
|
+
exponent = (prec & 0x0f) % 10;
|
250
|
+
return mantissa * POWEROFTEN[exponent];
|
251
|
+
end
|
252
|
+
|
253
|
+
def precsize_valton(val)
|
254
|
+
exponent = 0;
|
255
|
+
while (val >= 10)
|
256
|
+
val /= 10;
|
257
|
+
exponent+=1
|
258
|
+
end
|
259
|
+
return (val.round << 4) | (exponent & 0x0f);
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
end
|
264
264
|
end
|