Class: Scriptroute::ICMPecho
- Defined in:
- lib/scriptroute/packets.rb
Overview
Class for ping packets (echo and echo reply)
Constant Summary
Constants inherited from ICMP
Scriptroute::ICMP::ICMP_ECHO, Scriptroute::ICMP::ICMP_ECHOREPLY, Scriptroute::ICMP::ICMP_MASKREPLY, Scriptroute::ICMP::ICMP_MASKREQ, Scriptroute::ICMP::ICMP_PARAMETERPROB, Scriptroute::ICMP::ICMP_TIMESTAMP, Scriptroute::ICMP::ICMP_TIMESTAMPREPLY, Scriptroute::ICMP::ICMP_TIMXCEED, Scriptroute::ICMP::ICMP_UNREACH, Scriptroute::ICMP::ICMP_UNREACH_FILTER_PROHIB, Scriptroute::ICMP::ICMP_UNREACH_HOST, Scriptroute::ICMP::ICMP_UNREACH_HOST_PRECEDENCE, Scriptroute::ICMP::ICMP_UNREACH_HOST_PROHIB, Scriptroute::ICMP::ICMP_UNREACH_HOST_UNKNOWN, Scriptroute::ICMP::ICMP_UNREACH_ISOLATED, Scriptroute::ICMP::ICMP_UNREACH_NEEDFRAG, Scriptroute::ICMP::ICMP_UNREACH_NET, Scriptroute::ICMP::ICMP_UNREACH_NET_PROHIB, Scriptroute::ICMP::ICMP_UNREACH_NET_UNKNOWN, Scriptroute::ICMP::ICMP_UNREACH_PORT, Scriptroute::ICMP::ICMP_UNREACH_PRECEDENCE_CUTOFF, Scriptroute::ICMP::ICMP_UNREACH_PROTOCOL, Scriptroute::ICMP::ICMP_UNREACH_SRCFAIL, Scriptroute::ICMP::ICMP_UNREACH_TOSHOST, Scriptroute::ICMP::ICMP_UNREACH_TOSNET
Constants inherited from IPv4
Scriptroute::IPv4::IPPROTO_ICMP
Constants inherited from IP
Scriptroute::IP::IPPROTO_TCP, Scriptroute::IP::IPPROTO_UDP
Instance Attribute Summary collapse
- #icmp_id ⇒ Fixnum readonly
- #icmp_seq ⇒ Fixnum
Attributes inherited from ICMP
#icmp_cksum, #icmp_code, #icmp_type, #ip_p, #ip_payload_len
Attributes inherited from IPv4
#ip_dst, #ip_hl, #ip_id, #ip_len, #ip_off, #ip_options, #ip_p, #ip_src, #ip_sum, #ip_tos, #ip_ttl, #ip_v
Instance Method Summary collapse
-
#initialize(paylen_or_str = 0) ⇒ ICMPecho
constructor
A new instance of ICMPecho.
-
#marshal ⇒ String
The packet in string form.
- #to_s ⇒ String
Methods inherited from IPv4
#add_option, #calculate_header_len, #calculate_packet_len, creator, #ip_payload_len, #ipv4_unmarshal
Methods inherited from IP
Constructor Details
#initialize(paylen_or_str = 0) ⇒ ICMPecho
Returns a new instance of ICMPecho.
714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# 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 |
Instance Attribute Details
#icmp_id ⇒ Fixnum (readonly)
708 709 710 |
# File 'lib/scriptroute/packets.rb', line 708 def icmp_id @icmp_id end |
#icmp_seq ⇒ Fixnum
708 709 710 |
# File 'lib/scriptroute/packets.rb', line 708 def icmp_seq @icmp_seq end |
Instance Method Details
#marshal ⇒ String
Returns The packet in string form.
729 730 731 |
# 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 ⇒ String
733 734 735 |
# 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 |