class Scriptroute::ICMPecho

Class for ping packets (echo and echo reply)

Attributes

icmp_id[R]

@return [Fixnum]

icmp_seq[RW]

@return [Fixnum]

Public Class Methods

new(paylen_or_str = 0) click to toggle source
Calls superclass method Scriptroute::ICMP::new
# File lib/scriptroute/packets.rb, line 714
def initialize(paylen_or_str = 0)
  if(paylen_or_str.is_a?(Fixnum)) then
    if( paylen_or_str < 0) then raise "payload length must be >= 0" end
    @ip_payload_len = paylen_or_str + 4 + 4
    @icmp_id = 666
    @icmp_seq = 1
    super(ICMP_ECHO)
  else
    # x is skip forward a character.
    @ip_payload_len = paylen_or_str.length - 8
    @icmp_id, @icmp_seq = paylen_or_str.unpack("xxxxnn")
    super(paylen_or_str)
  end
end

Public Instance Methods

marshal() click to toggle source

@return [String] The packet in string form

Calls superclass method Scriptroute::ICMP#marshal
# File lib/scriptroute/packets.rb, line 729
def marshal
  super + [ @icmp_id, @icmp_seq ].pack("nn") + "\0" * ( @ip_payload_len - 4 - 4 )
end
to_s() click to toggle source

@return [String]

Calls superclass method Scriptroute::ICMP#to_s
# File lib/scriptroute/packets.rb, line 733
def to_s
  super + ": ECHO: id %d seq %d len %d" % [ @icmp_id, @icmp_seq, @ip_payload_len ] 
end