Updating PacketFu to match upstream

unstable
Tod Beardsley 2012-04-09 15:46:47 -05:00
parent 71d2ef71f8
commit b8129f9463
4 changed files with 46 additions and 6 deletions

View File

@ -1,6 +1,6 @@
== LICENSE == LICENSE
Copyright (c) 2008-2011, Tod Beardsley Copyright (c) 2008-2012, Tod Beardsley
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -265,8 +265,11 @@ module PacketFu
warn "Packet ##{packet_count} is corrupted: expected #{len.to_i}, got #{pcap_packet.data.size}. Exiting." warn "Packet ##{packet_count} is corrupted: expected #{len.to_i}, got #{pcap_packet.data.size}. Exiting."
break break
end end
pcap_packets << pcap_packet.clone if block
yield pcap_packets.last if block yield pcap_packet
else
pcap_packets << pcap_packet.clone
end
end end
ensure ensure
file_handle.close file_handle.close
@ -317,6 +320,7 @@ module PacketFu
def initialize(args={}) def initialize(args={})
init_fields(args) init_fields(args)
@filename = args.delete :filename
super(args[:endian], args[:head], args[:body]) super(args[:endian], args[:head], args[:body])
end end
@ -361,6 +365,18 @@ module PacketFu
self.read! fdata self.read! fdata
end 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. # 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 # Note that this strips out pcap timestamps -- if you'd like to retain
# timestamps and other libpcap file information, you will want to # timestamps and other libpcap file information, you will want to

View File

@ -132,7 +132,7 @@ module PacketFu
# method that returns an array rather than just the first candidate. # method that returns an array rather than just the first candidate.
end 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. # Will have Windows done shortly.
# #
# Takes an argument (either string or symbol) of the interface to look up, and # 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_saddr] = $1
ret[:ip6_obj] = IPAddr.new($1) ret[:ip6_obj] = IPAddr.new($1)
end 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
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 ret
end end

View File

@ -1,7 +1,7 @@
module PacketFu module PacketFu
# Check the repo's for version release histories # 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 # Returns PacketFu::VERSION
def self.version def self.version