Class: Scriptroute::ICMP6echo

Inherits:
ICMP6 show all
Defined in:
lib/scriptroute/packets.rb

Overview

Class for ping packets (echo and echo reply) much duplicated with ICMPecho

Constant Summary

Constants inherited from ICMP6

Scriptroute::ICMP6::ICMP6_DST_UNREACH, Scriptroute::ICMP6::ICMP6_ECHO, Scriptroute::ICMP6::ICMP6_ECHOREPLY, Scriptroute::ICMP6::ICMP6_PACKET_TOO_BIG, Scriptroute::ICMP6::ICMP6_PARAM_PROB, Scriptroute::ICMP6::ICMP6_TIME_EXCEEDED

Constants inherited from IPv6

Scriptroute::IPv6::IPPROTO_ICMP6

Constants inherited from IP

Scriptroute::IP::IPPROTO_TCP, Scriptroute::IP::IPPROTO_UDP

Instance Attribute Summary collapse

Attributes inherited from ICMP6

#icmp_cksum, #icmp_code, #icmp_type, #ip_payload_len

Attributes inherited from IPv6

#ip6_dst, #ip6_flow, #ip6_hlim, #ip6_src

Instance Method Summary collapse

Methods inherited from IPv6

creator, #ip_ttl=, #ipv6_unmarshal

Methods inherited from IP

creator, #to_bytes

Constructor Details

#initialize(paylen_or_str = 0) ⇒ ICMP6echo

Returns a new instance of ICMP6echo.



746
747
748
749
750
751
752
753
754
755
756
757
758
759
# File 'lib/scriptroute/packets.rb', line 746

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(ICMP6_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

Instance Attribute Details

#icmp_idFixnum (readonly)

Returns:

  • (Fixnum)


740
741
742
# File 'lib/scriptroute/packets.rb', line 740

def icmp_id
  @icmp_id
end

#icmp_seqFixnum

Returns:

  • (Fixnum)


740
741
742
# File 'lib/scriptroute/packets.rb', line 740

def icmp_seq
  @icmp_seq
end

Instance Method Details

#marshalString

Returns The packet in string form.

Returns:

  • (String)

    The packet in string form



761
762
763
# File 'lib/scriptroute/packets.rb', line 761

def marshal
  super + [ @icmp_id, @icmp_seq ].pack("nn") + "\0" * ( @ip_payload_len - 4 - 4 )
end

#to_sString

Returns:

  • (String)


765
766
767
# File 'lib/scriptroute/packets.rb', line 765

def to_s
  super + ": ECHO6: id %d seq %d len %d" % [ @icmp_id, @icmp_seq, @ip_payload_len ] 
end