Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds Packet#dissect() and Packet#dissect_table() so reading packets w…

…ith your eyeballs or with some other rendering device is much easier.

git-svn-id: https://packetfu.googlecode.com/svn/trunk@172 ebf01b17-4b54-0410-ae1b-bdaaa366248d
  • Loading branch information...
commit 75d7dad6797343b9370e22f9bedea0bba8ae45ed 1 parent fe844dd
@todb authored
View
22 examples/dissect_thinger.rb
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+# This just allows you to eyeball the dissection stuff to make sure it's all right.
+# Some day, there will be a proper test for it.
+
+fname = ARGV[0] || "../test/sample.pcap"
+sleep_interval = ARGV[1] || 1
+
+require File.join("..","lib","packetfu")
+puts "Loaded: PacketFu v#{PacketFu.version}"
+# $: << File.join(File.expand_path(File.dirname(__FILE__)),"..","lib")
+
+include PacketFu
+
+packets = PcapFile.file_to_array fname
+packets.each do |packet|
+ puts "_" * 75
+ puts packet.inspect
+ puts "_" * 75
+ pkt = Packet.parse(packet)
+ puts pkt.dissect
+ sleep sleep_interval
+end
View
73 lib/packetfu/packet.rb
@@ -341,6 +341,67 @@ def inspect_hex(arg=0)
end
end
+ def dissection_table
+ table = []
+ @headers.each_with_index do |header,table_idx|
+ proto = header.class.name.sub(/^.*::/,"")
+ table << [proto]
+ header.class.members.each do |elem|
+ elem_sym = RUBY_VERSION[/^1\.8/] ? elem.to_sym : elem
+ next if elem_sym == :body
+ elem_type_value = []
+ elem_type_value[0] = elem
+ readable_element = "#{elem}_readable"
+ if header.respond_to? readable_element
+ elem_type_value[1] = header.send(readable_element)
+ else
+ elem_type_value[1] = header.send(elem)
+ end
+ elem_type_value[2] = header[elem.to_sym].class.name
+ table[table_idx] ||= []
+ table[table_idx] << elem_type_value
+ end
+ end
+ table
+ end
+
+ # Renders the dissection_table suitable for screen printing. Can take
+ # one or two arguments. If just the one, only that layer will be displayed
+ # take either a range or a number -- if a range, only protos within
+ # that range will be rendered. If an integer, only that proto
+ # will be rendered.
+ def dissect(min=nil,max=nil)
+ table = self.dissection_table
+ widest = (0..2).map {|i| table.map {|x| x.map {|y| y[i].size}}.flatten.sort.last}
+ table_formatted = ""
+ begin
+ if min
+ layer_min = min.to_i
+ layer_max = max ? max.to_i : layer_min
+ table_range = (layer_min..layer_max)
+ else
+ layer_min = min
+ end
+ rescue => e
+ raise ArgumentError, "Method `dissect' accepts one or two to_i-able arguments"
+ end
+ header_line_width = widest.inject {|sum,i| sum ? sum + i : i} + 2
+ table.each_with_index do |proto_table,proto_idx|
+ if layer_min
+ next unless table_range.member? proto_idx
+ end
+ table_formatted << "--#{proto_table.first}"
+ table_formatted << "-" * (header_line_width - proto_table.first.size) << "\n"
+ proto_table[1,proto_table.size].each do |elem,value,type|
+ table_formatted << " %-#{widest[0]}s " % elem
+ table_formatted << "%-#{widest[1]}s " % value.to_s
+ table_formatted << type << "\n"
+ end
+ end
+ table_formatted << ("-" * header_line_width)
+ table_formatted
+ end
+
alias :orig_kind_of? :kind_of?
def kind_of?(klass)
@@ -451,10 +512,10 @@ def respond_to?(sym, include_private = false)
end # class Packet
- @@inspect_style = :pretty
+ @inspect_style = :pretty
- # If @@inspect_style is :ugly, set the inspect method to the usual inspect.
- # By default, @@inspect_style is :pretty. This default may change if people
+ # If @inspect_style is :ugly, set the inspect method to the usual inspect.
+ # By default, @inspect_style is :pretty. This default may change if people
# hate it.
# Since PacketFu is designed with irb in mind, the normal inspect is way too
# verbose when new packets are created, and it ruins the aesthetics of the
@@ -482,12 +543,12 @@ def respond_to?(sym, include_private = false)
# => #<PacketFu::TCPPacket:0xb7aaf96c @ip_header=#<struct PacketFu::IPHeader ip_v=4, ip_hl=5, ip_tos=#<struct StructFu::Int8 value=nil, endian=nil, width=1, default=0>, ip_len=#<struct StructFu::Int16 value=20, endian=:big, width=2, default=0>, ip_id=#<struct StructFu::Int16 value=58458, endian=:big, width=2, default=0>, ip_frag=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, ip_ttl=#<struct StructFu::Int8 value=32, endian=nil, width=1, default=0>, ip_proto=#<struct StructFu::Int8 value=6, endian=nil, width=1, default=0>, ip_sum=#<struct StructFu::Int16 value=65535, endian=:big, width=2, default=0>, ip_src=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, ip_dst=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, body=#<struct PacketFu::TCPHeader tcp_src=#<struct StructFu::Int16 value=17222, endian=:big, width=2, default=0>, tcp_dst=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_seq=#<struct StructFu::Int32 value=1528113240, endian=:big, width=4, default=0>, tcp_ack=#<struct StructFu::Int32 value=nil, endian=:big, width=4, default=0>, tcp_hlen=#<struct PacketFu::TcpHlen hlen=5>, tcp_reserved=#<struct PacketFu::TcpReserved r1=0, r2=0, r3=0>, tcp_ecn=#<struct PacketFu::TcpEcn n=nil, c=nil, e=nil>, tcp_flags=#<struct PacketFu::TcpFlags urg=0, ack=0, psh=0, rst=0, syn=0, fin=0>, tcp_win=#<struct StructFu::Int16 value=16384, endian=:big, width=2, default=0>, tcp_sum=#<struct StructFu::Int16 value=43333, endian=:big, width=2, default=0>, tcp_urg=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_opts=[], body="">>, @tcp_header=#<struct PacketFu::TCPHeader tcp_src=#<struct StructFu::Int16 value=17222, endian=:big, width=2, default=0>, tcp_dst=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_seq=#<struct StructFu::Int32 value=1528113240, endian=:big, width=4, default=0>, tcp_ack=#<struct StructFu::Int32 value=nil, endian=:big, width=4, default=0>, tcp_hlen=#<struct PacketFu::TcpHlen hlen=5>, tcp_reserved=#<struct PacketFu::TcpReserved r1=0, r2=0, r3=0>, tcp_ecn=#<struct PacketFu::TcpEcn n=nil, c=nil, e=nil>, tcp_flags=#<struct PacketFu::TcpFlags urg=0, ack=0, psh=0, rst=0, syn=0, fin=0>, tcp_win=#<struct StructFu::Int16 value=16384, endian=:big, width=2, default=0>, tcp_sum=#<struct StructFu::Int16 value=43333, endian=:big, width=2, default=0>, tcp_urg=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_opts=[], body="">, @eth_header=#<struct PacketFu::EthHeader eth_dst=#<struct PacketFu::EthMac oui=#<struct PacketFu::EthOui b0=nil, b1=nil, b2=nil, b3=nil, b4=nil, b5=nil, local=0, multicast=nil, oui=428>, nic=#<struct PacketFu::EthNic n0=nil, n1=nil, n2=nil>>, eth_src=#<struct PacketFu::EthMac oui=#<struct PacketFu::EthOui b0=nil, b1=nil, b2=nil, b3=nil, b4=nil, b5=nil, local=0, multicast=nil, oui=428>, nic=#<struct PacketFu::EthNic n0=nil, n1=nil, n2=nil>>, eth_proto=#<struct StructFu::Int16 value=2048, endian=:big, width=2, default=0>, body=#<struct PacketFu::IPHeader ip_v=4, ip_hl=5, ip_tos=#<struct StructFu::Int8 value=nil, endian=nil, width=1, default=0>, ip_len=#<struct StructFu::Int16 value=20, endian=:big, width=2, default=0>, ip_id=#<struct StructFu::Int16 value=58458, endian=:big, width=2, default=0>, ip_frag=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, ip_ttl=#<struct StructFu::Int8 value=32, endian=nil, width=1, default=0>, ip_proto=#<struct StructFu::Int8 value=6, endian=nil, width=1, default=0>, ip_sum=#<struct StructFu::Int16 value=65535, endian=:big, width=2, default=0>, ip_src=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, ip_dst=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, body=#<struct PacketFu::TCPHeader tcp_src=#<struct StructFu::Int16 value=17222, endian=:big, width=2, default=0>, tcp_dst=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_seq=#<struct StructFu::Int32 value=1528113240, endian=:big, width=4, default=0>, tcp_ack=#<struct StructFu::Int32 value=nil, endian=:big, width=4, default=0>, tcp_hlen=#<struct PacketFu::TcpHlen hlen=5>, tcp_reserved=#<struct PacketFu::TcpReserved r1=0, r2=0, r3=0>, tcp_ecn=#<struct PacketFu::TcpEcn n=nil, c=nil, e=nil>, tcp_flags=#<struct PacketFu::TcpFlags urg=0, ack=0, psh=0, rst=0, syn=0, fin=0>, tcp_win=#<struct StructFu::Int16 value=16384, endian=:big, width=2, default=0>, tcp_sum=#<struct StructFu::Int16 value=43333, endian=:big, width=2, default=0>, tcp_urg=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_opts=[], body="">>>, @headers=[#<struct PacketFu::EthHeader eth_dst=#<struct PacketFu::EthMac oui=#<struct PacketFu::EthOui b0=nil, b1=nil, b2=nil, b3=nil, b4=nil, b5=nil, local=0, multicast=nil, oui=428>, nic=#<struct PacketFu::EthNic n0=nil, n1=nil, n2=nil>>, eth_src=#<struct PacketFu::EthMac oui=#<struct PacketFu::EthOui b0=nil, b1=nil, b2=nil, b3=nil, b4=nil, b5=nil, local=0, multicast=nil, oui=428>, nic=#<struct PacketFu::EthNic n0=nil, n1=nil, n2=nil>>, eth_proto=#<struct StructFu::Int16 value=2048, endian=:big, width=2, default=0>, body=#<struct PacketFu::IPHeader ip_v=4, ip_hl=5, ip_tos=#<struct StructFu::Int8 value=nil, endian=nil, width=1, default=0>, ip_len=#<struct StructFu::Int16 value=20, endian=:big, width=2, default=0>, ip_id=#<struct StructFu::Int16 value=58458, endian=:big, width=2, default=0>, ip_frag=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, ip_ttl=#<struct StructFu::Int8 value=32, endian=nil, width=1, default=0>, ip_proto=#<struct StructFu::Int8 value=6, endian=nil, width=1, default=0>, ip_sum=#<struct StructFu::Int16 value=65535, endian=:big, width=2, default=0>, ip_src=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, ip_dst=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, body=#<struct PacketFu::TCPHeader tcp_src=#<struct StructFu::Int16 value=17222, endian=:big, width=2, default=0>, tcp_dst=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_seq=#<struct StructFu::Int32 value=1528113240, endian=:big, width=4, default=0>, tcp_ack=#<struct StructFu::Int32 value=nil, endian=:big, width=4, default=0>, tcp_hlen=#<struct PacketFu::TcpHlen hlen=5>, tcp_reserved=#<struct PacketFu::TcpReserved r1=0, r2=0, r3=0>, tcp_ecn=#<struct PacketFu::TcpEcn n=nil, c=nil, e=nil>, tcp_flags=#<struct PacketFu::TcpFlags urg=0, ack=0, psh=0, rst=0, syn=0, fin=0>, tcp_win=#<struct StructFu::Int16 value=16384, endian=:big, width=2, default=0>, tcp_sum=#<struct StructFu::Int16 value=43333, endian=:big, width=2, default=0>, tcp_urg=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_opts=[], body="">>>, #<struct PacketFu::IPHeader ip_v=4, ip_hl=5, ip_tos=#<struct StructFu::Int8 value=nil, endian=nil, width=1, default=0>, ip_len=#<struct StructFu::Int16 value=20, endian=:big, width=2, default=0>, ip_id=#<struct StructFu::Int16 value=58458, endian=:big, width=2, default=0>, ip_frag=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, ip_ttl=#<struct StructFu::Int8 value=32, endian=nil, width=1, default=0>, ip_proto=#<struct StructFu::Int8 value=6, endian=nil, width=1, default=0>, ip_sum=#<struct StructFu::Int16 value=65535, endian=:big, width=2, default=0>, ip_src=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, ip_dst=#<struct PacketFu::Octets o1=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o2=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o3=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>, o4=#<struct StructFu::Int8 value=0, endian=nil, width=1, default=0>>, body=#<struct PacketFu::TCPHeader tcp_src=#<struct StructFu::Int16 value=17222, endian=:big, width=2, default=0>, tcp_dst=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_seq=#<struct StructFu::Int32 value=1528113240, endian=:big, width=4, default=0>, tcp_ack=#<struct StructFu::Int32 value=nil, endian=:big, width=4, default=0>, tcp_hlen=#<struct PacketFu::TcpHlen hlen=5>, tcp_reserved=#<struct PacketFu::TcpReserved r1=0, r2=0, r3=0>, tcp_ecn=#<struct PacketFu::TcpEcn n=nil, c=nil, e=nil>, tcp_flags=#<struct PacketFu::TcpFlags urg=0, ack=0, psh=0, rst=0, syn=0, fin=0>, tcp_win=#<struct StructFu::Int16 value=16384, endian=:big, width=2, default=0>, tcp_sum=#<struct StructFu::Int16 value=43333, endian=:big, width=2, default=0>, tcp_urg=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_opts=[], body="">>, #<struct PacketFu::TCPHeader tcp_src=#<struct StructFu::Int16 value=17222, endian=:big, width=2, default=0>, tcp_dst=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_seq=#<struct StructFu::Int32 value=1528113240, endian=:big, width=4, default=0>, tcp_ack=#<struct StructFu::Int32 value=nil, endian=:big, width=4, default=0>, tcp_hlen=#<struct PacketFu::TcpHlen hlen=5>, tcp_reserved=#<struct PacketFu::TcpReserved r1=0, r2=0, r3=0>, tcp_ecn=#<struct PacketFu::TcpEcn n=nil, c=nil, e=nil>, tcp_flags=#<struct PacketFu::TcpFlags urg=0, ack=0, psh=0, rst=0, syn=0, fin=0>, tcp_win=#<struct StructFu::Int16 value=16384, endian=:big, width=2, default=0>, tcp_sum=#<struct StructFu::Int16 value=43333, endian=:big, width=2, default=0>, tcp_urg=#<struct StructFu::Int16 value=nil, endian=:big, width=2, default=0>, tcp_opts=[], body="">]>
# irb(main):004:0>
def toggle_inspect
- if @@inspect_style == :pretty
+ if @inspect_style == :pretty
eval("class Packet; def inspect; super; end; end")
- @@inspect_style = :ugly
+ @inspect_style = :ugly
else
eval("class Packet; def inspect; self.proto.join('|') + \"\n\" + self.inspect_hex; end; end")
- @@inspect_style = :pretty
+ @inspect_style = :pretty
end
end
View
7 lib/packetfu/pcap.rb
@@ -274,9 +274,6 @@ def readfile(file)
# Note that this strips out pcap timestamps -- if you'd like to retain
# timestamps and other libpcap file information, you will want to
# use read() instead.
- #
- # Note, invoking this requires the somewhat clumsy sytax of,
- # PcapFile.new.file_to_array(:f => 'filename.pcap')
def file_to_array(args={})
filename = args[:filename] || args[:file] || args[:f]
if filename
@@ -291,6 +288,10 @@ def file_to_array(args={})
alias_method :f2a, :file_to_array
+ def self.file_to_array(fname)
+ PcapFile.new.file_to_array(:f => fname)
+ end
+
# Takes an array of packets (as generated by file_to_array), and writes them
# to a file. Valid arguments are:
#
View
13 lib/packetfu/protos/arp.rb
@@ -77,7 +77,7 @@ def arp_hw_len; self[:arp_hw_len].to_i; end
# Setter for the ARP protocol length.
def arp_proto_len=(i); typecast i; end
# Getter for the ARP protocol length.
- def arp_proto; self[:arp_proto].to_i; end
+ def arp_proto_len; self[:arp_proto_len].to_i; end
# Setter for the ARP opcode.
def arp_opcode=(i); typecast i; end
# Getter for the ARP opcode.
@@ -143,6 +143,17 @@ def arp_daddr_ip
self[:arp_dst_ip].to_x
end
+ # Readability aliases
+
+ alias :arp_src_mac_readable :arp_saddr_mac
+ alias :arp_dst_mac_readable :arp_daddr_mac
+ alias :arp_src_ip_readable :arp_saddr_ip
+ alias :arp_dst_ip_readable :arp_daddr_ip
+
+ def arp_proto_readable
+ "0x%04x" % arp_proto
+ end
+
end # class ARPHeader
# ARPPacket is used to construct ARP packets. They contain an EthHeader and an ARPHeader.
View
9 lib/packetfu/protos/eth.rb
@@ -229,6 +229,15 @@ def eth_daddr
EthHeader.str2mac(self[:eth_dst].to_s)
end
+ # Readability aliases
+
+ alias :eth_dst_readable :eth_daddr
+ alias :eth_src_readable :eth_saddr
+
+ def eth_proto_readable
+ "0x%04x" % eth_proto
+ end
+
end
# EthPacket is used to construct Ethernet packets. They contain an
View
10 lib/packetfu/protos/hsrp.rb
@@ -109,6 +109,14 @@ def hsrp_addr
self[:hsrp_vip].to_x
end
+ # Readability aliases
+
+ alias :hsrp_vip_readable :hsrp_addr
+
+ def hsrp_password_readable
+ hsrp_password.to_s.inspect
+ end
+
end
# HSRPPacket is used to construct HSRP Packets. They contain an EthHeader, an IPHeader, and a UDPHeader.
@@ -186,7 +194,7 @@ def peek_format
peek_data << "%-5d" % self.to_s.size
peek_data << "%-16s" % self.hsrp_addr
peek_data << "%-4d" % self.hsrp_group
- peek_data << "%-35s" % self.hsrp_password.inspect # .gsub(/\x00/,"")
+ peek_data << "%-35s" % self.hsrp_password_readable
peek_data << "%-15s" % self.ip_saddr
peek_data.join
end
View
6 lib/packetfu/protos/icmp.rb
@@ -83,6 +83,12 @@ def icmp_recalc(arg=:all)
end
end
+ # Readability aliases
+
+ def icmp_sum_readable
+ "0x%04x" % icmp_sum
+ end
+
end
# ICMPPacket is used to construct ICMP Packets. They contain an EthHeader, an IPHeader, and a ICMPHeader.
View
13 lib/packetfu/protos/ip.rb
@@ -261,6 +261,19 @@ def ip_recalc(arg=:all)
end
end
+ # Readability aliases
+
+ alias :ip_src_readable :ip_saddr
+ alias :ip_dst_readable :ip_daddr
+
+ def ip_id_readable
+ "0x%04x" % ip_id
+ end
+
+ def ip_sum_readable
+ "0x%04x" % ip_sum
+ end
+
end
# IPPacket is used to construct IP packets. They contain an EthHeader, an IPHeader, and usually
View
5 lib/packetfu/protos/ipv6.rb
@@ -182,6 +182,11 @@ def ipv6_daddr=(str)
self[:ipv6_dst].read_x(str)
end
+ # Readability aliases
+
+ alias :ipv6_src_readable :ipv6_saddr
+ alias :ipv6_dst_readable :ipv6_daddr
+
end # class IPv6Header
# IPv6Packet is used to construct IPv6 Packets. They contain an EthHeader and an IPv6Header, and in
View
36 lib/packetfu/protos/tcp.rb
@@ -842,6 +842,15 @@ def tcp_options
self[:tcp_opts].decode
end
+ # Gets a more readable flags list
+ def tcp_flags_dotmap
+ dotmap = tcp_flags.members.map do |flag|
+ status = self.tcp_flags.send flag
+ status == 0 ? "." : flag.to_s.upcase[0]
+ end
+ dotmap.join
+ end
+
# Sets a more readable option list.
def tcp_options=(arg)
self[:tcp_opts].encode arg
@@ -887,6 +896,26 @@ def tcp_recalc(arg=:all)
end
end
+ # Readability aliases
+
+ alias :tcp_flags_readable :tcp_flags_dotmap
+
+ def tcp_ack_readable
+ "0x%08x" % tcp_ack
+ end
+
+ def tcp_seq_readable
+ "0x%08x" % tcp_seq
+ end
+
+ def tcp_sum_readable
+ "0x%04x" % tcp_sum
+ end
+
+ def tcp_opts_readable
+ tcp_options
+ end
+
end
# TCPPacket is used to construct TCP packets. They contain an EthHeader, an IPHeader, and a TCPHeader.
@@ -1067,12 +1096,7 @@ def peek_format
peek_data << "->"
peek_data << "%21s" % "#{self.ip_daddr}:#{self.tcp_dst}"
flags = ' ['
- flags << (self.tcp_flags.urg.zero? ? "." : "U")
- flags << (self.tcp_flags.ack.zero? ? "." : "A")
- flags << (self.tcp_flags.psh.zero? ? "." : "P")
- flags << (self.tcp_flags.rst.zero? ? "." : "R")
- flags << (self.tcp_flags.syn.zero? ? "." : "S")
- flags << (self.tcp_flags.fin.zero? ? "." : "F")
+ flags << self.tcp_flags_dotmap
flags << '] '
peek_data << flags
peek_data << "S:"
View
6 lib/packetfu/protos/udp.rb
@@ -97,6 +97,12 @@ def udp_dport=(arg)
self.udp_dst=(arg)
end
+ # Readability aliases
+
+ def udp_sum_readable
+ "0x%04x" % udp_sum
+ end
+
end
# UDPPacket is used to construct UDP Packets. They contain an EthHeader, an IPHeader, and a UDPHeader.
View
2  lib/packetfu/version.rb
@@ -1,7 +1,7 @@
module PacketFu
# Check the repo's for version release histories
- VERSION = "1.0.2"
+ VERSION = "1.0.3"
def self.version
VERSION
View
2  packetfu.gemspec
@@ -2,7 +2,7 @@ require 'rake'
Gem::Specification.new do |s|
s.name = %q{packetfu}
- s.version = "1.0.2.pre"
+ s.version = "1.0.3.pre"
s.date = %q{2011-05-22}
s.authors = ["Tod Beardsley"]
s.email = %q{todb@planb-security.net}
Please sign in to comment.
Something went wrong with that request. Please try again.