sub ping { my ($self, $host, # Name or IP number of host to ping $timeout, # Seconds after which ping times out ) = @_; my ($ip, # Packed IP number of $host $ret, # The return value $ping_time, # When ping began ); croak("Usage: \$p->ping(\$host [, \$timeout])") unless @_ == 2 || @_ == 3; $timeout = $self->{"timeout"} unless $timeout; croak("Timeout must be greater than 0 seconds") if $timeout <= 0; $ip = inet_aton($host); return () unless defined($ip); # Does host exist? # Dispatch to the appropriate routine. $ping_time = &time(); if ($self->{"proto"} eq "external") { $ret = $self->ping_external($ip, $timeout); } elsif ($self->{"proto"} eq "udp") { $ret = $self->ping_udp($ip, $timeout); } elsif ($self->{"proto"} eq "icmp") { $ret = $self->ping_icmp($ip, $timeout); } elsif ($self->{"proto"} eq "tcp") { $ret = $self->ping_tcp($ip, $timeout); } elsif ($self->{"proto"} eq "stream") { $ret = $self->ping_stream($ip, $timeout); } elsif ($self->{"proto"} eq "syn") { $ret = $self->ping_syn($host, $ip, $ping_time, $ping_time+$timeout); } else { croak("Unknown protocol \"$self->{proto}\" in ping()"); } return wantarray ? ($ret, &time() - $ping_time, $self->ntop($ip)) : $ret; }