Class: Net::DNS::RR::LOC
- Inherits:
-
Net::DNS::RR
- Object
- Net::DNS::RR
- Net::DNS::RR::LOC
- Defined in:
- lib/Net/DNS/RR/LOC.rb
Overview
NAME
Net::DNS::RR::LOC - DNS LOC resource record
head1 DESCRIPTION
Class for DNS Location (LOC) resource records. See RFC 1876 for details.
head1 COPYRIGHT
Copyright © 1997-2002 Michael Fuhr.
Portions Copyright © 2002-2004 Chris Reinhardt.
Ruby version Copyright © 2006 AlexD (Nominet UK)
All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Some of the code and documentation is based on RFC 1876 and on code contributed by Christopher Davis.
SEE ALSO
Net::DNS, Net::DNS::Resolver, Net::DNS::Packet, Net::DNS::Header, Net::DNS::Question, Net::DNS::RR, RFC 1876
Constant Summary collapse
- POWEROFTEN =
Powers of 10 from 0 to 9 (used to speed up calculations).
[1, 10, 100, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000]
- REFERENCE_ALT =
Reference altitude in centimeters (see RFC 1876).
100_000 * 100
- REFERENCE_LATLON =
Reference lat/lon (see RFC 1876).
2**31
- CONV_SEC =
Conversions to/from thousandths of a degree.
1000
- CONV_MIN =
60 * CONV_SEC
- CONV_DEG =
60 * CONV_MIN
- DEFAULT_MIN =
Defaults (from RFC 1876, Section 3).
0
- DEFAULT_SEC =
0
- DEFAULT_SIZE =
1
- DEFAULT_HORIZ_PRE =
10_000
- DEFAULT_VERT_PRE =
10
Constants inherited from Net::DNS::RR
Instance Attribute Summary collapse
-
#altitude ⇒ Object
Returns the altitude of the center of the sphere described by the size method, in centimeters, from a base of 100,000m below the WGS 84 reference spheroid used by GPS.
-
#horiz_pre ⇒ Object
Returns the horizontal precision of the data, in centimeters.
-
#latitude ⇒ Object
Returns the latitude of the center of the sphere described by the size method, in thousandths of a second of arc.
-
#longitude ⇒ Object
Returns the longitude of the center of the sphere described by the size method, in thousandths of a second of arc.
-
#size ⇒ Object
Returns the diameter of a sphere enclosing the described entity, in centimeters.
-
#version ⇒ Object
Returns the version number of the representation; programs should always check this.
-
#vert_pre ⇒ Object
Returns the vertical precision of the data, in centimeters.
Attributes inherited from Net::DNS::RR
#name, #rdata, #rdlength, #rrclass, #ttl, #type
Instance Method Summary collapse
- #dms2latlon(deg, min, sec, hem) ⇒ Object
-
#latlon ⇒ Object
Returns the latitude and longitude as floating-point degrees.
- #latlon2deg(rawmsec) ⇒ Object
- #latlon2dms(rawmsec, hems) ⇒ Object
- #new_from_data(data, offset) ⇒ Object
- #new_from_hash(values) ⇒ Object
- #new_from_string(string) ⇒ Object
- #precsize_ntoval(prec) ⇒ Object
- #precsize_valton(val) ⇒ Object
- #rdatastr ⇒ Object
- #rr_rdata(*args) ⇒ Object
Methods inherited from Net::DNS::RR
#_canonicalRdata, #_canonicaldata, _get_subclass, _name2wire, #_name2wire, build_regex, create, #create_rrsort_func, #data, #get_rrsort_func, #init, #init_rrsort_func, #inspect, new_from_data, new_from_hash, new_from_string, #set_rrsort_func
Instance Attribute Details
#altitude ⇒ Object
Returns the altitude of the center of the sphere described by the size method, in centimeters, from a base of 100,000m below the WGS 84 reference spheroid used by GPS.
print "altitude = ", rr.altitude, "\n"
90 91 92 |
# File 'lib/Net/DNS/RR/LOC.rb', line 90 def altitude @altitude end |
#horiz_pre ⇒ Object
Returns the horizontal precision of the data, in centimeters.
print "horiz_pre = ", rr.horiz_pre, "\n"
63 64 65 |
# File 'lib/Net/DNS/RR/LOC.rb', line 63 def horiz_pre @horiz_pre end |
#latitude ⇒ Object
Returns the latitude of the center of the sphere described by the size method, in thousandths of a second of arc. 2**31 represents the equator; numbers above that are north latitude.
print "latitude = ", rr.latitude, "\n"
75 76 77 |
# File 'lib/Net/DNS/RR/LOC.rb', line 75 def latitude @latitude end |
#longitude ⇒ Object
Returns the longitude of the center of the sphere described by the size method, in thousandths of a second of arc. 2**31 represents the prime meridian; numbers above that are east longitude.
print "longitude = ", rr.longitude, "\n"
83 84 85 |
# File 'lib/Net/DNS/RR/LOC.rb', line 83 def longitude @longitude end |
#size ⇒ Object
Returns the diameter of a sphere enclosing the described entity, in centimeters.
print "size = ", rr.size, "\n"
58 59 60 |
# File 'lib/Net/DNS/RR/LOC.rb', line 58 def size @size end |
#version ⇒ Object
Returns the version number of the representation; programs should always check this. C<Net::DNS> currently supports only version 0.
print "version = ", rr.version, "\n"
52 53 54 |
# File 'lib/Net/DNS/RR/LOC.rb', line 52 def version @version end |
#vert_pre ⇒ Object
Returns the vertical precision of the data, in centimeters.
print "vert_pre = ", rr.vert_pre, "\n"
68 69 70 |
# File 'lib/Net/DNS/RR/LOC.rb', line 68 def vert_pre @vert_pre end |
Instance Method Details
#dms2latlon(deg, min, sec, hem) ⇒ Object
305 306 307 308 309 310 311 312 |
# File 'lib/Net/DNS/RR/LOC.rb', line 305 def dms2latlon(deg, min, sec, hem) retval=0 retval = (deg * CONV_DEG) + (min * CONV_MIN) + (sec * CONV_SEC); retval = -retval if ((hem != nil) && ((hem == "S") || (hem == "W"))); retval += REFERENCE_LATLON; return retval; end |
#latlon ⇒ Object
Returns the latitude and longitude as floating-point degrees. Positive numbers represent north latitude or east longitude; negative numbers represent south latitude or west longitude.
lat, lon = rr.latlon
system("xearth", "-pos", "fixed #{lat} #{lon}")
321 322 323 324 325 326 327 328 329 330 |
# File 'lib/Net/DNS/RR/LOC.rb', line 321 def latlon retlat, retlon = nil if (@version == 0) retlat = latlon2deg(@latitude); retlon = latlon2deg(@longitude); end return retlat, retlon end |
#latlon2deg(rawmsec) ⇒ Object
332 333 334 335 336 337 |
# File 'lib/Net/DNS/RR/LOC.rb', line 332 def latlon2deg(rawmsec) deg=0; deg = (rawmsec - reference_latlon) / CONV_DEG; return deg; end |
#latlon2dms(rawmsec, hems) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/Net/DNS/RR/LOC.rb', line 287 def latlon2dms(rawmsec, hems) # Tried to use modulus here, but Perl dumped core if # the value was >= 2**31. abs = (rawmsec - REFERENCE_LATLON).abs; deg = (abs / CONV_DEG).round; abs -= deg * CONV_DEG; min = (abs / CONV_MIN).round; abs -= min * CONV_MIN; sec = (abs / CONV_SEC).round; # $conv_sec abs -= sec * CONV_SEC; msec = abs; hem = hems[(rawmsec >= REFERENCE_LATLON ? 0 : 1), 1] return sprintf("%d %02d %02d.%03d %s", deg, min, sec, msec, hem); end |
#new_from_data(data, offset) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/Net/DNS/RR/LOC.rb', line 112 def new_from_data(data, offset) if (@rdlength > 0) version = data.unpack("\@#{offset} C")[0] offset+=1 @version = version; if (version == 0) size = data.unpack("\@#{offset} C")[0]; @size = precsize_ntoval(size); offset+=1; horiz_pre = data.unpack("\@#{offset} C")[0]; @horiz_pre = precsize_ntoval(horiz_pre); offset+=1; vert_pre = data.unpack("\@#{offset} C")[0]; @vert_pre = precsize_ntoval(vert_pre); offset+=1 @latitude = data.unpack("\@#{offset} N")[0]; offset += Net::DNS::INT32SZ; @longitude = data.unpack("\@#{offset} N")[0]; offset += Net::DNS::INT32SZ; @altitude = data.unpack("\@#{offset} N")[0] offset += Net::DNS::INT32SZ; else # What to do for unsupported versions? end end end |
#new_from_hash(values) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/Net/DNS/RR/LOC.rb', line 146 def new_from_hash(values) if values.has_key?(:size) @size = values[:size] else @size = DEFAULT_SIZE end if values.has_key?(:horiz_pre) @horiz_pre = values[:horiz_pre] else @horiz_pre = DEFAULT_HORIZ_PRE * 100 end if values.has_key?(:vert_pre) @vert_pre = values[:vert_pre] else @vert_pre = DEFAULT_VERT_PRE * 100 end if values.has_key?(:latitude) @latitude = values[:latitude] end if values.has_key?(:longitude) @longitude = values[:longitude] end if values.has_key?(:altitude) @altitude = values[:altitude] end if values.has_key?(:version) @version = values[:version] # else # @version = DEFAULT_VERSION end end |
#new_from_string(string) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/Net/DNS/RR/LOC.rb', line 178 def new_from_string(string) if (string && string =~ /^ (\d+) \s+ # deg lat ((\d+) \s+)? # min lat (([\d.]+) \s+)? # sec lat (N|S) \s+ # hem lat (\d+) \s+ # deg lon ((\d+) \s+)? # min lon (([\d.]+) \s+)? # sec lon (E|W) \s+ # hem lon (-?[\d.]+) m? # altitude (\s+ ([\d.]+) m?)? # size (\s+ ([\d.]+) m?)? # horiz precision (\s+ ([\d.]+) m?)? # vert precision /ix) # # What to do for other versions? version = 0; latdeg, latmin, latsec, lathem = $1.to_i, $3.to_i, $5.to_i, $6; londeg, lonmin, lonsec, lonhem = $7.to_i, $9.to_i, $11.to_i, $12 alt, size, horiz_pre, vert_pre = $13.to_i, $15.to_i, $17.to_i, $19.to_i latmin = DEFAULT_MIN unless latmin; latsec = DEFAULT_SEC unless latsec; lathem = lathem.upcase; lonmin = DEFAULT_MIN unless lonmin; lonsec = DEFAULT_SEC unless lonsec; lonhem = lonhem.upcase size = DEFAULT_SIZE unless size; horiz_pre = DEFAULT_HORIZ_PRE unless horiz_pre; vert_pre = DEFAULT_VERT_PRE unless vert_pre; @version = version; @size = size * 100; @horiz_pre = horiz_pre * 100; @vert_pre = vert_pre * 100; @latitude = dms2latlon(latdeg, latmin, latsec, lathem); @longitude = dms2latlon(londeg, lonmin, lonsec, lonhem); @altitude = alt * 100 + REFERENCE_ALT; end end |
#precsize_ntoval(prec) ⇒ Object
272 273 274 275 276 |
# File 'lib/Net/DNS/RR/LOC.rb', line 272 def precsize_ntoval(prec) mantissa = ((prec >> 4) & 0x0f) % 10; exponent = (prec & 0x0f) % 10; return mantissa * POWEROFTEN[exponent]; end |
#precsize_valton(val) ⇒ Object
278 279 280 281 282 283 284 285 |
# File 'lib/Net/DNS/RR/LOC.rb', line 278 def precsize_valton(val) exponent = 0; while (val >= 10) val /= 10; exponent+=1 end return (val.round << 4) | (exponent & 0x0f); end |
#rdatastr ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/Net/DNS/RR/LOC.rb', line 223 def rdatastr rdatastr="" if (defined?@version) if (@version == 0) lat = @latitude; lon = @longitude; altitude = @altitude; size = @size; horiz_pre = @horiz_pre; vert_pre = @vert_pre; altitude = (altitude - REFERENCE_ALT) / 100; size /= 100; horiz_pre /= 100; vert_pre /= 100; rdatastr = latlon2dms(lat, "NS") + " " + latlon2dms(lon, "EW") + " " + sprintf("%.2fm", altitude) + " " + sprintf("%.2fm", size) + " " + sprintf("%.2fm", horiz_pre) + " " + sprintf("%.2fm", vert_pre); else rdatastr = "; version " + @version + " not supported"; end else rdatastr = ''; end return rdatastr; end |
#rr_rdata(*args) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/Net/DNS/RR/LOC.rb', line 256 def rr_rdata(*args) rdata = ""; if (defined?@version) rdata += [@version].pack("C"); if (@version == 0) rdata += [precsize_valton(@size), precsize_valton(@horiz_pre), precsize_valton(@vert_pre)].pack("C3"); rdata += [@latitude, @longitude, @altitude].pack("N3"); else # What to do for other versions? end end return rdata; end |