Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/simple_ping/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ def exec(dest_ip_addr:, data: nil)
# Receive
begin
Timeout.timeout(TIMEOUT_TIME) do
mesg, _ = socket.recvfrom(1500)
icmp_reply = SimplePing::RecvMessage.new(mesg).to_icmp
loop do
mesg, _ = socket.recvfrom(1500)
icmp_reply = SimplePing::RecvMessage.new(mesg).to_icmp

if icmp.successful_reply?(icmp_reply)
true
elsif icmp_reply.is_type_destination_unreachable?
logger.warn { "Destination Unreachable!!" }
false
elsif icmp_reply.is_type_redirect?
logger.warn { "Redirect Required!!" }
false
if icmp.successful_reply?(icmp_reply)
return true
elsif icmp_reply.is_type_destination_unreachable?
logger.warn { "Destination Unreachable!!" }
return false
elsif icmp_reply.is_type_redirect?
logger.warn { "Redirect Required!!" }
return false
end
end
end
rescue Timeout::Error => e
Expand Down