class SimplePing::RecvMessage

Class that stores the received message Implements a method to retrieve the ICMP header

Public Class Methods

new(mesg) click to toggle source

constructor

@param [String] mesg

# File lib/simple_ping/recv_message.rb, line 21
def initialize(mesg)
  @mesg = mesg
end

Public Instance Methods

code() click to toggle source

Code

@return [Integer]

# File lib/simple_ping/recv_message.rb, line 7
def code
  @mesg[21].bytes[0]
end
data() click to toggle source

Data

@return [String]

# File lib/simple_ping/recv_message.rb, line 28
def data
  @mesg[28, @mesg.length.to_i - 28]
end
id() click to toggle source

ID

@return [Integer]

# File lib/simple_ping/recv_message.rb, line 14
def id
  (@mesg[24].bytes[0] << 8) + @mesg[25].bytes[0]
end
seq_number() click to toggle source

sequence numebr

@return [Integer]

# File lib/simple_ping/recv_message.rb, line 35
def seq_number
  (@mesg[26].bytes[0] << 8) + @mesg[27].bytes[0]
end
to_icmp() click to toggle source

create icmp object

@return [SimplePing::ICMP]

# File lib/simple_ping/recv_message.rb, line 42
def to_icmp
  icmp = SimplePing::ICMP.new(code: code, type: type)
  if icmp.is_type_echo?
    icmp.id = id
    icmp.seq_number = seq_number
    icmp.data = data
  end
  icmp
end
type() click to toggle source

Type

@return [Integer]

# File lib/simple_ping/recv_message.rb, line 55
def type
  @mesg[20].bytes[0]
end