Class: Resolv::DNS::Message::MessageDecoder
- Inherits:
-
Object
- Object
- Resolv::DNS::Message::MessageDecoder
- Defined in:
- lib/logmerge/resolv.rb
Instance Method Summary collapse
- #get_bytes(len = @limit - @index) ⇒ Object
- #get_label ⇒ Object
- #get_labels(limit = nil) ⇒ Object
- #get_length16 ⇒ Object
- #get_name ⇒ Object
- #get_question ⇒ Object
- #get_rr ⇒ Object
- #get_string ⇒ Object
- #get_string_list ⇒ Object
- #get_unpack(template) ⇒ Object
-
#initialize(data) {|_self| ... } ⇒ MessageDecoder
constructor
A new instance of MessageDecoder.
Constructor Details
#initialize(data) {|_self| ... } ⇒ MessageDecoder
Returns a new instance of MessageDecoder.
1255 1256 1257 1258 1259 1260 |
# File 'lib/logmerge/resolv.rb', line 1255 def initialize(data) @data = data @index = 0 @limit = data.length yield self end |
Instance Method Details
#get_bytes(len = @limit - @index) ⇒ Object
1276 1277 1278 1279 1280 |
# File 'lib/logmerge/resolv.rb', line 1276 def get_bytes(len = @limit - @index) d = @data[@index, len] @index += len return d end |
#get_label ⇒ Object
1347 1348 1349 |
# File 'lib/logmerge/resolv.rb', line 1347 def get_label return Label::Str.new(self.get_string) end |
#get_labels(limit = nil) ⇒ Object
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 |
# File 'lib/logmerge/resolv.rb', line 1322 def get_labels(limit=nil) limit = @index if !limit || @index < limit d = [] while true case @data[@index] when 0 @index += 1 return d when 192..255 idx = self.get_unpack('n')[0] & 0x3fff if limit <= idx raise DecodeError.new("non-backward name pointer") end save_index = @index @index = idx d += self.get_labels(limit) @index = save_index return d else d << self.get_label end end return d end |
#get_length16 ⇒ Object
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 |
# File 'lib/logmerge/resolv.rb', line 1262 def get_length16 len, = self.get_unpack('n') save_limit = @limit @limit = @index + len d = yield(len) if @index < @limit raise DecodeError.new("junk exists") elsif @limit < @index raise DecodeError.new("limit exceeded") end @limit = save_limit return d end |
#get_name ⇒ Object
1318 1319 1320 |
# File 'lib/logmerge/resolv.rb', line 1318 def get_name return Name.new(self.get_labels) end |
#get_question ⇒ Object
1351 1352 1353 1354 1355 |
# File 'lib/logmerge/resolv.rb', line 1351 def get_question name = self.get_name type, klass = self.get_unpack("nn") return name, Resource.get_class(type, klass) end |
#get_rr ⇒ Object
1357 1358 1359 1360 1361 1362 1363 1364 |
# File 'lib/logmerge/resolv.rb', line 1357 def get_rr name = self.get_name type, klass, ttl = self.get_unpack('nnN') typeclass = Resource.get_class(type, klass) res = self.get_length16 { typeclass.decode_rdata self } res.instance_variable_set :@ttl, ttl return name, ttl, res end |
#get_string ⇒ Object
1302 1303 1304 1305 1306 1307 1308 |
# File 'lib/logmerge/resolv.rb', line 1302 def get_string len = @data[@index] raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len d = @data[@index + 1, len] @index += 1 + len return d end |
#get_string_list ⇒ Object
1310 1311 1312 1313 1314 1315 1316 |
# File 'lib/logmerge/resolv.rb', line 1310 def get_string_list strings = [] while @index < @limit strings << self.get_string end strings end |
#get_unpack(template) ⇒ Object
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 |
# File 'lib/logmerge/resolv.rb', line 1282 def get_unpack(template) len = 0 template.each_byte {|byte| case byte when ?c, ?C len += 1 when ?n len += 2 when ?N len += 4 else raise StandardError.new("unsupported template: '#{byte.chr}' in '#{template}'") end } raise DecodeError.new("limit exceeded") if @limit < @index + len arr = @data.unpack("@#{@index}#{template}") @index += len return arr end |