Hm. Worth a try I suppose, but I wouldn't want to base any conclusions upon the accuracy of the results.

From what I saw, it looks like the module predates the availability of a HiRes timer and has been (badly) adapted to use it as an afterthought.

When the granularity of the timing was whole seconds, network speeds were 4MHz for LANs and 56kbps for WANs; timing all the housekeeping probably made little difference to the outcome, but now it just swamps the actual time measured.

The module needs serious attention. Some of which would be fairly easy. By setting up the appropriate implementation func in new():

if ($self->{"proto"} eq "udp") # Open a socket ... $self->{func} = \&ping_tcp; } elsif ($self->{"proto"} eq "icmp") { ... $self->{func} = \&ping_icmp; } ...

Then ping() can be reduced from:

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; }

To this:

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? $ping_time = &time(); $ret = $self->{func}->( $self, $ip, $timeout ); return wantarray ? ($ret, &time() - $ping_time, $self->ntop($ip)) : +$ret; }

And if each of the implementation funcs did the timing of the critical part and returned it, it could become:

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? ( $ping_time, $ret ) = $self->{func}->( $self, $ip, $timeout ); return wantarray ? ($ret, $ping_time, $self->ntop($ip)) : $ret; }

But that would take someone with motivation to work out exactly where to start and stop the timers.

Personally I don't have that motivation. A quick call out to ping.exe satisfies my needs.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to Re^3: Net::Ping timing not correct by BrowserUk
in thread Net::Ping timing not correct by gepebril69

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.