Class: PcapSimple::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/pcap_simple.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Packet

Returns a new instance of Packet.

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
49
# File 'lib/pcap_simple.rb', line 40

def initialize(*args)
  Hash[*args].each {|k,v| self.send("%s="%k,v)}
  raise ArgumentError, "need to specify raw_data" if raw_data.nil?
  @ethernet=Ethernet.new(raw_data)
  @ip      =IP.new(@ethernet.data)
  case ip.ip_p
    when 17
      @datagram=UDP.new(ip.data)
  end
end

Instance Attribute Details

#datagramObject (readonly)

Returns the value of attribute datagram.



38
39
40
# File 'lib/pcap_simple.rb', line 38

def datagram
  @datagram
end

#ethernetObject (readonly)

Returns the value of attribute ethernet.



38
39
40
# File 'lib/pcap_simple.rb', line 38

def ethernet
  @ethernet
end

#headerObject

Returns the value of attribute header.



37
38
39
# File 'lib/pcap_simple.rb', line 37

def header
  @header
end

#ipObject (readonly)

Returns the value of attribute ip.



38
39
40
# File 'lib/pcap_simple.rb', line 38

def ip
  @ip
end

#raw_dataObject

Returns the value of attribute raw_data.



37
38
39
# File 'lib/pcap_simple.rb', line 37

def raw_data
  @raw_data
end

Instance Method Details

#dportObject



65
66
67
# File 'lib/pcap_simple.rb', line 65

def dport
  datagram.dport
end

#dstObject



56
57
58
# File 'lib/pcap_simple.rb', line 56

def dst
  ip.ip_dst
end

#ip_idObject



59
60
61
# File 'lib/pcap_simple.rb', line 59

def ip_id
  ip.ip_id
end

#sportObject



62
63
64
# File 'lib/pcap_simple.rb', line 62

def sport
  datagram.sport
end

#srcObject



53
54
55
# File 'lib/pcap_simple.rb', line 53

def src
  ip.ip_src
end

#timeObject



68
69
70
# File 'lib/pcap_simple.rb', line 68

def time
  Time.at(header.ts_sec)
end

#udp_dataObject



50
51
52
# File 'lib/pcap_simple.rb', line 50

def udp_data
  datagram.data
end