Class: Jruby::Pcap::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/jruby-pcap/frame.rb

Instance Method Summary collapse

Constructor Details

#initialize(handle, frame) ⇒ Frame

Returns a new instance of Frame.



4
5
6
7
8
# File 'lib/jruby-pcap/frame.rb', line 4

def initialize(handle, frame)
  @handle = handle
  @frame  = frame
  @header = @frame.header
end

Instance Method Details

#dst_addrObject



26
27
28
# File 'lib/jruby-pcap/frame.rb', line 26

def dst_addr
  @header.dst_addr.to_s.gsub("/","")
end

#dst_hostObject



30
31
32
# File 'lib/jruby-pcap/frame.rb', line 30

def dst_host
  @header.dst_addr.host_name
end

#dst_portObject



34
35
36
# File 'lib/jruby-pcap/frame.rb', line 34

def dst_port
  @header.dst_port.value_as_string
end

#dst_port_nameObject



38
39
40
# File 'lib/jruby-pcap/frame.rb', line 38

def dst_port_name
  @header.dst_port.name
end

#lengthObject



50
51
52
# File 'lib/jruby-pcap/frame.rb', line 50

def length
  @frame.length
end

#protocolObject



42
43
44
# File 'lib/jruby-pcap/frame.rb', line 42

def protocol
  @header.protocol.name
end

#src_addrObject



10
11
12
# File 'lib/jruby-pcap/frame.rb', line 10

def src_addr
  @header.src_addr.to_s.gsub("/","")
end

#src_hostObject



14
15
16
# File 'lib/jruby-pcap/frame.rb', line 14

def src_host
  @header.src_addr.host_name
end

#src_portObject



18
19
20
# File 'lib/jruby-pcap/frame.rb', line 18

def src_port
  @header.src_port.value_as_string
end

#src_port_nameObject



22
23
24
# File 'lib/jruby-pcap/frame.rb', line 22

def src_port_name
  @header.src_port.name
end

#to_hashObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jruby-pcap/frame.rb', line 54

def to_hash
  hash = {}
  if (@frame.is_a?(IpV4Packet))
    hash['src_addr']  = src_addr
    hash['dst_addr']  = dst_addr
    hash['procotol']  = protocol
    hash['version']   = version
    hash['ip_length'] = length
  elsif (@frame.is_a?(TcpPacket) || @frame.is_a?(UdpPacket))
    hash['src_port'] = src_port
    hash['src_port_name'] = src_port_name
    hash['dst_port'] = dst_port
    hash['dst_port_name'] = dst_port_name
    hash['tcpip_length'] = length
  end
  hash
end

#versionObject



46
47
48
# File 'lib/jruby-pcap/frame.rb', line 46

def version
  @header.version.name
end