From: Alexey V. Barantsev Date: Thu, 2 Nov 2000 20:12:20 +0000 (+0300) Subject: recv() can fail and return undef. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b4b1f6091e7b2196e3cee1d4763595e9bae86880;p=p5sagit%2Fp5-mst-13.2.git recv() can fail and return undef. Subject: [ID 20001102.003] Net::Ping patch: "Bad arg lenght" error appears if host is unreachable Message-Id: <200011021712.UAA07919@dallas.kazbek.ispras.ru> p4raw-id: //depot/perl@7529 --- diff --git a/lib/Net/Ping.pm b/lib/Net/Ping.pm index 9cc942d..e3006f9 100644 --- a/lib/Net/Ping.pm +++ b/lib/Net/Ping.pm @@ -369,16 +369,17 @@ sub ping_udp elsif ($nfound) # A packet is waiting { $from_msg = ""; - $from_saddr = recv($self->{"fh"}, $from_msg, 1500, $flags); - ($from_port, $from_ip) = sockaddr_in($from_saddr); - if (($from_ip eq $ip) && # Does the packet check out? - ($from_port == $self->{"port_num"}) && - ($from_msg eq $msg)) - { - $ret = 1; # It's a winner - $done = 1; - } - } + $from_saddr = recv($self->{"fh"}, $from_msg, 1500, $flags) + or last; # For example an unreachable host will make recv() fail. + ($from_port, $from_ip) = sockaddr_in($from_saddr); + if (($from_ip eq $ip) && # Does the packet check out? + ($from_port == $self->{"port_num"}) && + ($from_msg eq $msg)) + { + $ret = 1; # It's a winner + $done = 1; + } + } else # Oops, timed out { $done = 1;