Handling Packets

Class Packet

Gives you access to fieds within (the captured part) of a packet.  You will normally work on Packets returned from  Trace.read_packet  or  Trace.each_packet  (see Trace Handling), but you can create a new packet instance with  Packet.new  (see below).

Note that the Layer and Decode methods return nil if their requested oject was not present in the packet, or was not completely captured.

Class Methods
new Packet.new -> aPacket
Makes a new Ruby Packet.


Instance Methods
copy_packet pkt.copy_packet -> aNewPacket
Makes a new Ruby Packet containing a copy of pkt.  

A ruby-libtrace Packet uses a libtrace packet directly, i.e. a set of pointers into the current packet of a trace - the actual data is not copied.   Use copy_packet if you need to save a copy of a packet's data for later use.
layer2 pkt.layer2 -> aLayer2
Gets a Layer2 object from the packet; see Layers page
layer3 pkt.layer3 -> aLayer3
Gets a Layer3 object from the packet; see Layers
transport pkt.transport -> aTransport
Gets a Transport object from the packet; see Layers
udp_payload pkt.udp_payload -> aData
Gets Data for a UDP payload  from the packet
tcp_payload pkt.tcp_payload -> aData
Gets Data for a TCP payload  from the packet
ip pkt.ip -> anIP
Gets an IPv4 header from the packet
ip6 pkt.ip6 -> anIP6
Gets an IPv6 header from the packet
tcp pkt.tcp-> aTCP
Gets a TCP header from the packet
udp pkt.udp -> aUDP
Gets a UDP header from the packet
icmp pkt.icmp -> anICMP
Gets (first part of) an ICMP header from the packet
apply_filter pkt.apply_filter(aFilter) -> result
Tests whether the current contents of the packet match aFilter.
Result is true if the filter matches, false if it doesn't, or nil if the filter was invalid.

Instance Variables
timepkt.time -> aTimeval
Packet Arrival Time as a ruby Time
seconds pkt.seconds -> aFloat
Packet Arrival Time in Unix seconds (double)
ts_sec
pkt.ts_sec -> aTimeval
Packet Arrival Time in Unix seconds (integer)
erf_time pkt.erf_time -> anInteger
Packet Arrival Time as a DAG ERF time (64-bit)
wire_len pkt.wire_len -> anInteger
Original size of packet on the wire
capture_len pkt.capture_len-> anInteger
Number of bytes captured; may be less than wire_len
linktype
pkt.linktype-> anInteger
Packet's link type; see Layer2 on Layers page for linktype values

Nevil Brownlee
Wed, 9 Feb 11 (NZDT)