Mailing List Archive

Net::Ping::pingecho returns something funny when target machine is down
The program

#!/usr/add-on/ncmp/bin/perl5 -w

use Net::Ping;

warn "pinging";

if (pingecho('deadmach', 2))
{
warn "passed!";
}
else
{
warn "failed";
}

produces

pinging at /usr/tmp/pingtest line 5.
Argument "" isn't numeric for numeric eq at
/usr/add-on/ncmp/lib/perl5.001/lib/perl5/Net/Ping.pm line 100.
failed at /usr/tmp/pingtest line 13.

I fixed it once by changing

$ret == 1 ? 1 : 0

to

$ret eq 1 ? 1 : 0

but that didn't feel like the right answer. So I changed

alarm(0);
close(PINGSOCK);
$ret == 1 ? 1 : 0 ;

to

$ret = 0 if defined($@);
alarm(0);
close(PINGSOCK);
$ret == 1 ? 1 : 0 ;

I wasn't sure, after reading eval on perlfunc, if the eval should
return undef or a mysterious undefined value in this case. If the
latter, I suggest you add something like '(not undef!)' after the
word 'undefined' in that section.


--

Robert W. Gebhardt
AT&T Global Business Communications Systems
11900 N. Pecos St.
Denver, CO 80234

gebha@dr.att.com

Phone: 303-538-4726
FAX: 303-538-3564
Re: Net::Ping::pingecho returns something funny when target machine is down [ In reply to ]
>>>>> "robert" == Robert W Gebhardt <Robert.W.Gebhardt@att.com> writes:

robert> The program
robert> #!/usr/add-on/ncmp/bin/perl5 -w

robert> use Net::Ping;

robert> warn "pinging";

[...]
robert> produces

robert> pinging at /usr/tmp/pingtest line 5.
robert> Argument "" isn't numeric for numeric eq at
robert> /usr/add-on/ncmp/lib/perl5.001/lib/perl5/Net/Ping.pm line 100.
robert> failed at /usr/tmp/pingtest line 13.

Please get Net-Ping-1.00, from CPAN from the directory
authors/id/PMQS. It has fixed this.

The current list of CPAN sites is in
ftp://ftp.funet.fi/pub/languages/perl/CPAN/CPAN .


Regards,
andreas