Updating PacketFu to match upstream
parent
71d2ef71f8
commit
b8129f9463
|
@ -1,6 +1,6 @@
|
|||
== LICENSE
|
||||
|
||||
Copyright (c) 2008-2011, Tod Beardsley
|
||||
Copyright (c) 2008-2012, Tod Beardsley
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -265,8 +265,11 @@ module PacketFu
|
|||
warn "Packet ##{packet_count} is corrupted: expected #{len.to_i}, got #{pcap_packet.data.size}. Exiting."
|
||||
break
|
||||
end
|
||||
pcap_packets << pcap_packet.clone
|
||||
yield pcap_packets.last if block
|
||||
if block
|
||||
yield pcap_packet
|
||||
else
|
||||
pcap_packets << pcap_packet.clone
|
||||
end
|
||||
end
|
||||
ensure
|
||||
file_handle.close
|
||||
|
@ -317,6 +320,7 @@ module PacketFu
|
|||
|
||||
def initialize(args={})
|
||||
init_fields(args)
|
||||
@filename = args.delete :filename
|
||||
super(args[:endian], args[:head], args[:body])
|
||||
end
|
||||
|
||||
|
@ -361,6 +365,18 @@ module PacketFu
|
|||
self.read! fdata
|
||||
end
|
||||
|
||||
# Calls the class method with this object's @filename
|
||||
def read_packet_bytes(fname=@filename,&block)
|
||||
raise ArgumentError, "Need a file" unless fname
|
||||
return self.class.read_packet_bytes(fname, &block)
|
||||
end
|
||||
|
||||
# Calls the class method with this object's @filename
|
||||
def read_packets(fname=@filename,&block)
|
||||
raise ArgumentError, "Need a file" unless fname
|
||||
return self.class.read_packets(fname, &block)
|
||||
end
|
||||
|
||||
# file_to_array() translates a libpcap file into an array of packets.
|
||||
# Note that this strips out pcap timestamps -- if you'd like to retain
|
||||
# timestamps and other libpcap file information, you will want to
|
||||
|
|
|
@ -132,7 +132,7 @@ module PacketFu
|
|||
# method that returns an array rather than just the first candidate.
|
||||
end
|
||||
|
||||
# Handles ifconfig for various (okay, one) platforms. Mac guys, fix this and submit a patch!
|
||||
# Handles ifconfig for various (okay, two) platforms.
|
||||
# Will have Windows done shortly.
|
||||
#
|
||||
# Takes an argument (either string or symbol) of the interface to look up, and
|
||||
|
@ -182,8 +182,32 @@ module PacketFu
|
|||
ret[:ip6_saddr] = $1
|
||||
ret[:ip6_obj] = IPAddr.new($1)
|
||||
end
|
||||
end # linux
|
||||
when /darwin/i
|
||||
ifconfig_data = %x[ifconfig #{iface}]
|
||||
if ifconfig_data =~ /#{iface}/i
|
||||
ifconfig_data = ifconfig_data.split(/[\s]*\n[\s]*/)
|
||||
else
|
||||
raise ArgumentError, "Cannot ifconfig #{iface}"
|
||||
end
|
||||
end # linux
|
||||
real_iface = ifconfig_data.first
|
||||
ret[:iface] = real_iface.split(':')[0]
|
||||
ifconfig_data.each do |s|
|
||||
case s
|
||||
when /ether[\s]([0-9a-fA-F:]{17})/i
|
||||
ret[:eth_saddr] = $1
|
||||
ret[:eth_src] = EthHeader.mac2str(ret[:eth_saddr])
|
||||
when /inet[\s]*([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)(.*Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+))?/i
|
||||
ret[:ip_saddr] = $1
|
||||
ret[:ip_src] = [IPAddr.new($1).to_i].pack("N")
|
||||
ret[:ip4_obj] = IPAddr.new($1)
|
||||
ret[:ip4_obj] = ret[:ip4_obj].mask($3) if $3
|
||||
when /inet6[\s]*([0-9a-fA-F:\x2f]+)/
|
||||
ret[:ip6_saddr] = $1
|
||||
ret[:ip6_obj] = IPAddr.new($1)
|
||||
end
|
||||
end # darwin
|
||||
end # RUBY_PLATFORM
|
||||
ret
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module PacketFu
|
||||
|
||||
# Check the repo's for version release histories
|
||||
VERSION = "1.1.3" # Unscrewing the 1.1.2 gem
|
||||
VERSION = "1.1.5" # Unscrewing the 1.1.4 gem
|
||||
|
||||
# Returns PacketFu::VERSION
|
||||
def self.version
|
||||
|
|
Loading…
Reference in New Issue