Sha256: b03c938df8d9122d90115b2992098d7b7f3b32abba5186b3a55a8bdeb148b439
Contents?: true
Size: 1.12 KB
Versions: 3
Compression:
Stored size: 1.12 KB
Contents
require 'strscan' class PacketViaDMEM PACKET = /^(Received|Sent) \d+ byte parcel:.*\n/ FAKE = { :dmac => %w( 22 22 22 22 22 22 ), :smac => %w( 66 66 66 66 66 66 ), :etype_mpls => %w( 88 47 ), :etype_ipv4 => %w( 08 00 ), :ipv4 => %w( 45 ), } HEADER_SIZE = { :received => 6, :sent => 13, } class Error < StandardError; end def initialize opts={} @received = opts.delete :received @sent = opts.delete :sent @received ||= HEADER_SIZE[:received] @sc = StringScanner.new '' end def parse str packets = Packets.new @sc.string = str while @sc.scan_until PACKET match = @sc.matched.split(/\s+/) type = match.first.downcase.to_sym @sc.scan_until(/\n/) if type == :received pkt = '' while @sc.match?(/^0x/) pkt << @sc.scan_until(/\n/).strip end pkt = parse_packet pkt packets.add pkt, type end packets end private def parse_packet pkt pkt = pkt.gsub(/0x/, '') pkt = pkt.gsub(/\s+/, '') pkt = pkt.scan(/../) pkt end end require_relative 'packet_via_dmem/packets'
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
packet_via_dmem-0.0.6 | lib/packet_via_dmem.rb |
packet_via_dmem-0.0.5 | lib/packet_via_dmem.rb |
packet_via_dmem-0.0.4 | lib/packet_via_dmem.rb |