Class: Unified2::Packet
- Inherits:
-
Object
- Object
- Unified2::Packet
- Defined in:
- lib/unified2/packet.rb
Overview
Packet
Instance Attribute Summary collapse
-
#event_id ⇒ Object
readonly
Build method defaults.
-
#event_timestamp ⇒ Object
readonly
Build method defaults.
-
#length ⇒ Object
readonly
Build method defaults.
-
#link_type ⇒ Object
readonly
Build method defaults.
-
#microsecond ⇒ Object
readonly
Build method defaults.
-
#raw ⇒ String
readonly
Raw.
-
#timestamp ⇒ Object
readonly
Build method defaults.
Instance Method Summary collapse
-
#blank? ⇒ true, false
Blank?.
-
#checksum ⇒ String
Checksum.
-
#dump(options = {}) {|index, hex_segment, print_segment| ... } ⇒ nil
Dump.
-
#hex(include_header = true) ⇒ String
Hex.
-
#hexdump(options = {}) ⇒ Object
Hexdump.
-
#initialize(packet) ⇒ Packet
constructor
Initialize packet Object.
-
#ip_header ⇒ Hash
IP Header.
-
#payload ⇒ Payload
Payload.
-
#protocol ⇒ Protocol
Protocol.
-
#to_s ⇒ String
String.
Constructor Details
#initialize(packet) ⇒ Packet
Initialize packet Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/unified2/packet.rb', line 27 def initialize(packet) @raw = packet @link_type = packet[:linktype] @microsecond = packet[:packet_microsecond] @event_timestamp = Time.at(packet[:timestamp]) @timestamp = Time.at(packet[:packet_timestamp]) @length = packet[:packet_length].to_i @event_id = packet[:event_id] @packet ||= PacketFu::Packet.parse(packet[:packet]) @protocol = @packet.protocol.last.to_sym end |
Instance Attribute Details
#event_id ⇒ Object (readonly)
Build method defaults
18 19 20 |
# File 'lib/unified2/packet.rb', line 18 def event_id @event_id end |
#event_timestamp ⇒ Object (readonly)
Build method defaults
18 19 20 |
# File 'lib/unified2/packet.rb', line 18 def @event_timestamp end |
#length ⇒ Object (readonly)
Build method defaults
18 19 20 |
# File 'lib/unified2/packet.rb', line 18 def length @length end |
#link_type ⇒ Object (readonly)
Build method defaults
18 19 20 |
# File 'lib/unified2/packet.rb', line 18 def link_type @link_type end |
#microsecond ⇒ Object (readonly)
Build method defaults
18 19 20 |
# File 'lib/unified2/packet.rb', line 18 def microsecond @microsecond end |
#timestamp ⇒ Object (readonly)
Build method defaults
18 19 20 |
# File 'lib/unified2/packet.rb', line 18 def @timestamp end |
Instance Method Details
#blank? ⇒ true, false
Blank?
98 99 100 101 |
# File 'lib/unified2/packet.rb', line 98 def blank? return true unless @packet false end |
#checksum ⇒ String
Checksum
Create a unique payload checksum
204 205 206 |
# File 'lib/unified2/packet.rb', line 204 def checksum Digest::MD5.hexdigest(hex(false)) end |
#dump(options = {}) {|index, hex_segment, print_segment| ... } ⇒ nil
Note:
Please view the hexdump documentation for more information. Hexdump is a great lib by @postmodern. (github.com/postmodern/hexdump)
Dump
170 171 172 173 174 175 176 177 178 |
# File 'lib/unified2/packet.rb', line 170 def dump(={}) packet = if [:header] @raw[:packet] else @packet.payload end Hexdump.dump(packet, ) end |
#hex(include_header = true) ⇒ String
Hex
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/unified2/packet.rb', line 117 def hex(include_header=true) packet = if include_header @packet.to_s else @packet.payload.to_s end hex = packet.unpack('H*') return hex.first if hex nil end |
#hexdump(options = {}) ⇒ Object
Hexdump
188 189 190 191 192 193 194 195 |
# File 'lib/unified2/packet.rb', line 188 def hexdump(={}) hexdump = [:output] ||= "" [:width] ||= 30 [:header] ||= true dump() hexdump end |
#ip_header ⇒ Hash
IP Header
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/unified2/packet.rb', line 46 def ip_header if @packet.is_ip? @ip_header = { :ip_ver => @packet.ip_header.ip_v, :ip_hlen => @packet.ip_header.ip_hl, :ip_tos => @packet.ip_header.ip_tos, :ip_len => @packet.ip_header.ip_len, :ip_id => @packet.ip_header.ip_id, :ip_frag => @packet.ip_header.ip_frag, :ip_ttl => @packet.ip_header.ip_ttl, :ip_proto => @packet.ip_header.ip_proto, :ip_csum => @packet.ip_header.ip_sum } else @ip_header = {} end @ip_header end |
#payload ⇒ Payload
Payload
89 90 91 |
# File 'lib/unified2/packet.rb', line 89 def payload @packet.payload end |